summaryrefslogtreecommitdiff
path: root/Build/source
diff options
context:
space:
mode:
authorMartin Schröder <martin@oneiros.de>2007-07-11 21:13:59 +0000
committerMartin Schröder <martin@oneiros.de>2007-07-11 21:13:59 +0000
commit7bf56e6bfcd7b204b3507dc9acaaaa3dce2cbcdb (patch)
tree5f8b4be4a21dc917441e4d2a1ec3e6fe25fd0192 /Build/source
parentc0da09fd6e4a542610245624c185a66f5ec814b2 (diff)
Imported pdftex 1.40.4
git-svn-id: svn://tug.org/texlive/trunk@4561 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source')
-rw-r--r--Build/source/libs/libpng/ANNOUNCE47
-rw-r--r--Build/source/libs/libpng/CHANGES51
-rw-r--r--Build/source/libs/libpng/INSTALL18
-rw-r--r--Build/source/libs/libpng/KNOWNBUG7
-rw-r--r--Build/source/libs/libpng/LICENSE6
-rw-r--r--Build/source/libs/libpng/README14
-rw-r--r--Build/source/libs/libpng/Y2KINFO4
-rw-r--r--Build/source/libs/libpng/libpng-1.2.18.txt2976
-rw-r--r--Build/source/libs/libpng/libpng.335
-rw-r--r--Build/source/libs/libpng/libpngpf.34
-rw-r--r--Build/source/libs/libpng/png.52
-rw-r--r--Build/source/libs/libpng/png.c19
-rw-r--r--Build/source/libs/libpng/png.h51
-rw-r--r--Build/source/libs/libpng/pngconf.h14
-rw-r--r--Build/source/libs/libpng/pngerror.c2
-rw-r--r--Build/source/libs/libpng/pnggccrd.c44
-rw-r--r--Build/source/libs/libpng/pngpread.c35
-rw-r--r--Build/source/libs/libpng/pngrtran.c8
-rw-r--r--Build/source/libs/libpng/pngrutil.c38
-rw-r--r--Build/source/libs/libpng/pngset.c10
-rw-r--r--Build/source/libs/libpng/pngtest.c2
-rw-r--r--Build/source/libs/libpng/pngtrans.c11
-rw-r--r--Build/source/libs/libpng/pngwutil.c5
-rw-r--r--Build/source/libs/obsdcompat/README9
-rw-r--r--Build/source/libs/obsdcompat/bsd-asprintf.c5
-rw-r--r--Build/source/libs/obsdcompat/bsd-snprintf.c177
-rwxr-xr-xBuild/source/libs/obsdcompat/config.guess122
-rwxr-xr-xBuild/source/libs/obsdcompat/config.sub7
-rw-r--r--Build/source/libs/xpdf/ANNOUNCE13
-rw-r--r--Build/source/libs/xpdf/CHANGES136
-rw-r--r--Build/source/libs/xpdf/INSTALL6
-rw-r--r--Build/source/libs/xpdf/README54
-rw-r--r--Build/source/libs/xpdf/aconf-win32.h38
-rw-r--r--Build/source/libs/xpdf/aconf.h.in25
-rw-r--r--Build/source/libs/xpdf/dj_make.bat17
-rw-r--r--Build/source/libs/xpdf/fofi/FoFiTrueType.cc434
-rw-r--r--Build/source/libs/xpdf/fofi/FoFiTrueType.h40
-rw-r--r--Build/source/libs/xpdf/fofi/FoFiType1.cc65
-rw-r--r--Build/source/libs/xpdf/fofi/FoFiType1C.cc590
-rw-r--r--Build/source/libs/xpdf/fofi/FoFiType1C.h5
-rw-r--r--Build/source/libs/xpdf/goo/FixedPoint.cc29
-rw-r--r--Build/source/libs/xpdf/goo/FixedPoint.h5
-rw-r--r--Build/source/libs/xpdf/goo/GString.cc449
-rw-r--r--Build/source/libs/xpdf/goo/GString.h39
-rw-r--r--Build/source/libs/xpdf/goo/Makefile.in7
-rw-r--r--Build/source/libs/xpdf/goo/depend.mk2
-rw-r--r--Build/source/libs/xpdf/goo/gfile.cc58
-rw-r--r--Build/source/libs/xpdf/goo/gfile.h5
-rw-r--r--Build/source/libs/xpdf/goo/gmem.cc (renamed from Build/source/libs/xpdf/goo/gmem.c)119
-rw-r--r--Build/source/libs/xpdf/goo/gmem.h25
-rw-r--r--Build/source/libs/xpdf/xpdf/Catalog.cc35
-rw-r--r--Build/source/libs/xpdf/xpdf/Catalog.h9
-rw-r--r--Build/source/libs/xpdf/xpdf/Decrypt.cc427
-rw-r--r--Build/source/libs/xpdf/xpdf/Decrypt.h54
-rw-r--r--Build/source/libs/xpdf/xpdf/Function.cc64
-rw-r--r--Build/source/libs/xpdf/xpdf/Function.h8
-rw-r--r--Build/source/libs/xpdf/xpdf/GfxFont.cc28
-rw-r--r--Build/source/libs/xpdf/xpdf/GfxFont.h7
-rw-r--r--Build/source/libs/xpdf/xpdf/GfxState.cc205
-rw-r--r--Build/source/libs/xpdf/xpdf/GfxState.h40
-rw-r--r--Build/source/libs/xpdf/xpdf/GlobalParams.cc1249
-rw-r--r--Build/source/libs/xpdf/xpdf/GlobalParams.h143
-rw-r--r--Build/source/libs/xpdf/xpdf/JBIG2Stream.cc74
-rw-r--r--Build/source/libs/xpdf/xpdf/JBIG2Stream.h4
-rw-r--r--Build/source/libs/xpdf/xpdf/JPXStream.cc235
-rw-r--r--Build/source/libs/xpdf/xpdf/JPXStream.h8
-rw-r--r--Build/source/libs/xpdf/xpdf/Link.cc141
-rw-r--r--Build/source/libs/xpdf/xpdf/Link.h40
-rw-r--r--Build/source/libs/xpdf/xpdf/OutputDev.cc2
-rw-r--r--Build/source/libs/xpdf/xpdf/OutputDev.h59
-rw-r--r--Build/source/libs/xpdf/xpdf/PDFDoc.cc85
-rw-r--r--Build/source/libs/xpdf/xpdf/PDFDoc.h17
-rw-r--r--Build/source/libs/xpdf/xpdf/PSTokenizer.cc2
-rw-r--r--Build/source/libs/xpdf/xpdf/Page.cc226
-rw-r--r--Build/source/libs/xpdf/xpdf/Page.h20
-rw-r--r--Build/source/libs/xpdf/xpdf/Parser.cc61
-rw-r--r--Build/source/libs/xpdf/xpdf/Parser.h11
-rw-r--r--Build/source/libs/xpdf/xpdf/SecurityHandler.cc14
-rw-r--r--Build/source/libs/xpdf/xpdf/SecurityHandler.h5
-rw-r--r--Build/source/libs/xpdf/xpdf/Stream.cc280
-rw-r--r--Build/source/libs/xpdf/xpdf/Stream.h40
-rw-r--r--Build/source/libs/xpdf/xpdf/XRef.cc26
-rw-r--r--Build/source/libs/xpdf/xpdf/XRef.h6
-rw-r--r--Build/source/libs/xpdf/xpdf/config.h17
-rw-r--r--Build/source/texk/kpathsea/cnf.c3
-rw-r--r--Build/source/texk/kpathsea/depend.mak1
-rw-r--r--Build/source/texk/kpathsea/depend.mk1
-rw-r--r--Build/source/texk/kpathsea/kpathsea.h1
-rw-r--r--Build/source/texk/kpathsea/recorder.h30
-rw-r--r--Build/source/texk/web2c/alephdir/com16bit-rc2.ch20
-rw-r--r--Build/source/texk/web2c/cpascal.h2
-rw-r--r--Build/source/texk/web2c/lib/openclose.c37
-rw-r--r--Build/source/texk/web2c/lib/texmfmp.c6
-rw-r--r--Build/source/texk/web2c/omegadir/com16bit.ch20
-rw-r--r--Build/source/texk/web2c/pdftexdir/Makefile.in4
-rw-r--r--Build/source/texk/web2c/pdftexdir/NEWS35
-rw-r--r--Build/source/texk/web2c/pdftexdir/README23
-rw-r--r--Build/source/texk/web2c/pdftexdir/avl.c1135
-rw-r--r--Build/source/texk/web2c/pdftexdir/avlstuff.c8
-rw-r--r--Build/source/texk/web2c/pdftexdir/avlstuff.h10
-rw-r--r--Build/source/texk/web2c/pdftexdir/epdf.c10
-rw-r--r--Build/source/texk/web2c/pdftexdir/epdf.h11
-rw-r--r--Build/source/texk/web2c/pdftexdir/image.h10
-rw-r--r--Build/source/texk/web2c/pdftexdir/macnames.c10
-rw-r--r--Build/source/texk/web2c/pdftexdir/mapfile.c25
-rw-r--r--Build/source/texk/web2c/pdftexdir/pdftex.ch10
-rw-r--r--Build/source/texk/web2c/pdftexdir/pdftex.defines17
-rw-r--r--Build/source/texk/web2c/pdftexdir/pdftex.h10
-rw-r--r--Build/source/texk/web2c/pdftexdir/pdftex.web853
-rw-r--r--Build/source/texk/web2c/pdftexdir/pdftexextra.in10
-rw-r--r--Build/source/texk/web2c/pdftexdir/pdftoepdf.cc29
-rw-r--r--Build/source/texk/web2c/pdftexdir/pdftosrc.cc10
-rw-r--r--Build/source/texk/web2c/pdftexdir/pkin.c10
-rw-r--r--Build/source/texk/web2c/pdftexdir/ptexlib.h30
-rw-r--r--Build/source/texk/web2c/pdftexdir/ptexmac.h10
-rw-r--r--Build/source/texk/web2c/pdftexdir/subfont.c10
-rw-r--r--Build/source/texk/web2c/pdftexdir/tex.ch010
-rw-r--r--Build/source/texk/web2c/pdftexdir/tounicode.c10
-rw-r--r--Build/source/texk/web2c/pdftexdir/ttf2afm.c10
-rw-r--r--Build/source/texk/web2c/pdftexdir/utils.c19
-rw-r--r--Build/source/texk/web2c/pdftexdir/vfpacket.c88
-rw-r--r--Build/source/texk/web2c/pdftexdir/writeenc.c14
-rw-r--r--Build/source/texk/web2c/pdftexdir/writefont.c72
-rw-r--r--Build/source/texk/web2c/pdftexdir/writeimg.c172
-rw-r--r--Build/source/texk/web2c/pdftexdir/writejbig2.c8
-rw-r--r--Build/source/texk/web2c/pdftexdir/writejbig2.h8
-rw-r--r--Build/source/texk/web2c/pdftexdir/writejpg.c10
-rw-r--r--Build/source/texk/web2c/pdftexdir/writepng.c27
-rw-r--r--Build/source/texk/web2c/pdftexdir/writet1.c50
-rw-r--r--Build/source/texk/web2c/pdftexdir/writet3.c23
-rw-r--r--Build/source/texk/web2c/pdftexdir/writettf.c18
-rw-r--r--Build/source/texk/web2c/pdftexdir/writettf.h10
-rw-r--r--Build/source/texk/web2c/pdftexdir/writezip.c53
-rw-r--r--Build/source/texk/web2c/tex.ch20
134 files changed, 9726 insertions, 2823 deletions
diff --git a/Build/source/libs/libpng/ANNOUNCE b/Build/source/libs/libpng/ANNOUNCE
index a7ef3145bcc..aaf5d4a0d13 100644
--- a/Build/source/libs/libpng/ANNOUNCE
+++ b/Build/source/libs/libpng/ANNOUNCE
@@ -1,5 +1,5 @@
-Libpng 1.2.15 - January 5, 2007
+Libpng 1.2.18 - May 15, 2007
This is a public release of libpng, intended for use in production codes.
@@ -8,47 +8,38 @@ Files available for download:
Source files with LF line endings (for Unix/Linux) and with a
"configure" script
- libpng-1.2.15.tar.gz
- libpng-1.2.15.tar.bz2
+ libpng-1.2.18.tar.gz
+ libpng-1.2.18.tar.bz2
Source files with LF line endings (for Unix/Linux) without the
"configure" script
- libpng-1.2.15-no-config.tar.gz
- libpng-1.2.15-no-config.tar.bz2
+ libpng-1.2.18-no-config.tar.gz
+ libpng-1.2.18-no-config.tar.bz2
Source files with CRLF line endings (for Windows), without the
"configure" script
- lpng1215.zip
- lpng1215.tar.bz2
+ lpng1218.zip
+ lpng1218.tar.bz2
Project files
- libpng-1.2.15-project-netware.zip
- libpng-1.2.15-project-wince.zip
+ libpng-1.2.18-project-netware.zip
+ libpng-1.2.18-project-wince.zip
Other information:
- libpng-1.2.15-README.txt
- libpng-1.2.15-KNOWNBUGS.txt
- libpng-1.2.15-LICENSE.txt
- libpng-1.2.15-Y2K-compliance.txt
-
-Changes since the last public release (1.2.14):
-
-version 1.2.15 [January 5, 2007]
-
- Generated configure with autoconf-2.61 instead of 2.60
- Revised configure.ac to update libpng.pc and libpng-config.
- Always export MMX asm functions, just stubs if not building pnggccrd.c
- Add "png_bytep" typecast to profile while calculating length in pngwutil.c
- Added scripts/CMakeLists.txt
- Changed PNG_NO_ASSEMBLER_CODE to PNG_NO_MMX_CODE in scripts, like 1.4.0beta
- Added conditional #undef jmpbuf in pngtest.c to undo #define in AIX headers.
- Added scripts/makefile.nommx
- Fixed handling of rgb_to_gray when png_ptr->color.gray isn't set.
- Added some (unsigned long) typecasts in pngtest.c to avoid printing errors.
+ libpng-1.2.18-README.txt
+ libpng-1.2.18-KNOWNBUGS.txt
+ libpng-1.2.18-LICENSE.txt
+ libpng-1.2.18-Y2K-compliance.txt
+
+Changes since the last public release (1.2.17):
+
+version 1.2.18 [May 15, 2007]
+
+ Reverted the recent change to symbol-handling in configure script
Send comments/corrections/commendations to png-mng-implement at lists.sf.net
(subscription required; visit
diff --git a/Build/source/libs/libpng/CHANGES b/Build/source/libs/libpng/CHANGES
index 89cfb3cfb11..ff2f37942c0 100644
--- a/Build/source/libs/libpng/CHANGES
+++ b/Build/source/libs/libpng/CHANGES
@@ -1480,7 +1480,7 @@ version 1.2.9beta5 [March 4, 2006]
Restored scripts/makefile.elf which was inadvertently deleted.
version 1.2.9beta6 [March 6, 2006]
- Fixed typo (15) in configuration files.
+ Fixed typo (18) in configuration files.
version 1.2.9beta7 [March 7, 2006]
Removed libpng.vers and libpng.sym from libpng12_la_SOURCES in Makefile.am
@@ -1680,6 +1680,55 @@ version 1.2.15rc5 [December 31, 2006]
version 1.2.15 [January 5, 2007]
Added some (unsigned long) typecasts in pngtest.c to avoid printing errors.
+version 1.2.16beta1 [January 6, 2007]
+ Fix bugs in makefile.nommx
+
+version 1.2.16beta2 [January 16, 2007]
+ Revised scripts/CMakeLists.txt
+
+version 1.2.16 [January 31, 2007]
+ No changes.
+
+version 1.2.17beta1 [March 6, 2007]
+ Revised scripts/CMakeLists.txt to install both shared and static libraries.
+ Deleted a redundant line from pngset.c.
+
+version 1.2.17beta2 [April 26, 2007]
+ Relocated misplaced test for png_ptr == NULL in pngpread.c
+ Change "==" to "&" for testing PNG_RGB_TO_GRAY_ERR & PNG_RGB_TO_GRAY_WARN
+ flags.
+ Changed remaining instances of PNG_ASSEMBLER_* to PNG_MMX_*
+ Added pngerror() when write_IHDR fails in deflateInit2().
+ Added "const" to some array declarations.
+ Mention examples of libpng usage in the libpng*.txt and libpng.3 documents.
+
+version 1.2.17rc1 [May 4, 2007]
+ No changes.
+
+version 1.2.17rc2 [May 8, 2007]
+ Moved several PNG_HAVE_* macros out of PNG_INTERNAL because applications
+ calling set_unknown_chunk_location() need them.
+ Changed transformation flag from PNG_EXPAND_tRNS to PNG_EXPAND in
+ png_set_expand_gray_1_2_4_to_8().
+ Added png_ptr->unknown_chunk to hold working unknown chunk data, so it
+ can be free'ed in case of error. Revised unknown chunk handling in
+ pngrutil.c and pngpread.c to use this structure.
+
+version 1.2.17rc3 [May 8, 2007]
+ Revised symbol-handling in configure script.
+
+version 1.2.17rc4 [May 10, 2007]
+ Revised unknown chunk handling to avoid storing unknown critical chunks.
+
+version 1.0.25 [May 15, 2007]
+version 1.2.17 [May 15, 2007]
+ Added "png_ptr->num_trans=0" before error return in png_handle_tRNS,
+ to eliminate a vulnerability (CVE-2007-2554, CERT VU#684664)
+
+version 1.0.26 [May 15, 2007]
+version 1.2.18 [May 15, 2007]
+ Reverted the libpng-1.2.17rc3 change to symbol-handling in configure script
+
Send comments/corrections/commendations to png-mng-implement at lists.sf.net
(subscription required; visit
https://lists.sourceforge.net/lists/listinfo/png-mng-implement
diff --git a/Build/source/libs/libpng/INSTALL b/Build/source/libs/libpng/INSTALL
index 9fb7c8ee71a..01ef8b87c56 100644
--- a/Build/source/libs/libpng/INSTALL
+++ b/Build/source/libs/libpng/INSTALL
@@ -1,5 +1,5 @@
-Installing libpng version 1.2.15 - January 5, 2007
+Installing libpng version 1.2.18 - May 15, 2007
On Unix/Linux and similar systems, you can simply type
@@ -44,7 +44,7 @@ to have access to the zlib.h and zconf.h include files that
correspond to the version of zlib that's installed.
You can rename the directories that you downloaded (they
-might be called "libpng-1.2.15" or "lpng109" and "zlib-1.2.1"
+might be called "libpng-1.2.18" or "lpng109" and "zlib-1.2.1"
or "zlib121") so that you have directories called "zlib" and "libpng".
Your directory structure should look like this:
@@ -101,14 +101,14 @@ include
CMakeLists.txt => "cmake" script
makefile.std => Generic UNIX makefile (cc, creates static libpng.a)
makefile.elf => Linux/ELF makefile symbol versioning,
- gcc, creates libpng12.so.0.1.2.15)
+ gcc, creates libpng12.so.0.1.2.18)
makefile.linux => Linux/ELF makefile
- (gcc, creates libpng12.so.0.1.2.15)
+ (gcc, creates libpng12.so.0.1.2.18)
makefile.gcmmx => Linux/ELF makefile
- (gcc, creates libpng12.so.0.1.2.15,
+ (gcc, creates libpng12.so.0.1.2.18,
uses assembler code tuned for Intel MMX platform)
makefile.nommx => Linux/ELF makefile
- (gcc, creates libpng12.so.0.1.2.15
+ (gcc, creates libpng12.so.0.1.2.18
does not use Intel MMX assembler code)
makefile.gcc => Generic makefile (gcc, creates static libpng.a)
makefile.knr => Archaic UNIX Makefile that converts files with
@@ -131,12 +131,12 @@ include
makefile.openbsd => OpenBSD makefile
makefile.sgi => Silicon Graphics IRIX makefile (cc, creates static lib)
makefile.sggcc => Silicon Graphics (gcc,
- creates libpng12.so.0.1.2.15)
+ creates libpng12.so.0.1.2.18)
makefile.sunos => Sun makefile
makefile.solaris => Solaris 2.X makefile (gcc,
- creates libpng12.so.0.1.2.15)
+ creates libpng12.so.0.1.2.18)
makefile.so9 => Solaris 9 makefile (gcc,
- creates libpng12.so.0.1.2.15)
+ creates libpng12.so.0.1.2.18)
makefile.32sunu => Sun Ultra 32-bit makefile
makefile.64sunu => Sun Ultra 64-bit makefile
makefile.sco => For SCO OSr5 ELF and Unixware 7 with Native cc
diff --git a/Build/source/libs/libpng/KNOWNBUG b/Build/source/libs/libpng/KNOWNBUG
index a5ee1f385fc..7052ccd067a 100644
--- a/Build/source/libs/libpng/KNOWNBUG
+++ b/Build/source/libs/libpng/KNOWNBUG
@@ -1,5 +1,5 @@
-Known bugs in libpng version 1.2.15
+Known bugs in libpng version 1.2.18
1. April 22, 2001: pnggccrd.c has been reported to crash on NetBSD when
reading interlaced PNG files, when assembler code is enabled but running
@@ -21,3 +21,8 @@ Known bugs in libpng version 1.2.15
STATUS: For now, system library builders should use the custom makefiles.
+4. March 2007: Building 1.2.16 with PNG_ASSEMBLER_CODE_SUPPORTED;
+ PNG_MMX_CODE_SUPPORTED results in multiple definitions of png_combine_row,
+ png_do_read_interlace, and png_read_filter_row
+
+ STATUS: Investigating.
diff --git a/Build/source/libs/libpng/LICENSE b/Build/source/libs/libpng/LICENSE
index 3b68cf272d8..1d62448c314 100644
--- a/Build/source/libs/libpng/LICENSE
+++ b/Build/source/libs/libpng/LICENSE
@@ -8,8 +8,8 @@ COPYRIGHT NOTICE, DISCLAIMER, and LICENSE:
If you modify libpng you may insert additional notices immediately following
this sentence.
-libpng versions 1.2.6, August 15, 2004, through 1.2.15, January 5, 2007, are
-Copyright (c) 2004, 2006 Glenn Randers-Pehrson, and are
+libpng versions 1.2.6, August 15, 2004, through 1.2.18, May 15, 2007, are
+Copyright (c) 2004, 2006-2007 Glenn Randers-Pehrson, and are
distributed according to the same disclaimer and license as libpng-1.2.5
with the following individual added to the list of Contributing Authors
@@ -106,4 +106,4 @@ certification mark of the Open Source Initiative.
Glenn Randers-Pehrson
glennrp at users.sourceforge.net
-January 5, 2007
+May 15, 2007
diff --git a/Build/source/libs/libpng/README b/Build/source/libs/libpng/README
index 6d83a1294ba..94d64aaecfc 100644
--- a/Build/source/libs/libpng/README
+++ b/Build/source/libs/libpng/README
@@ -1,4 +1,4 @@
-README for libpng version 1.2.15 - January 5, 2007 (shared library 12.0)
+README for libpng version 1.2.18 - May 15, 2007 (shared library 12.0)
See the note about version numbers near the top of png.h
See INSTALL for instructions on how to install libpng.
@@ -190,11 +190,11 @@ Files in this distribution:
descrip.mms => VMS makefile for MMS or MMK
makefile.std => Generic UNIX makefile (cc, creates static libpng.a)
makefile.elf => Linux/ELF makefile symbol versioning,
- gcc, creates libpng12.so.0.1.2.15)
+ gcc, creates libpng12.so.0.1.2.18)
makefile.linux => Linux/ELF makefile
- (gcc, creates libpng12.so.0.1.2.15)
+ (gcc, creates libpng12.so.0.1.2.18)
makefile.gcmmx => Linux/ELF makefile
- (gcc, creates libpng12.so.0.1.2.15,
+ (gcc, creates libpng12.so.0.1.2.18,
uses assembler code tuned for Intel MMX platform)
makefile.gcc => Generic makefile (gcc, creates static libpng.a)
makefile.knr => Archaic UNIX Makefile that converts files with
@@ -216,12 +216,12 @@ Files in this distribution:
makefile.openbsd => OpenBSD makefile
makefile.sgi => Silicon Graphics IRIX (cc, creates static lib)
makefile.sggcc => Silicon Graphics
- (gcc, creates libpng12.so.0.1.2.15)
+ (gcc, creates libpng12.so.0.1.2.18)
makefile.sunos => Sun makefile
makefile.solaris => Solaris 2.X makefile
- (gcc, creates libpng12.so.0.1.2.15)
+ (gcc, creates libpng12.so.0.1.2.18)
makefile.so9 => Solaris 9 makefile
- (gcc, creates libpng12.so.0.1.2.15)
+ (gcc, creates libpng12.so.0.1.2.18)
makefile.32sunu => Sun Ultra 32-bit makefile
makefile.64sunu => Sun Ultra 64-bit makefile
makefile.sco => For SCO OSr5 ELF and Unixware 7 with Native cc
diff --git a/Build/source/libs/libpng/Y2KINFO b/Build/source/libs/libpng/Y2KINFO
index 2fd51989f68..aa690e4ef46 100644
--- a/Build/source/libs/libpng/Y2KINFO
+++ b/Build/source/libs/libpng/Y2KINFO
@@ -1,13 +1,13 @@
Y2K compliance in libpng:
=========================
- January 5, 2007
+ May 15, 2007
Since the PNG Development group is an ad-hoc body, we can't make
an official declaration.
This is your unofficial assurance that libpng from version 0.71 and
- upward through 1.2.15 are Y2K compliant. It is my belief that earlier
+ upward through 1.2.18 are Y2K compliant. It is my belief that earlier
versions were also Y2K compliant.
Libpng only has three year fields. One is a 2-byte unsigned integer
diff --git a/Build/source/libs/libpng/libpng-1.2.18.txt b/Build/source/libs/libpng/libpng-1.2.18.txt
new file mode 100644
index 00000000000..1b251546ef8
--- /dev/null
+++ b/Build/source/libs/libpng/libpng-1.2.18.txt
@@ -0,0 +1,2976 @@
+libpng.txt - A description on how to use and modify libpng
+
+ libpng version 1.2.18 - May 15, 2007
+ Updated and distributed by Glenn Randers-Pehrson
+ <glennrp at users.sourceforge.net>
+ Copyright (c) 1998-2007 Glenn Randers-Pehrson
+ For conditions of distribution and use, see copyright
+ notice in png.h.
+
+ based on:
+
+ libpng 1.0 beta 6 version 0.96 May 28, 1997
+ Updated and distributed by Andreas Dilger
+ Copyright (c) 1996, 1997 Andreas Dilger
+
+ libpng 1.0 beta 2 - version 0.88 January 26, 1996
+ For conditions of distribution and use, see copyright
+ notice in png.h. Copyright (c) 1995, 1996 Guy Eric
+ Schalnat, Group 42, Inc.
+
+ Updated/rewritten per request in the libpng FAQ
+ Copyright (c) 1995, 1996 Frank J. T. Wojcik
+ December 18, 1995 & January 20, 1996
+
+I. Introduction
+
+This file describes how to use and modify the PNG reference library
+(known as libpng) for your own use. There are five sections to this
+file: introduction, structures, reading, writing, and modification and
+configuration notes for various special platforms. In addition to this
+file, example.c is a good starting point for using the library, as
+it is heavily commented and should include everything most people
+will need. We assume that libpng is already installed; see the
+INSTALL file for instructions on how to install libpng.
+
+For examples of libpng usage, see the files "example.c", "pngtest.c",
+and the files in the "contrib" directory, all of which are included in the
+libpng distribution.
+
+Libpng was written as a companion to the PNG specification, as a way
+of reducing the amount of time and effort it takes to support the PNG
+file format in application programs.
+
+The PNG specification (second edition), November 2003, is available as
+a W3C Recommendation and as an ISO Standard (ISO/IEC 15948:2003 (E)) at
+<http://www.w3.org/TR/2003/REC-PNG-20031110/
+The W3C and ISO documents have identical technical content.
+
+The PNG-1.2 specification is available at
+<http://www.libpng.org/pub/png/documents/>
+
+The PNG-1.0 specification is available
+as RFC 2083 <http://www.libpng.org/pub/png/documents/> and as a
+W3C Recommendation <http://www.w3.org/TR/REC.png.html>. Some
+additional chunks are described in the special-purpose public chunks
+documents at <http://www.libpng.org/pub/png/documents/>.
+
+Other information
+about PNG, and the latest version of libpng, can be found at the PNG home
+page, <http://www.libpng.org/pub/png/>.
+
+Most users will not have to modify the library significantly; advanced
+users may want to modify it more. All attempts were made to make it as
+complete as possible, while keeping the code easy to understand.
+Currently, this library only supports C. Support for other languages
+is being considered.
+
+Libpng has been designed to handle multiple sessions at one time,
+to be easily modifiable, to be portable to the vast majority of
+machines (ANSI, K&R, 16-, 32-, and 64-bit) available, and to be easy
+to use. The ultimate goal of libpng is to promote the acceptance of
+the PNG file format in whatever way possible. While there is still
+work to be done (see the TODO file), libpng should cover the
+majority of the needs of its users.
+
+Libpng uses zlib for its compression and decompression of PNG files.
+Further information about zlib, and the latest version of zlib, can
+be found at the zlib home page, <http://www.info-zip.org/pub/infozip/zlib/>.
+The zlib compression utility is a general purpose utility that is
+useful for more than PNG files, and can be used without libpng.
+See the documentation delivered with zlib for more details.
+You can usually find the source files for the zlib utility wherever you
+find the libpng source files.
+
+Libpng is thread safe, provided the threads are using different
+instances of the structures. Each thread should have its own
+png_struct and png_info instances, and thus its own image.
+Libpng does not protect itself against two threads using the
+same instance of a structure. Note: thread safety may be defeated
+by use of some of the MMX assembler code in pnggccrd.c, which is only
+compiled when the user defines PNG_THREAD_UNSAFE_OK.
+
+II. Structures
+
+There are two main structures that are important to libpng, png_struct
+and png_info. The first, png_struct, is an internal structure that
+will not, for the most part, be used by a user except as the first
+variable passed to every libpng function call.
+
+The png_info structure is designed to provide information about the
+PNG file. At one time, the fields of png_info were intended to be
+directly accessible to the user. However, this tended to cause problems
+with applications using dynamically loaded libraries, and as a result
+a set of interface functions for png_info (the png_get_*() and png_set_*()
+functions) was developed. The fields of png_info are still available for
+older applications, but it is suggested that applications use the new
+interfaces if at all possible.
+
+Applications that do make direct access to the members of png_struct (except
+for png_ptr->jmpbuf) must be recompiled whenever the library is updated,
+and applications that make direct access to the members of png_info must
+be recompiled if they were compiled or loaded with libpng version 1.0.6,
+in which the members were in a different order. In version 1.0.7, the
+members of the png_info structure reverted to the old order, as they were
+in versions 0.97c through 1.0.5. Starting with version 2.0.0, both
+structures are going to be hidden, and the contents of the structures will
+only be accessible through the png_get/png_set functions.
+
+The png.h header file is an invaluable reference for programming with libpng.
+And while I'm on the topic, make sure you include the libpng header file:
+
+#include <png.h>
+
+III. Reading
+
+We'll now walk you through the possible functions to call when reading
+in a PNG file sequentially, briefly explaining the syntax and purpose
+of each one. See example.c and png.h for more detail. While
+progressive reading is covered in the next section, you will still
+need some of the functions discussed in this section to read a PNG
+file.
+
+Setup
+
+You will want to do the I/O initialization(*) before you get into libpng,
+so if it doesn't work, you don't have much to undo. Of course, you
+will also want to insure that you are, in fact, dealing with a PNG
+file. Libpng provides a simple check to see if a file is a PNG file.
+To use it, pass in the first 1 to 8 bytes of the file to the function
+png_sig_cmp(), and it will return 0 if the bytes match the corresponding
+bytes of the PNG signature, or nonzero otherwise. Of course, the more bytes
+you pass in, the greater the accuracy of the prediction.
+
+If you are intending to keep the file pointer open for use in libpng,
+you must ensure you don't read more than 8 bytes from the beginning
+of the file, and you also have to make a call to png_set_sig_bytes_read()
+with the number of bytes you read from the beginning. Libpng will
+then only check the bytes (if any) that your program didn't read.
+
+(*): If you are not using the standard I/O functions, you will need
+to replace them with custom functions. See the discussion under
+Customizing libpng.
+
+
+ FILE *fp = fopen(file_name, "rb");
+ if (!fp)
+ {
+ return (ERROR);
+ }
+ fread(header, 1, number, fp);
+ is_png = !png_sig_cmp(header, 0, number);
+ if (!is_png)
+ {
+ return (NOT_PNG);
+ }
+
+
+Next, png_struct and png_info need to be allocated and initialized. In
+order to ensure that the size of these structures is correct even with a
+dynamically linked libpng, there are functions to initialize and
+allocate the structures. We also pass the library version, optional
+pointers to error handling functions, and a pointer to a data struct for
+use by the error functions, if necessary (the pointer and functions can
+be NULL if the default error handlers are to be used). See the section
+on Changes to Libpng below regarding the old initialization functions.
+The structure allocation functions quietly return NULL if they fail to
+create the structure, so your application should check for that.
+
+ png_structp png_ptr = png_create_read_struct
+ (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
+ user_error_fn, user_warning_fn);
+ if (!png_ptr)
+ return (ERROR);
+
+ png_infop info_ptr = png_create_info_struct(png_ptr);
+ if (!info_ptr)
+ {
+ png_destroy_read_struct(&png_ptr,
+ (png_infopp)NULL, (png_infopp)NULL);
+ return (ERROR);
+ }
+
+ png_infop end_info = png_create_info_struct(png_ptr);
+ if (!end_info)
+ {
+ png_destroy_read_struct(&png_ptr, &info_ptr,
+ (png_infopp)NULL);
+ return (ERROR);
+ }
+
+If you want to use your own memory allocation routines,
+define PNG_USER_MEM_SUPPORTED and use
+png_create_read_struct_2() instead of png_create_read_struct():
+
+ png_structp png_ptr = png_create_read_struct_2
+ (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
+ user_error_fn, user_warning_fn, (png_voidp)
+ user_mem_ptr, user_malloc_fn, user_free_fn);
+
+The error handling routines passed to png_create_read_struct()
+and the memory alloc/free routines passed to png_create_struct_2()
+are only necessary if you are not using the libpng supplied error
+handling and memory alloc/free functions.
+
+When libpng encounters an error, it expects to longjmp back
+to your routine. Therefore, you will need to call setjmp and pass
+your png_jmpbuf(png_ptr). If you read the file from different
+routines, you will need to update the jmpbuf field every time you enter
+a new routine that will call a png_*() function.
+
+See your documentation of setjmp/longjmp for your compiler for more
+information on setjmp/longjmp. See the discussion on libpng error
+handling in the Customizing Libpng section below for more information
+on the libpng error handling. If an error occurs, and libpng longjmp's
+back to your setjmp, you will want to call png_destroy_read_struct() to
+free any memory.
+
+ if (setjmp(png_jmpbuf(png_ptr)))
+ {
+ png_destroy_read_struct(&png_ptr, &info_ptr,
+ &end_info);
+ fclose(fp);
+ return (ERROR);
+ }
+
+If you would rather avoid the complexity of setjmp/longjmp issues,
+you can compile libpng with PNG_SETJMP_NOT_SUPPORTED, in which case
+errors will result in a call to PNG_ABORT() which defaults to abort().
+
+Now you need to set up the input code. The default for libpng is to
+use the C function fread(). If you use this, you will need to pass a
+valid FILE * in the function png_init_io(). Be sure that the file is
+opened in binary mode. If you wish to handle reading data in another
+way, you need not call the png_init_io() function, but you must then
+implement the libpng I/O methods discussed in the Customizing Libpng
+section below.
+
+ png_init_io(png_ptr, fp);
+
+If you had previously opened the file and read any of the signature from
+the beginning in order to see if this was a PNG file, you need to let
+libpng know that there are some bytes missing from the start of the file.
+
+ png_set_sig_bytes(png_ptr, number);
+
+Setting up callback code
+
+You can set up a callback function to handle any unknown chunks in the
+input stream. You must supply the function
+
+ read_chunk_callback(png_ptr ptr,
+ png_unknown_chunkp chunk);
+ {
+ /* The unknown chunk structure contains your
+ chunk data: */
+ png_byte name[5];
+ png_byte *data;
+ png_size_t size;
+ /* Note that libpng has already taken care of
+ the CRC handling */
+
+ /* put your code here. Return one of the
+ following: */
+
+ return (-n); /* chunk had an error */
+ return (0); /* did not recognize */
+ return (n); /* success */
+ }
+
+(You can give your function another name that you like instead of
+"read_chunk_callback")
+
+To inform libpng about your function, use
+
+ png_set_read_user_chunk_fn(png_ptr, user_chunk_ptr,
+ read_chunk_callback);
+
+This names not only the callback function, but also a user pointer that
+you can retrieve with
+
+ png_get_user_chunk_ptr(png_ptr);
+
+At this point, you can set up a callback function that will be
+called after each row has been read, which you can use to control
+a progress meter or the like. It's demonstrated in pngtest.c.
+You must supply a function
+
+ void read_row_callback(png_ptr ptr, png_uint_32 row,
+ int pass);
+ {
+ /* put your code here */
+ }
+
+(You can give it another name that you like instead of "read_row_callback")
+
+To inform libpng about your function, use
+
+ png_set_read_status_fn(png_ptr, read_row_callback);
+
+Width and height limits
+
+The PNG specification allows the width and height of an image to be as
+large as 2^31-1 (0x7fffffff), or about 2.147 billion rows and columns.
+Since very few applications really need to process such large images,
+we have imposed an arbitrary 1-million limit on rows and columns.
+Larger images will be rejected immediately with a png_error() call. If
+you wish to override this limit, you can use
+
+ png_set_user_limits(png_ptr, width_max, height_max);
+
+to set your own limits, or use width_max = height_max = 0x7fffffffL
+to allow all valid dimensions (libpng may reject some very large images
+anyway because of potential buffer overflow conditions).
+
+You should put this statement after you create the PNG structure and
+before calling png_read_info(), png_read_png(), or png_process_data().
+If you need to retrieve the limits that are being applied, use
+
+ width_max = png_get_user_width_max(png_ptr);
+ height_max = png_get_user_height_max(png_ptr);
+
+Unknown-chunk handling
+
+Now you get to set the way the library processes unknown chunks in the
+input PNG stream. Both known and unknown chunks will be read. Normal
+behavior is that known chunks will be parsed into information in
+various info_ptr members; unknown chunks will be discarded. To change
+this, you can call:
+
+ png_set_keep_unknown_chunks(png_ptr, keep,
+ chunk_list, num_chunks);
+ keep - 0: do not handle as unknown
+ 1: do not keep
+ 2: keep only if safe-to-copy
+ 3: keep even if unsafe-to-copy
+ You can use these definitions:
+ PNG_HANDLE_CHUNK_AS_DEFAULT 0
+ PNG_HANDLE_CHUNK_NEVER 1
+ PNG_HANDLE_CHUNK_IF_SAFE 2
+ PNG_HANDLE_CHUNK_ALWAYS 3
+ chunk_list - list of chunks affected (a byte string,
+ five bytes per chunk, NULL or '\0' if
+ num_chunks is 0)
+ num_chunks - number of chunks affected; if 0, all
+ unknown chunks are affected. If nonzero,
+ only the chunks in the list are affected
+
+Unknown chunks declared in this way will be saved as raw data onto a
+list of png_unknown_chunk structures. If a chunk that is normally
+known to libpng is named in the list, it will be handled as unknown,
+according to the "keep" directive. If a chunk is named in successive
+instances of png_set_keep_unknown_chunks(), the final instance will
+take precedence. The IHDR and IEND chunks should not be named in
+chunk_list; if they are, libpng will process them normally anyway.
+
+The high-level read interface
+
+At this point there are two ways to proceed; through the high-level
+read interface, or through a sequence of low-level read operations.
+You can use the high-level interface if (a) you are willing to read
+the entire image into memory, and (b) the input transformations
+you want to do are limited to the following set:
+
+ PNG_TRANSFORM_IDENTITY No transformation
+ PNG_TRANSFORM_STRIP_16 Strip 16-bit samples to
+ 8 bits
+ PNG_TRANSFORM_STRIP_ALPHA Discard the alpha channel
+ PNG_TRANSFORM_PACKING Expand 1, 2 and 4-bit
+ samples to bytes
+ PNG_TRANSFORM_PACKSWAP Change order of packed
+ pixels to LSB first
+ PNG_TRANSFORM_EXPAND Perform set_expand()
+ PNG_TRANSFORM_INVERT_MONO Invert monochrome images
+ PNG_TRANSFORM_SHIFT Normalize pixels to the
+ sBIT depth
+ PNG_TRANSFORM_BGR Flip RGB to BGR, RGBA
+ to BGRA
+ PNG_TRANSFORM_SWAP_ALPHA Flip RGBA to ARGB or GA
+ to AG
+ PNG_TRANSFORM_INVERT_ALPHA Change alpha from opacity
+ to transparency
+ PNG_TRANSFORM_SWAP_ENDIAN Byte-swap 16-bit samples
+
+(This excludes setting a background color, doing gamma transformation,
+dithering, and setting filler.) If this is the case, simply do this:
+
+ png_read_png(png_ptr, info_ptr, png_transforms, NULL)
+
+where png_transforms is an integer containing the bitwise OR of
+some set of transformation flags. This call is equivalent to png_read_info(),
+followed the set of transformations indicated by the transform mask,
+then png_read_image(), and finally png_read_end().
+
+(The final parameter of this call is not yet used. Someday it might point
+to transformation parameters required by some future input transform.)
+
+You must use png_transforms and not call any png_set_transform() functions
+when you use png_read_png().
+
+After you have called png_read_png(), you can retrieve the image data
+with
+
+ row_pointers = png_get_rows(png_ptr, info_ptr);
+
+where row_pointers is an array of pointers to the pixel data for each row:
+
+ png_bytep row_pointers[height];
+
+If you know your image size and pixel size ahead of time, you can allocate
+row_pointers prior to calling png_read_png() with
+
+ if (height > PNG_UINT_32_MAX/png_sizeof(png_byte))
+ png_error (png_ptr,
+ "Image is too tall to process in memory");
+ if (width > PNG_UINT_32_MAX/pixel_size)
+ png_error (png_ptr,
+ "Image is too wide to process in memory");
+ row_pointers = png_malloc(png_ptr,
+ height*png_sizeof(png_bytep));
+ for (int i=0; i<height, i++)
+ row_pointers[i]=png_malloc(png_ptr,
+ width*pixel_size);
+ png_set_rows(png_ptr, info_ptr, &row_pointers);
+
+Alternatively you could allocate your image in one big block and define
+row_pointers[i] to point into the proper places in your block.
+
+If you use png_set_rows(), the application is responsible for freeing
+row_pointers (and row_pointers[i], if they were separately allocated).
+
+If you don't allocate row_pointers ahead of time, png_read_png() will
+do it, and it'll be free'ed when you call png_destroy_*().
+
+The low-level read interface
+
+If you are going the low-level route, you are now ready to read all
+the file information up to the actual image data. You do this with a
+call to png_read_info().
+
+ png_read_info(png_ptr, info_ptr);
+
+This will process all chunks up to but not including the image data.
+
+Querying the info structure
+
+Functions are used to get the information from the info_ptr once it
+has been read. Note that these fields may not be completely filled
+in until png_read_end() has read the chunk data following the image.
+
+ png_get_IHDR(png_ptr, info_ptr, &width, &height,
+ &bit_depth, &color_type, &interlace_type,
+ &compression_type, &filter_method);
+
+ width - holds the width of the image
+ in pixels (up to 2^31).
+ height - holds the height of the image
+ in pixels (up to 2^31).
+ bit_depth - holds the bit depth of one of the
+ image channels. (valid values are
+ 1, 2, 4, 8, 16 and depend also on
+ the color_type. See also
+ significant bits (sBIT) below).
+ color_type - describes which color/alpha channels
+ are present.
+ PNG_COLOR_TYPE_GRAY
+ (bit depths 1, 2, 4, 8, 16)
+ PNG_COLOR_TYPE_GRAY_ALPHA
+ (bit depths 8, 16)
+ PNG_COLOR_TYPE_PALETTE
+ (bit depths 1, 2, 4, 8)
+ PNG_COLOR_TYPE_RGB
+ (bit_depths 8, 16)
+ PNG_COLOR_TYPE_RGB_ALPHA
+ (bit_depths 8, 16)
+
+ PNG_COLOR_MASK_PALETTE
+ PNG_COLOR_MASK_COLOR
+ PNG_COLOR_MASK_ALPHA
+
+ filter_method - (must be PNG_FILTER_TYPE_BASE
+ for PNG 1.0, and can also be
+ PNG_INTRAPIXEL_DIFFERENCING if
+ the PNG datastream is embedded in
+ a MNG-1.0 datastream)
+ compression_type - (must be PNG_COMPRESSION_TYPE_BASE
+ for PNG 1.0)
+ interlace_type - (PNG_INTERLACE_NONE or
+ PNG_INTERLACE_ADAM7)
+ Any or all of interlace_type, compression_type, of
+ filter_method can be NULL if you are
+ not interested in their values.
+
+ channels = png_get_channels(png_ptr, info_ptr);
+ channels - number of channels of info for the
+ color type (valid values are 1 (GRAY,
+ PALETTE), 2 (GRAY_ALPHA), 3 (RGB),
+ 4 (RGB_ALPHA or RGB + filler byte))
+ rowbytes = png_get_rowbytes(png_ptr, info_ptr);
+ rowbytes - number of bytes needed to hold a row
+
+ signature = png_get_signature(png_ptr, info_ptr);
+ signature - holds the signature read from the
+ file (if any). The data is kept in
+ the same offset it would be if the
+ whole signature were read (i.e. if an
+ application had already read in 4
+ bytes of signature before starting
+ libpng, the remaining 4 bytes would
+ be in signature[4] through signature[7]
+ (see png_set_sig_bytes())).
+
+
+ width = png_get_image_width(png_ptr,
+ info_ptr);
+ height = png_get_image_height(png_ptr,
+ info_ptr);
+ bit_depth = png_get_bit_depth(png_ptr,
+ info_ptr);
+ color_type = png_get_color_type(png_ptr,
+ info_ptr);
+ filter_method = png_get_filter_type(png_ptr,
+ info_ptr);
+ compression_type = png_get_compression_type(png_ptr,
+ info_ptr);
+ interlace_type = png_get_interlace_type(png_ptr,
+ info_ptr);
+
+
+These are also important, but their validity depends on whether the chunk
+has been read. The png_get_valid(png_ptr, info_ptr, PNG_INFO_<chunk>) and
+png_get_<chunk>(png_ptr, info_ptr, ...) functions return non-zero if the
+data has been read, or zero if it is missing. The parameters to the
+png_get_<chunk> are set directly if they are simple data types, or a pointer
+into the info_ptr is returned for any complex types.
+
+ png_get_PLTE(png_ptr, info_ptr, &palette,
+ &num_palette);
+ palette - the palette for the file
+ (array of png_color)
+ num_palette - number of entries in the palette
+
+ png_get_gAMA(png_ptr, info_ptr, &gamma);
+ gamma - the gamma the file is written
+ at (PNG_INFO_gAMA)
+
+ png_get_sRGB(png_ptr, info_ptr, &srgb_intent);
+ srgb_intent - the rendering intent (PNG_INFO_sRGB)
+ The presence of the sRGB chunk
+ means that the pixel data is in the
+ sRGB color space. This chunk also
+ implies specific values of gAMA and
+ cHRM.
+
+ png_get_iCCP(png_ptr, info_ptr, &name,
+ &compression_type, &profile, &proflen);
+ name - The profile name.
+ compression - The compression type; always
+ PNG_COMPRESSION_TYPE_BASE for PNG 1.0.
+ You may give NULL to this argument to
+ ignore it.
+ profile - International Color Consortium color
+ profile data. May contain NULs.
+ proflen - length of profile data in bytes.
+
+ png_get_sBIT(png_ptr, info_ptr, &sig_bit);
+ sig_bit - the number of significant bits for
+ (PNG_INFO_sBIT) each of the gray,
+ red, green, and blue channels,
+ whichever are appropriate for the
+ given color type (png_color_16)
+
+ png_get_tRNS(png_ptr, info_ptr, &trans, &num_trans,
+ &trans_values);
+ trans - array of transparent entries for
+ palette (PNG_INFO_tRNS)
+ trans_values - graylevel or color sample values of
+ the single transparent color for
+ non-paletted images (PNG_INFO_tRNS)
+ num_trans - number of transparent entries
+ (PNG_INFO_tRNS)
+
+ png_get_hIST(png_ptr, info_ptr, &hist);
+ (PNG_INFO_hIST)
+ hist - histogram of palette (array of
+ png_uint_16)
+
+ png_get_tIME(png_ptr, info_ptr, &mod_time);
+ mod_time - time image was last modified
+ (PNG_VALID_tIME)
+
+ png_get_bKGD(png_ptr, info_ptr, &background);
+ background - background color (PNG_VALID_bKGD)
+ valid 16-bit red, green and blue
+ values, regardless of color_type
+
+ num_comments = png_get_text(png_ptr, info_ptr,
+ &text_ptr, &num_text);
+ num_comments - number of comments
+ text_ptr - array of png_text holding image
+ comments
+ text_ptr[i].compression - type of compression used
+ on "text" PNG_TEXT_COMPRESSION_NONE
+ PNG_TEXT_COMPRESSION_zTXt
+ PNG_ITXT_COMPRESSION_NONE
+ PNG_ITXT_COMPRESSION_zTXt
+ text_ptr[i].key - keyword for comment. Must contain
+ 1-79 characters.
+ text_ptr[i].text - text comments for current
+ keyword. Can be empty.
+ text_ptr[i].text_length - length of text string,
+ after decompression, 0 for iTXt
+ text_ptr[i].itxt_length - length of itxt string,
+ after decompression, 0 for tEXt/zTXt
+ text_ptr[i].lang - language of comment (empty
+ string for unknown).
+ text_ptr[i].lang_key - keyword in UTF-8
+ (empty string for unknown).
+ num_text - number of comments (same as
+ num_comments; you can put NULL here
+ to avoid the duplication)
+ Note while png_set_text() will accept text, language,
+ and translated keywords that can be NULL pointers, the
+ structure returned by png_get_text will always contain
+ regular zero-terminated C strings. They might be
+ empty strings but they will never be NULL pointers.
+
+ num_spalettes = png_get_sPLT(png_ptr, info_ptr,
+ &palette_ptr);
+ palette_ptr - array of palette structures holding
+ contents of one or more sPLT chunks
+ read.
+ num_spalettes - number of sPLT chunks read.
+
+ png_get_oFFs(png_ptr, info_ptr, &offset_x, &offset_y,
+ &unit_type);
+ offset_x - positive offset from the left edge
+ of the screen
+ offset_y - positive offset from the top edge
+ of the screen
+ unit_type - PNG_OFFSET_PIXEL, PNG_OFFSET_MICROMETER
+
+ png_get_pHYs(png_ptr, info_ptr, &res_x, &res_y,
+ &unit_type);
+ res_x - pixels/unit physical resolution in
+ x direction
+ res_y - pixels/unit physical resolution in
+ x direction
+ unit_type - PNG_RESOLUTION_UNKNOWN,
+ PNG_RESOLUTION_METER
+
+ png_get_sCAL(png_ptr, info_ptr, &unit, &width,
+ &height)
+ unit - physical scale units (an integer)
+ width - width of a pixel in physical scale units
+ height - height of a pixel in physical scale units
+ (width and height are doubles)
+
+ png_get_sCAL_s(png_ptr, info_ptr, &unit, &width,
+ &height)
+ unit - physical scale units (an integer)
+ width - width of a pixel in physical scale units
+ height - height of a pixel in physical scale units
+ (width and height are strings like "2.54")
+
+ num_unknown_chunks = png_get_unknown_chunks(png_ptr,
+ info_ptr, &unknowns)
+ unknowns - array of png_unknown_chunk
+ structures holding unknown chunks
+ unknowns[i].name - name of unknown chunk
+ unknowns[i].data - data of unknown chunk
+ unknowns[i].size - size of unknown chunk's data
+ unknowns[i].location - position of chunk in file
+
+ The value of "i" corresponds to the order in which the
+ chunks were read from the PNG file or inserted with the
+ png_set_unknown_chunks() function.
+
+The data from the pHYs chunk can be retrieved in several convenient
+forms:
+
+ res_x = png_get_x_pixels_per_meter(png_ptr,
+ info_ptr)
+ res_y = png_get_y_pixels_per_meter(png_ptr,
+ info_ptr)
+ res_x_and_y = png_get_pixels_per_meter(png_ptr,
+ info_ptr)
+ res_x = png_get_x_pixels_per_inch(png_ptr,
+ info_ptr)
+ res_y = png_get_y_pixels_per_inch(png_ptr,
+ info_ptr)
+ res_x_and_y = png_get_pixels_per_inch(png_ptr,
+ info_ptr)
+ aspect_ratio = png_get_pixel_aspect_ratio(png_ptr,
+ info_ptr)
+
+ (Each of these returns 0 [signifying "unknown"] if
+ the data is not present or if res_x is 0;
+ res_x_and_y is 0 if res_x != res_y)
+
+The data from the oFFs chunk can be retrieved in several convenient
+forms:
+
+ x_offset = png_get_x_offset_microns(png_ptr, info_ptr);
+ y_offset = png_get_y_offset_microns(png_ptr, info_ptr);
+ x_offset = png_get_x_offset_inches(png_ptr, info_ptr);
+ y_offset = png_get_y_offset_inches(png_ptr, info_ptr);
+
+ (Each of these returns 0 [signifying "unknown" if both
+ x and y are 0] if the data is not present or if the
+ chunk is present but the unit is the pixel)
+
+For more information, see the png_info definition in png.h and the
+PNG specification for chunk contents. Be careful with trusting
+rowbytes, as some of the transformations could increase the space
+needed to hold a row (expand, filler, gray_to_rgb, etc.).
+See png_read_update_info(), below.
+
+A quick word about text_ptr and num_text. PNG stores comments in
+keyword/text pairs, one pair per chunk, with no limit on the number
+of text chunks, and a 2^31 byte limit on their size. While there are
+suggested keywords, there is no requirement to restrict the use to these
+strings. It is strongly suggested that keywords and text be sensible
+to humans (that's the point), so don't use abbreviations. Non-printing
+symbols are not allowed. See the PNG specification for more details.
+There is also no requirement to have text after the keyword.
+
+Keywords should be limited to 79 Latin-1 characters without leading or
+trailing spaces, but non-consecutive spaces are allowed within the
+keyword. It is possible to have the same keyword any number of times.
+The text_ptr is an array of png_text structures, each holding a
+pointer to a language string, a pointer to a keyword and a pointer to
+a text string. The text string, language code, and translated
+keyword may be empty or NULL pointers. The keyword/text
+pairs are put into the array in the order that they are received.
+However, some or all of the text chunks may be after the image, so, to
+make sure you have read all the text chunks, don't mess with these
+until after you read the stuff after the image. This will be
+mentioned again below in the discussion that goes with png_read_end().
+
+Input transformations
+
+After you've read the header information, you can set up the library
+to handle any special transformations of the image data. The various
+ways to transform the data will be described in the order that they
+should occur. This is important, as some of these change the color
+type and/or bit depth of the data, and some others only work on
+certain color types and bit depths. Even though each transformation
+checks to see if it has data that it can do something with, you should
+make sure to only enable a transformation if it will be valid for the
+data. For example, don't swap red and blue on grayscale data.
+
+The colors used for the background and transparency values should be
+supplied in the same format/depth as the current image data. They
+are stored in the same format/depth as the image data in a bKGD or tRNS
+chunk, so this is what libpng expects for this data. The colors are
+transformed to keep in sync with the image data when an application
+calls the png_read_update_info() routine (see below).
+
+Data will be decoded into the supplied row buffers packed into bytes
+unless the library has been told to transform it into another format.
+For example, 4 bit/pixel paletted or grayscale data will be returned
+2 pixels/byte with the leftmost pixel in the high-order bits of the
+byte, unless png_set_packing() is called. 8-bit RGB data will be stored
+in RGB RGB RGB format unless png_set_filler() or png_set_add_alpha()
+is called to insert filler bytes, either before or after each RGB triplet.
+16-bit RGB data will be returned RRGGBB RRGGBB, with the most significant
+byte of the color value first, unless png_set_strip_16() is called to
+transform it to regular RGB RGB triplets, or png_set_filler() or
+png_set_add alpha() is called to insert filler bytes, either before or
+after each RRGGBB triplet. Similarly, 8-bit or 16-bit grayscale data can
+be modified with
+png_set_filler(), png_set_add_alpha(), or png_set_strip_16().
+
+The following code transforms grayscale images of less than 8 to 8 bits,
+changes paletted images to RGB, and adds a full alpha channel if there is
+transparency information in a tRNS chunk. This is most useful on
+grayscale images with bit depths of 2 or 4 or if there is a multiple-image
+viewing application that wishes to treat all images in the same way.
+
+ if (color_type == PNG_COLOR_TYPE_PALETTE)
+ png_set_palette_to_rgb(png_ptr);
+
+ if (color_type == PNG_COLOR_TYPE_GRAY &&
+ bit_depth < 8) png_set_expand_gray_1_2_4_to_8(png_ptr);
+
+ if (png_get_valid(png_ptr, info_ptr,
+ PNG_INFO_tRNS)) png_set_tRNS_to_alpha(png_ptr);
+
+These three functions are actually aliases for png_set_expand(), added
+in libpng version 1.0.4, with the function names expanded to improve code
+readability. In some future version they may actually do different
+things.
+
+As of libpng version 1.2.9, png_set_expand_gray_1_2_4_to_8() was
+added. It expands the sample depth without changing tRNS to alpha.
+At the same time, png_set_gray_1_2_4_to_8() was deprecated, and it
+will be removed from a future version.
+
+PNG can have files with 16 bits per channel. If you only can handle
+8 bits per channel, this will strip the pixels down to 8 bit.
+
+ if (bit_depth == 16)
+ png_set_strip_16(png_ptr);
+
+If, for some reason, you don't need the alpha channel on an image,
+and you want to remove it rather than combining it with the background
+(but the image author certainly had in mind that you *would* combine
+it with the background, so that's what you should probably do):
+
+ if (color_type & PNG_COLOR_MASK_ALPHA)
+ png_set_strip_alpha(png_ptr);
+
+In PNG files, the alpha channel in an image
+is the level of opacity. If you need the alpha channel in an image to
+be the level of transparency instead of opacity, you can invert the
+alpha channel (or the tRNS chunk data) after it's read, so that 0 is
+fully opaque and 255 (in 8-bit or paletted images) or 65535 (in 16-bit
+images) is fully transparent, with
+
+ png_set_invert_alpha(png_ptr);
+
+PNG files pack pixels of bit depths 1, 2, and 4 into bytes as small as
+they can, resulting in, for example, 8 pixels per byte for 1 bit
+files. This code expands to 1 pixel per byte without changing the
+values of the pixels:
+
+ if (bit_depth < 8)
+ png_set_packing(png_ptr);
+
+PNG files have possible bit depths of 1, 2, 4, 8, and 16. All pixels
+stored in a PNG image have been "scaled" or "shifted" up to the next
+higher possible bit depth (e.g. from 5 bits/sample in the range [0,31] to
+8 bits/sample in the range [0, 255]). However, it is also possible to
+convert the PNG pixel data back to the original bit depth of the image.
+This call reduces the pixels back down to the original bit depth:
+
+ png_color_8p sig_bit;
+
+ if (png_get_sBIT(png_ptr, info_ptr, &sig_bit))
+ png_set_shift(png_ptr, sig_bit);
+
+PNG files store 3-color pixels in red, green, blue order. This code
+changes the storage of the pixels to blue, green, red:
+
+ if (color_type == PNG_COLOR_TYPE_RGB ||
+ color_type == PNG_COLOR_TYPE_RGB_ALPHA)
+ png_set_bgr(png_ptr);
+
+PNG files store RGB pixels packed into 3 or 6 bytes. This code expands them
+into 4 or 8 bytes for windowing systems that need them in this format:
+
+ if (color_type == PNG_COLOR_TYPE_RGB)
+ png_set_filler(png_ptr, filler, PNG_FILLER_BEFORE);
+
+where "filler" is the 8 or 16-bit number to fill with, and the location is
+either PNG_FILLER_BEFORE or PNG_FILLER_AFTER, depending upon whether
+you want the filler before the RGB or after. This transformation
+does not affect images that already have full alpha channels. To add an
+opaque alpha channel, use filler=0xff or 0xffff and PNG_FILLER_AFTER which
+will generate RGBA pixels.
+
+Note that png_set_filler() does not change the color type. If you want
+to do that, you can add a true alpha channel with
+
+ if (color_type == PNG_COLOR_TYPE_RGB ||
+ color_type == PNG_COLOR_TYPE_GRAY)
+ png_set_add_alpha(png_ptr, filler, PNG_FILLER_AFTER);
+
+where "filler" contains the alpha value to assign to each pixel.
+This function was added in libpng-1.2.7.
+
+If you are reading an image with an alpha channel, and you need the
+data as ARGB instead of the normal PNG format RGBA:
+
+ if (color_type == PNG_COLOR_TYPE_RGB_ALPHA)
+ png_set_swap_alpha(png_ptr);
+
+For some uses, you may want a grayscale image to be represented as
+RGB. This code will do that conversion:
+
+ if (color_type == PNG_COLOR_TYPE_GRAY ||
+ color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
+ png_set_gray_to_rgb(png_ptr);
+
+Conversely, you can convert an RGB or RGBA image to grayscale or grayscale
+with alpha.
+
+ if (color_type == PNG_COLOR_TYPE_RGB ||
+ color_type == PNG_COLOR_TYPE_RGB_ALPHA)
+ png_set_rgb_to_gray_fixed(png_ptr, error_action,
+ int red_weight, int green_weight);
+
+ error_action = 1: silently do the conversion
+ error_action = 2: issue a warning if the original
+ image has any pixel where
+ red != green or red != blue
+ error_action = 3: issue an error and abort the
+ conversion if the original
+ image has any pixel where
+ red != green or red != blue
+
+ red_weight: weight of red component times 100000
+ green_weight: weight of green component times 100000
+ If either weight is negative, default
+ weights (21268, 71514) are used.
+
+If you have set error_action = 1 or 2, you can
+later check whether the image really was gray, after processing
+the image rows, with the png_get_rgb_to_gray_status(png_ptr) function.
+It will return a png_byte that is zero if the image was gray or
+1 if there were any non-gray pixels. bKGD and sBIT data
+will be silently converted to grayscale, using the green channel
+data, regardless of the error_action setting.
+
+With red_weight+green_weight<=100000,
+the normalized graylevel is computed:
+
+ int rw = red_weight * 65536;
+ int gw = green_weight * 65536;
+ int bw = 65536 - (rw + gw);
+ gray = (rw*red + gw*green + bw*blue)/65536;
+
+The default values approximate those recommended in the Charles
+Poynton's Color FAQ, <http://www.inforamp.net/~poynton/>
+Copyright (c) 1998-01-04 Charles Poynton <poynton at inforamp.net>
+
+ Y = 0.212671 * R + 0.715160 * G + 0.072169 * B
+
+Libpng approximates this with
+
+ Y = 0.21268 * R + 0.7151 * G + 0.07217 * B
+
+which can be expressed with integers as
+
+ Y = (6969 * R + 23434 * G + 2365 * B)/32768
+
+The calculation is done in a linear colorspace, if the image gamma
+is known.
+
+If you have a grayscale and you are using png_set_expand_depth(),
+png_set_expand(), or png_set_gray_to_rgb to change to truecolor or to
+a higher bit-depth, you must either supply the background color as a gray
+value at the original file bit-depth (need_expand = 1) or else supply the
+background color as an RGB triplet at the final, expanded bit depth
+(need_expand = 0). Similarly, if you are reading a paletted image, you
+must either supply the background color as a palette index (need_expand = 1)
+or as an RGB triplet that may or may not be in the palette (need_expand = 0).
+
+ png_color_16 my_background;
+ png_color_16p image_background;
+
+ if (png_get_bKGD(png_ptr, info_ptr, &image_background))
+ png_set_background(png_ptr, image_background,
+ PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);
+ else
+ png_set_background(png_ptr, &my_background,
+ PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0);
+
+The png_set_background() function tells libpng to composite images
+with alpha or simple transparency against the supplied background
+color. If the PNG file contains a bKGD chunk (PNG_INFO_bKGD valid),
+you may use this color, or supply another color more suitable for
+the current display (e.g., the background color from a web page). You
+need to tell libpng whether the color is in the gamma space of the
+display (PNG_BACKGROUND_GAMMA_SCREEN for colors you supply), the file
+(PNG_BACKGROUND_GAMMA_FILE for colors from the bKGD chunk), or one
+that is neither of these gammas (PNG_BACKGROUND_GAMMA_UNIQUE - I don't
+know why anyone would use this, but it's here).
+
+To properly display PNG images on any kind of system, the application needs
+to know what the display gamma is. Ideally, the user will know this, and
+the application will allow them to set it. One method of allowing the user
+to set the display gamma separately for each system is to check for a
+SCREEN_GAMMA or DISPLAY_GAMMA environment variable, which will hopefully be
+correctly set.
+
+Note that display_gamma is the overall gamma correction required to produce
+pleasing results, which depends on the lighting conditions in the surrounding
+environment. In a dim or brightly lit room, no compensation other than
+the physical gamma exponent of the monitor is needed, while in a dark room
+a slightly smaller exponent is better.
+
+ double gamma, screen_gamma;
+
+ if (/* We have a user-defined screen
+ gamma value */)
+ {
+ screen_gamma = user_defined_screen_gamma;
+ }
+ /* One way that applications can share the same
+ screen gamma value */
+ else if ((gamma_str = getenv("SCREEN_GAMMA"))
+ != NULL)
+ {
+ screen_gamma = (double)atof(gamma_str);
+ }
+ /* If we don't have another value */
+ else
+ {
+ screen_gamma = 2.2; /* A good guess for a
+ PC monitor in a bright office or a dim room */
+ screen_gamma = 2.0; /* A good guess for a
+ PC monitor in a dark room */
+ screen_gamma = 1.7 or 1.0; /* A good
+ guess for Mac systems */
+ }
+
+The png_set_gamma() function handles gamma transformations of the data.
+Pass both the file gamma and the current screen_gamma. If the file does
+not have a gamma value, you can pass one anyway if you have an idea what
+it is (usually 0.45455 is a good guess for GIF images on PCs). Note
+that file gammas are inverted from screen gammas. See the discussions
+on gamma in the PNG specification for an excellent description of what
+gamma is, and why all applications should support it. It is strongly
+recommended that PNG viewers support gamma correction.
+
+ if (png_get_gAMA(png_ptr, info_ptr, &gamma))
+ png_set_gamma(png_ptr, screen_gamma, gamma);
+ else
+ png_set_gamma(png_ptr, screen_gamma, 0.45455);
+
+If you need to reduce an RGB file to a paletted file, or if a paletted
+file has more entries then will fit on your screen, png_set_dither()
+will do that. Note that this is a simple match dither that merely
+finds the closest color available. This should work fairly well with
+optimized palettes, and fairly badly with linear color cubes. If you
+pass a palette that is larger then maximum_colors, the file will
+reduce the number of colors in the palette so it will fit into
+maximum_colors. If there is a histogram, it will use it to make
+more intelligent choices when reducing the palette. If there is no
+histogram, it may not do as good a job.
+
+ if (color_type & PNG_COLOR_MASK_COLOR)
+ {
+ if (png_get_valid(png_ptr, info_ptr,
+ PNG_INFO_PLTE))
+ {
+ png_uint_16p histogram = NULL;
+
+ png_get_hIST(png_ptr, info_ptr,
+ &histogram);
+ png_set_dither(png_ptr, palette, num_palette,
+ max_screen_colors, histogram, 1);
+ }
+ else
+ {
+ png_color std_color_cube[MAX_SCREEN_COLORS] =
+ { ... colors ... };
+
+ png_set_dither(png_ptr, std_color_cube,
+ MAX_SCREEN_COLORS, MAX_SCREEN_COLORS,
+ NULL,0);
+ }
+ }
+
+PNG files describe monochrome as black being zero and white being one.
+The following code will reverse this (make black be one and white be
+zero):
+
+ if (bit_depth == 1 && color_type == PNG_COLOR_TYPE_GRAY)
+ png_set_invert_mono(png_ptr);
+
+This function can also be used to invert grayscale and gray-alpha images:
+
+ if (color_type == PNG_COLOR_TYPE_GRAY ||
+ color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
+ png_set_invert_mono(png_ptr);
+
+PNG files store 16 bit pixels in network byte order (big-endian,
+ie. most significant bits first). This code changes the storage to the
+other way (little-endian, i.e. least significant bits first, the
+way PCs store them):
+
+ if (bit_depth == 16)
+ png_set_swap(png_ptr);
+
+If you are using packed-pixel images (1, 2, or 4 bits/pixel), and you
+need to change the order the pixels are packed into bytes, you can use:
+
+ if (bit_depth < 8)
+ png_set_packswap(png_ptr);
+
+Finally, you can write your own transformation function if none of
+the existing ones meets your needs. This is done by setting a callback
+with
+
+ png_set_read_user_transform_fn(png_ptr,
+ read_transform_fn);
+
+You must supply the function
+
+ void read_transform_fn(png_ptr ptr, row_info_ptr
+ row_info, png_bytep data)
+
+See pngtest.c for a working example. Your function will be called
+after all of the other transformations have been processed.
+
+You can also set up a pointer to a user structure for use by your
+callback function, and you can inform libpng that your transform
+function will change the number of channels or bit depth with the
+function
+
+ png_set_user_transform_info(png_ptr, user_ptr,
+ user_depth, user_channels);
+
+The user's application, not libpng, is responsible for allocating and
+freeing any memory required for the user structure.
+
+You can retrieve the pointer via the function
+png_get_user_transform_ptr(). For example:
+
+ voidp read_user_transform_ptr =
+ png_get_user_transform_ptr(png_ptr);
+
+The last thing to handle is interlacing; this is covered in detail below,
+but you must call the function here if you want libpng to handle expansion
+of the interlaced image.
+
+ number_of_passes = png_set_interlace_handling(png_ptr);
+
+After setting the transformations, libpng can update your png_info
+structure to reflect any transformations you've requested with this
+call. This is most useful to update the info structure's rowbytes
+field so you can use it to allocate your image memory. This function
+will also update your palette with the correct screen_gamma and
+background if these have been given with the calls above.
+
+ png_read_update_info(png_ptr, info_ptr);
+
+After you call png_read_update_info(), you can allocate any
+memory you need to hold the image. The row data is simply
+raw byte data for all forms of images. As the actual allocation
+varies among applications, no example will be given. If you
+are allocating one large chunk, you will need to build an
+array of pointers to each row, as it will be needed for some
+of the functions below.
+
+Reading image data
+
+After you've allocated memory, you can read the image data.
+The simplest way to do this is in one function call. If you are
+allocating enough memory to hold the whole image, you can just
+call png_read_image() and libpng will read in all the image data
+and put it in the memory area supplied. You will need to pass in
+an array of pointers to each row.
+
+This function automatically handles interlacing, so you don't need
+to call png_set_interlace_handling() or call this function multiple
+times, or any of that other stuff necessary with png_read_rows().
+
+ png_read_image(png_ptr, row_pointers);
+
+where row_pointers is:
+
+ png_bytep row_pointers[height];
+
+You can point to void or char or whatever you use for pixels.
+
+If you don't want to read in the whole image at once, you can
+use png_read_rows() instead. If there is no interlacing (check
+interlace_type == PNG_INTERLACE_NONE), this is simple:
+
+ png_read_rows(png_ptr, row_pointers, NULL,
+ number_of_rows);
+
+where row_pointers is the same as in the png_read_image() call.
+
+If you are doing this just one row at a time, you can do this with
+a single row_pointer instead of an array of row_pointers:
+
+ png_bytep row_pointer = row;
+ png_read_row(png_ptr, row_pointer, NULL);
+
+If the file is interlaced (interlace_type != 0 in the IHDR chunk), things
+get somewhat harder. The only current (PNG Specification version 1.2)
+interlacing type for PNG is (interlace_type == PNG_INTERLACE_ADAM7)
+is a somewhat complicated 2D interlace scheme, known as Adam7, that
+breaks down an image into seven smaller images of varying size, based
+on an 8x8 grid.
+
+libpng can fill out those images or it can give them to you "as is".
+If you want them filled out, there are two ways to do that. The one
+mentioned in the PNG specification is to expand each pixel to cover
+those pixels that have not been read yet (the "rectangle" method).
+This results in a blocky image for the first pass, which gradually
+smooths out as more pixels are read. The other method is the "sparkle"
+method, where pixels are drawn only in their final locations, with the
+rest of the image remaining whatever colors they were initialized to
+before the start of the read. The first method usually looks better,
+but tends to be slower, as there are more pixels to put in the rows.
+
+If you don't want libpng to handle the interlacing details, just call
+png_read_rows() seven times to read in all seven images. Each of the
+images is a valid image by itself, or they can all be combined on an
+8x8 grid to form a single image (although if you intend to combine them
+you would be far better off using the libpng interlace handling).
+
+The first pass will return an image 1/8 as wide as the entire image
+(every 8th column starting in column 0) and 1/8 as high as the original
+(every 8th row starting in row 0), the second will be 1/8 as wide
+(starting in column 4) and 1/8 as high (also starting in row 0). The
+third pass will be 1/4 as wide (every 4th pixel starting in column 0) and
+1/8 as high (every 8th row starting in row 4), and the fourth pass will
+be 1/4 as wide and 1/4 as high (every 4th column starting in column 2,
+and every 4th row starting in row 0). The fifth pass will return an
+image 1/2 as wide, and 1/4 as high (starting at column 0 and row 2),
+while the sixth pass will be 1/2 as wide and 1/2 as high as the original
+(starting in column 1 and row 0). The seventh and final pass will be as
+wide as the original, and 1/2 as high, containing all of the odd
+numbered scanlines. Phew!
+
+If you want libpng to expand the images, call this before calling
+png_start_read_image() or png_read_update_info():
+
+ if (interlace_type == PNG_INTERLACE_ADAM7)
+ number_of_passes
+ = png_set_interlace_handling(png_ptr);
+
+This will return the number of passes needed. Currently, this
+is seven, but may change if another interlace type is added.
+This function can be called even if the file is not interlaced,
+where it will return one pass.
+
+If you are not going to display the image after each pass, but are
+going to wait until the entire image is read in, use the sparkle
+effect. This effect is faster and the end result of either method
+is exactly the same. If you are planning on displaying the image
+after each pass, the "rectangle" effect is generally considered the
+better looking one.
+
+If you only want the "sparkle" effect, just call png_read_rows() as
+normal, with the third parameter NULL. Make sure you make pass over
+the image number_of_passes times, and you don't change the data in the
+rows between calls. You can change the locations of the data, just
+not the data. Each pass only writes the pixels appropriate for that
+pass, and assumes the data from previous passes is still valid.
+
+ png_read_rows(png_ptr, row_pointers, NULL,
+ number_of_rows);
+
+If you only want the first effect (the rectangles), do the same as
+before except pass the row buffer in the third parameter, and leave
+the second parameter NULL.
+
+ png_read_rows(png_ptr, NULL, row_pointers,
+ number_of_rows);
+
+Finishing a sequential read
+
+After you are finished reading the image through the
+low-level interface, you can finish reading the file. If you are
+interested in comments or time, which may be stored either before or
+after the image data, you should pass the separate png_info struct if
+you want to keep the comments from before and after the image
+separate. If you are not interested, you can pass NULL.
+
+ png_read_end(png_ptr, end_info);
+
+When you are done, you can free all memory allocated by libpng like this:
+
+ png_destroy_read_struct(&png_ptr, &info_ptr,
+ &end_info);
+
+It is also possible to individually free the info_ptr members that
+point to libpng-allocated storage with the following function:
+
+ png_free_data(png_ptr, info_ptr, mask, seq)
+ mask - identifies data to be freed, a mask
+ containing the bitwise OR of one or
+ more of
+ PNG_FREE_PLTE, PNG_FREE_TRNS,
+ PNG_FREE_HIST, PNG_FREE_ICCP,
+ PNG_FREE_PCAL, PNG_FREE_ROWS,
+ PNG_FREE_SCAL, PNG_FREE_SPLT,
+ PNG_FREE_TEXT, PNG_FREE_UNKN,
+ or simply PNG_FREE_ALL
+ seq - sequence number of item to be freed
+ (-1 for all items)
+
+This function may be safely called when the relevant storage has
+already been freed, or has not yet been allocated, or was allocated
+by the user and not by libpng, and will in those
+cases do nothing. The "seq" parameter is ignored if only one item
+of the selected data type, such as PLTE, is allowed. If "seq" is not
+-1, and multiple items are allowed for the data type identified in
+the mask, such as text or sPLT, only the n'th item in the structure
+is freed, where n is "seq".
+
+The default behavior is only to free data that was allocated internally
+by libpng. This can be changed, so that libpng will not free the data,
+or so that it will free data that was allocated by the user with png_malloc()
+or png_zalloc() and passed in via a png_set_*() function, with
+
+ png_data_freer(png_ptr, info_ptr, freer, mask)
+ mask - which data elements are affected
+ same choices as in png_free_data()
+ freer - one of
+ PNG_DESTROY_WILL_FREE_DATA
+ PNG_SET_WILL_FREE_DATA
+ PNG_USER_WILL_FREE_DATA
+
+This function only affects data that has already been allocated.
+You can call this function after reading the PNG data but before calling
+any png_set_*() functions, to control whether the user or the png_set_*()
+function is responsible for freeing any existing data that might be present,
+and again after the png_set_*() functions to control whether the user
+or png_destroy_*() is supposed to free the data. When the user assumes
+responsibility for libpng-allocated data, the application must use
+png_free() to free it, and when the user transfers responsibility to libpng
+for data that the user has allocated, the user must have used png_malloc()
+or png_zalloc() to allocate it.
+
+If you allocated your row_pointers in a single block, as suggested above in
+the description of the high level read interface, you must not transfer
+responsibility for freeing it to the png_set_rows or png_read_destroy function,
+because they would also try to free the individual row_pointers[i].
+
+If you allocated text_ptr.text, text_ptr.lang, and text_ptr.translated_keyword
+separately, do not transfer responsibility for freeing text_ptr to libpng,
+because when libpng fills a png_text structure it combines these members with
+the key member, and png_free_data() will free only text_ptr.key. Similarly,
+if you transfer responsibility for free'ing text_ptr from libpng to your
+application, your application must not separately free those members.
+
+The png_free_data() function will turn off the "valid" flag for anything
+it frees. If you need to turn the flag off for a chunk that was freed by your
+application instead of by libpng, you can use
+
+ png_set_invalid(png_ptr, info_ptr, mask);
+ mask - identifies the chunks to be made invalid,
+ containing the bitwise OR of one or
+ more of
+ PNG_INFO_gAMA, PNG_INFO_sBIT,
+ PNG_INFO_cHRM, PNG_INFO_PLTE,
+ PNG_INFO_tRNS, PNG_INFO_bKGD,
+ PNG_INFO_hIST, PNG_INFO_pHYs,
+ PNG_INFO_oFFs, PNG_INFO_tIME,
+ PNG_INFO_pCAL, PNG_INFO_sRGB,
+ PNG_INFO_iCCP, PNG_INFO_sPLT,
+ PNG_INFO_sCAL, PNG_INFO_IDAT
+
+For a more compact example of reading a PNG image, see the file example.c.
+
+Reading PNG files progressively
+
+The progressive reader is slightly different then the non-progressive
+reader. Instead of calling png_read_info(), png_read_rows(), and
+png_read_end(), you make one call to png_process_data(), which calls
+callbacks when it has the info, a row, or the end of the image. You
+set up these callbacks with png_set_progressive_read_fn(). You don't
+have to worry about the input/output functions of libpng, as you are
+giving the library the data directly in png_process_data(). I will
+assume that you have read the section on reading PNG files above,
+so I will only highlight the differences (although I will show
+all of the code).
+
+png_structp png_ptr;
+png_infop info_ptr;
+
+ /* An example code fragment of how you would
+ initialize the progressive reader in your
+ application. */
+ int
+ initialize_png_reader()
+ {
+ png_ptr = png_create_read_struct
+ (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
+ user_error_fn, user_warning_fn);
+ if (!png_ptr)
+ return (ERROR);
+ info_ptr = png_create_info_struct(png_ptr);
+ if (!info_ptr)
+ {
+ png_destroy_read_struct(&png_ptr, (png_infopp)NULL,
+ (png_infopp)NULL);
+ return (ERROR);
+ }
+
+ if (setjmp(png_jmpbuf(png_ptr)))
+ {
+ png_destroy_read_struct(&png_ptr, &info_ptr,
+ (png_infopp)NULL);
+ return (ERROR);
+ }
+
+ /* This one's new. You can provide functions
+ to be called when the header info is valid,
+ when each row is completed, and when the image
+ is finished. If you aren't using all functions,
+ you can specify NULL parameters. Even when all
+ three functions are NULL, you need to call
+ png_set_progressive_read_fn(). You can use
+ any struct as the user_ptr (cast to a void pointer
+ for the function call), and retrieve the pointer
+ from inside the callbacks using the function
+
+ png_get_progressive_ptr(png_ptr);
+
+ which will return a void pointer, which you have
+ to cast appropriately.
+ */
+ png_set_progressive_read_fn(png_ptr, (void *)user_ptr,
+ info_callback, row_callback, end_callback);
+
+ return 0;
+ }
+
+ /* A code fragment that you call as you receive blocks
+ of data */
+ int
+ process_data(png_bytep buffer, png_uint_32 length)
+ {
+ if (setjmp(png_jmpbuf(png_ptr)))
+ {
+ png_destroy_read_struct(&png_ptr, &info_ptr,
+ (png_infopp)NULL);
+ return (ERROR);
+ }
+
+ /* This one's new also. Simply give it a chunk
+ of data from the file stream (in order, of
+ course). On machines with segmented memory
+ models machines, don't give it any more than
+ 64K. The library seems to run fine with sizes
+ of 4K. Although you can give it much less if
+ necessary (I assume you can give it chunks of
+ 1 byte, I haven't tried less then 256 bytes
+ yet). When this function returns, you may
+ want to display any rows that were generated
+ in the row callback if you don't already do
+ so there.
+ */
+ png_process_data(png_ptr, info_ptr, buffer, length);
+ return 0;
+ }
+
+ /* This function is called (as set by
+ png_set_progressive_read_fn() above) when enough data
+ has been supplied so all of the header has been
+ read.
+ */
+ void
+ info_callback(png_structp png_ptr, png_infop info)
+ {
+ /* Do any setup here, including setting any of
+ the transformations mentioned in the Reading
+ PNG files section. For now, you _must_ call
+ either png_start_read_image() or
+ png_read_update_info() after all the
+ transformations are set (even if you don't set
+ any). You may start getting rows before
+ png_process_data() returns, so this is your
+ last chance to prepare for that.
+ */
+ }
+
+ /* This function is called when each row of image
+ data is complete */
+ void
+ row_callback(png_structp png_ptr, png_bytep new_row,
+ png_uint_32 row_num, int pass)
+ {
+ /* If the image is interlaced, and you turned
+ on the interlace handler, this function will
+ be called for every row in every pass. Some
+ of these rows will not be changed from the
+ previous pass. When the row is not changed,
+ the new_row variable will be NULL. The rows
+ and passes are called in order, so you don't
+ really need the row_num and pass, but I'm
+ supplying them because it may make your life
+ easier.
+
+ For the non-NULL rows of interlaced images,
+ you must call png_progressive_combine_row()
+ passing in the row and the old row. You can
+ call this function for NULL rows (it will just
+ return) and for non-interlaced images (it just
+ does the memcpy for you) if it will make the
+ code easier. Thus, you can just do this for
+ all cases:
+ */
+
+ png_progressive_combine_row(png_ptr, old_row,
+ new_row);
+
+ /* where old_row is what was displayed for
+ previously for the row. Note that the first
+ pass (pass == 0, really) will completely cover
+ the old row, so the rows do not have to be
+ initialized. After the first pass (and only
+ for interlaced images), you will have to pass
+ the current row, and the function will combine
+ the old row and the new row.
+ */
+ }
+
+ void
+ end_callback(png_structp png_ptr, png_infop info)
+ {
+ /* This function is called after the whole image
+ has been read, including any chunks after the
+ image (up to and including the IEND). You
+ will usually have the same info chunk as you
+ had in the header, although some data may have
+ been added to the comments and time fields.
+
+ Most people won't do much here, perhaps setting
+ a flag that marks the image as finished.
+ */
+ }
+
+
+
+IV. Writing
+
+Much of this is very similar to reading. However, everything of
+importance is repeated here, so you won't have to constantly look
+back up in the reading section to understand writing.
+
+Setup
+
+You will want to do the I/O initialization before you get into libpng,
+so if it doesn't work, you don't have anything to undo. If you are not
+using the standard I/O functions, you will need to replace them with
+custom writing functions. See the discussion under Customizing libpng.
+
+ FILE *fp = fopen(file_name, "wb");
+ if (!fp)
+ {
+ return (ERROR);
+ }
+
+Next, png_struct and png_info need to be allocated and initialized.
+As these can be both relatively large, you may not want to store these
+on the stack, unless you have stack space to spare. Of course, you
+will want to check if they return NULL. If you are also reading,
+you won't want to name your read structure and your write structure
+both "png_ptr"; you can call them anything you like, such as
+"read_ptr" and "write_ptr". Look at pngtest.c, for example.
+
+ png_structp png_ptr = png_create_write_struct
+ (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
+ user_error_fn, user_warning_fn);
+ if (!png_ptr)
+ return (ERROR);
+
+ png_infop info_ptr = png_create_info_struct(png_ptr);
+ if (!info_ptr)
+ {
+ png_destroy_write_struct(&png_ptr,
+ (png_infopp)NULL);
+ return (ERROR);
+ }
+
+If you want to use your own memory allocation routines,
+define PNG_USER_MEM_SUPPORTED and use
+png_create_write_struct_2() instead of png_create_write_struct():
+
+ png_structp png_ptr = png_create_write_struct_2
+ (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
+ user_error_fn, user_warning_fn, (png_voidp)
+ user_mem_ptr, user_malloc_fn, user_free_fn);
+
+After you have these structures, you will need to set up the
+error handling. When libpng encounters an error, it expects to
+longjmp() back to your routine. Therefore, you will need to call
+setjmp() and pass the png_jmpbuf(png_ptr). If you
+write the file from different routines, you will need to update
+the png_jmpbuf(png_ptr) every time you enter a new routine that will
+call a png_*() function. See your documentation of setjmp/longjmp
+for your compiler for more information on setjmp/longjmp. See
+the discussion on libpng error handling in the Customizing Libpng
+section below for more information on the libpng error handling.
+
+ if (setjmp(png_jmpbuf(png_ptr)))
+ {
+ png_destroy_write_struct(&png_ptr, &info_ptr);
+ fclose(fp);
+ return (ERROR);
+ }
+ ...
+ return;
+
+If you would rather avoid the complexity of setjmp/longjmp issues,
+you can compile libpng with PNG_SETJMP_NOT_SUPPORTED, in which case
+errors will result in a call to PNG_ABORT() which defaults to abort().
+
+Now you need to set up the output code. The default for libpng is to
+use the C function fwrite(). If you use this, you will need to pass a
+valid FILE * in the function png_init_io(). Be sure that the file is
+opened in binary mode. Again, if you wish to handle writing data in
+another way, see the discussion on libpng I/O handling in the Customizing
+Libpng section below.
+
+ png_init_io(png_ptr, fp);
+
+If you are embedding your PNG into a datastream such as MNG, and don't
+want libpng to write the 8-byte signature, or if you have already
+written the signature in your application, use
+
+ png_set_sig_bytes(png_ptr, 8);
+
+to inform libpng that it should not write a signature.
+
+Write callbacks
+
+At this point, you can set up a callback function that will be
+called after each row has been written, which you can use to control
+a progress meter or the like. It's demonstrated in pngtest.c.
+You must supply a function
+
+ void write_row_callback(png_ptr, png_uint_32 row,
+ int pass);
+ {
+ /* put your code here */
+ }
+
+(You can give it another name that you like instead of "write_row_callback")
+
+To inform libpng about your function, use
+
+ png_set_write_status_fn(png_ptr, write_row_callback);
+
+You now have the option of modifying how the compression library will
+run. The following functions are mainly for testing, but may be useful
+in some cases, like if you need to write PNG files extremely fast and
+are willing to give up some compression, or if you want to get the
+maximum possible compression at the expense of slower writing. If you
+have no special needs in this area, let the library do what it wants by
+not calling this function at all, as it has been tuned to deliver a good
+speed/compression ratio. The second parameter to png_set_filter() is
+the filter method, for which the only valid values are 0 (as of the
+July 1999 PNG specification, version 1.2) or 64 (if you are writing
+a PNG datastream that is to be embedded in a MNG datastream). The third
+parameter is a flag that indicates which filter type(s) are to be tested
+for each scanline. See the PNG specification for details on the specific filter
+types.
+
+
+ /* turn on or off filtering, and/or choose
+ specific filters. You can use either a single
+ PNG_FILTER_VALUE_NAME or the bitwise OR of one
+ or more PNG_FILTER_NAME masks. */
+ png_set_filter(png_ptr, 0,
+ PNG_FILTER_NONE | PNG_FILTER_VALUE_NONE |
+ PNG_FILTER_SUB | PNG_FILTER_VALUE_SUB |
+ PNG_FILTER_UP | PNG_FILTER_VALUE_UP |
+ PNG_FILTER_AVE | PNG_FILTER_VALUE_AVE |
+ PNG_FILTER_PAETH | PNG_FILTER_VALUE_PAETH|
+ PNG_ALL_FILTERS);
+
+If an application
+wants to start and stop using particular filters during compression,
+it should start out with all of the filters (to ensure that the previous
+row of pixels will be stored in case it's needed later), and then add
+and remove them after the start of compression.
+
+If you are writing a PNG datastream that is to be embedded in a MNG
+datastream, the second parameter can be either 0 or 64.
+
+The png_set_compression_*() functions interface to the zlib compression
+library, and should mostly be ignored unless you really know what you are
+doing. The only generally useful call is png_set_compression_level()
+which changes how much time zlib spends on trying to compress the image
+data. See the Compression Library (zlib.h and algorithm.txt, distributed
+with zlib) for details on the compression levels.
+
+ /* set the zlib compression level */
+ png_set_compression_level(png_ptr,
+ Z_BEST_COMPRESSION);
+
+ /* set other zlib parameters */
+ png_set_compression_mem_level(png_ptr, 8);
+ png_set_compression_strategy(png_ptr,
+ Z_DEFAULT_STRATEGY);
+ png_set_compression_window_bits(png_ptr, 15);
+ png_set_compression_method(png_ptr, 8);
+ png_set_compression_buffer_size(png_ptr, 8192)
+
+extern PNG_EXPORT(void,png_set_zbuf_size)
+
+Setting the contents of info for output
+
+You now need to fill in the png_info structure with all the data you
+wish to write before the actual image. Note that the only thing you
+are allowed to write after the image is the text chunks and the time
+chunk (as of PNG Specification 1.2, anyway). See png_write_end() and
+the latest PNG specification for more information on that. If you
+wish to write them before the image, fill them in now, and flag that
+data as being valid. If you want to wait until after the data, don't
+fill them until png_write_end(). For all the fields in png_info and
+their data types, see png.h. For explanations of what the fields
+contain, see the PNG specification.
+
+Some of the more important parts of the png_info are:
+
+ png_set_IHDR(png_ptr, info_ptr, width, height,
+ bit_depth, color_type, interlace_type,
+ compression_type, filter_method)
+ width - holds the width of the image
+ in pixels (up to 2^31).
+ height - holds the height of the image
+ in pixels (up to 2^31).
+ bit_depth - holds the bit depth of one of the
+ image channels.
+ (valid values are 1, 2, 4, 8, 16
+ and depend also on the
+ color_type. See also significant
+ bits (sBIT) below).
+ color_type - describes which color/alpha
+ channels are present.
+ PNG_COLOR_TYPE_GRAY
+ (bit depths 1, 2, 4, 8, 16)
+ PNG_COLOR_TYPE_GRAY_ALPHA
+ (bit depths 8, 16)
+ PNG_COLOR_TYPE_PALETTE
+ (bit depths 1, 2, 4, 8)
+ PNG_COLOR_TYPE_RGB
+ (bit_depths 8, 16)
+ PNG_COLOR_TYPE_RGB_ALPHA
+ (bit_depths 8, 16)
+
+ PNG_COLOR_MASK_PALETTE
+ PNG_COLOR_MASK_COLOR
+ PNG_COLOR_MASK_ALPHA
+
+ interlace_type - PNG_INTERLACE_NONE or
+ PNG_INTERLACE_ADAM7
+ compression_type - (must be
+ PNG_COMPRESSION_TYPE_DEFAULT)
+ filter_method - (must be PNG_FILTER_TYPE_DEFAULT
+ or, if you are writing a PNG to
+ be embedded in a MNG datastream,
+ can also be
+ PNG_INTRAPIXEL_DIFFERENCING)
+
+ png_set_PLTE(png_ptr, info_ptr, palette,
+ num_palette);
+ palette - the palette for the file
+ (array of png_color)
+ num_palette - number of entries in the palette
+
+ png_set_gAMA(png_ptr, info_ptr, gamma);
+ gamma - the gamma the image was created
+ at (PNG_INFO_gAMA)
+
+ png_set_sRGB(png_ptr, info_ptr, srgb_intent);
+ srgb_intent - the rendering intent
+ (PNG_INFO_sRGB) The presence of
+ the sRGB chunk means that the pixel
+ data is in the sRGB color space.
+ This chunk also implies specific
+ values of gAMA and cHRM. Rendering
+ intent is the CSS-1 property that
+ has been defined by the International
+ Color Consortium
+ (http://www.color.org).
+ It can be one of
+ PNG_sRGB_INTENT_SATURATION,
+ PNG_sRGB_INTENT_PERCEPTUAL,
+ PNG_sRGB_INTENT_ABSOLUTE, or
+ PNG_sRGB_INTENT_RELATIVE.
+
+
+ png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr,
+ srgb_intent);
+ srgb_intent - the rendering intent
+ (PNG_INFO_sRGB) The presence of the
+ sRGB chunk means that the pixel
+ data is in the sRGB color space.
+ This function also causes gAMA and
+ cHRM chunks with the specific values
+ that are consistent with sRGB to be
+ written.
+
+ png_set_iCCP(png_ptr, info_ptr, name, compression_type,
+ profile, proflen);
+ name - The profile name.
+ compression - The compression type; always
+ PNG_COMPRESSION_TYPE_BASE for PNG 1.0.
+ You may give NULL to this argument to
+ ignore it.
+ profile - International Color Consortium color
+ profile data. May contain NULs.
+ proflen - length of profile data in bytes.
+
+ png_set_sBIT(png_ptr, info_ptr, sig_bit);
+ sig_bit - the number of significant bits for
+ (PNG_INFO_sBIT) each of the gray, red,
+ green, and blue channels, whichever are
+ appropriate for the given color type
+ (png_color_16)
+
+ png_set_tRNS(png_ptr, info_ptr, trans, num_trans,
+ trans_values);
+ trans - array of transparent entries for
+ palette (PNG_INFO_tRNS)
+ trans_values - graylevel or color sample values of
+ the single transparent color for
+ non-paletted images (PNG_INFO_tRNS)
+ num_trans - number of transparent entries
+ (PNG_INFO_tRNS)
+
+ png_set_hIST(png_ptr, info_ptr, hist);
+ (PNG_INFO_hIST)
+ hist - histogram of palette (array of
+ png_uint_16)
+
+ png_set_tIME(png_ptr, info_ptr, mod_time);
+ mod_time - time image was last modified
+ (PNG_VALID_tIME)
+
+ png_set_bKGD(png_ptr, info_ptr, background);
+ background - background color (PNG_VALID_bKGD)
+
+ png_set_text(png_ptr, info_ptr, text_ptr, num_text);
+ text_ptr - array of png_text holding image
+ comments
+ text_ptr[i].compression - type of compression used
+ on "text" PNG_TEXT_COMPRESSION_NONE
+ PNG_TEXT_COMPRESSION_zTXt
+ PNG_ITXT_COMPRESSION_NONE
+ PNG_ITXT_COMPRESSION_zTXt
+ text_ptr[i].key - keyword for comment. Must contain
+ 1-79 characters.
+ text_ptr[i].text - text comments for current
+ keyword. Can be NULL or empty.
+ text_ptr[i].text_length - length of text string,
+ after decompression, 0 for iTXt
+ text_ptr[i].itxt_length - length of itxt string,
+ after decompression, 0 for tEXt/zTXt
+ text_ptr[i].lang - language of comment (NULL or
+ empty for unknown).
+ text_ptr[i].translated_keyword - keyword in UTF-8 (NULL
+ or empty for unknown).
+ num_text - number of comments
+
+ png_set_sPLT(png_ptr, info_ptr, &palette_ptr,
+ num_spalettes);
+ palette_ptr - array of png_sPLT_struct structures
+ to be added to the list of palettes
+ in the info structure.
+ num_spalettes - number of palette structures to be
+ added.
+
+ png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y,
+ unit_type);
+ offset_x - positive offset from the left
+ edge of the screen
+ offset_y - positive offset from the top
+ edge of the screen
+ unit_type - PNG_OFFSET_PIXEL, PNG_OFFSET_MICROMETER
+
+ png_set_pHYs(png_ptr, info_ptr, res_x, res_y,
+ unit_type);
+ res_x - pixels/unit physical resolution
+ in x direction
+ res_y - pixels/unit physical resolution
+ in y direction
+ unit_type - PNG_RESOLUTION_UNKNOWN,
+ PNG_RESOLUTION_METER
+
+ png_set_sCAL(png_ptr, info_ptr, unit, width, height)
+ unit - physical scale units (an integer)
+ width - width of a pixel in physical scale units
+ height - height of a pixel in physical scale units
+ (width and height are doubles)
+
+ png_set_sCAL_s(png_ptr, info_ptr, unit, width, height)
+ unit - physical scale units (an integer)
+ width - width of a pixel in physical scale units
+ height - height of a pixel in physical scale units
+ (width and height are strings like "2.54")
+
+ png_set_unknown_chunks(png_ptr, info_ptr, &unknowns,
+ num_unknowns)
+ unknowns - array of png_unknown_chunk
+ structures holding unknown chunks
+ unknowns[i].name - name of unknown chunk
+ unknowns[i].data - data of unknown chunk
+ unknowns[i].size - size of unknown chunk's data
+ unknowns[i].location - position to write chunk in file
+ 0: do not write chunk
+ PNG_HAVE_IHDR: before PLTE
+ PNG_HAVE_PLTE: before IDAT
+ PNG_AFTER_IDAT: after IDAT
+
+The "location" member is set automatically according to
+what part of the output file has already been written.
+You can change its value after calling png_set_unknown_chunks()
+as demonstrated in pngtest.c. Within each of the "locations",
+the chunks are sequenced according to their position in the
+structure (that is, the value of "i", which is the order in which
+the chunk was either read from the input file or defined with
+png_set_unknown_chunks).
+
+A quick word about text and num_text. text is an array of png_text
+structures. num_text is the number of valid structures in the array.
+Each png_text structure holds a language code, a keyword, a text value,
+and a compression type.
+
+The compression types have the same valid numbers as the compression
+types of the image data. Currently, the only valid number is zero.
+However, you can store text either compressed or uncompressed, unlike
+images, which always have to be compressed. So if you don't want the
+text compressed, set the compression type to PNG_TEXT_COMPRESSION_NONE.
+Because tEXt and zTXt chunks don't have a language field, if you
+specify PNG_TEXT_COMPRESSION_NONE or PNG_TEXT_COMPRESSION_zTXt
+any language code or translated keyword will not be written out.
+
+Until text gets around 1000 bytes, it is not worth compressing it.
+After the text has been written out to the file, the compression type
+is set to PNG_TEXT_COMPRESSION_NONE_WR or PNG_TEXT_COMPRESSION_zTXt_WR,
+so that it isn't written out again at the end (in case you are calling
+png_write_end() with the same struct.
+
+The keywords that are given in the PNG Specification are:
+
+ Title Short (one line) title or
+ caption for image
+ Author Name of image's creator
+ Description Description of image (possibly long)
+ Copyright Copyright notice
+ Creation Time Time of original image creation
+ (usually RFC 1123 format, see below)
+ Software Software used to create the image
+ Disclaimer Legal disclaimer
+ Warning Warning of nature of content
+ Source Device used to create the image
+ Comment Miscellaneous comment; conversion
+ from other image format
+
+The keyword-text pairs work like this. Keywords should be short
+simple descriptions of what the comment is about. Some typical
+keywords are found in the PNG specification, as is some recommendations
+on keywords. You can repeat keywords in a file. You can even write
+some text before the image and some after. For example, you may want
+to put a description of the image before the image, but leave the
+disclaimer until after, so viewers working over modem connections
+don't have to wait for the disclaimer to go over the modem before
+they start seeing the image. Finally, keywords should be full
+words, not abbreviations. Keywords and text are in the ISO 8859-1
+(Latin-1) character set (a superset of regular ASCII) and can not
+contain NUL characters, and should not contain control or other
+unprintable characters. To make the comments widely readable, stick
+with basic ASCII, and avoid machine specific character set extensions
+like the IBM-PC character set. The keyword must be present, but
+you can leave off the text string on non-compressed pairs.
+Compressed pairs must have a text string, as only the text string
+is compressed anyway, so the compression would be meaningless.
+
+PNG supports modification time via the png_time structure. Two
+conversion routines are provided, png_convert_from_time_t() for
+time_t and png_convert_from_struct_tm() for struct tm. The
+time_t routine uses gmtime(). You don't have to use either of
+these, but if you wish to fill in the png_time structure directly,
+you should provide the time in universal time (GMT) if possible
+instead of your local time. Note that the year number is the full
+year (e.g. 1998, rather than 98 - PNG is year 2000 compliant!), and
+that months start with 1.
+
+If you want to store the time of the original image creation, you should
+use a plain tEXt chunk with the "Creation Time" keyword. This is
+necessary because the "creation time" of a PNG image is somewhat vague,
+depending on whether you mean the PNG file, the time the image was
+created in a non-PNG format, a still photo from which the image was
+scanned, or possibly the subject matter itself. In order to facilitate
+machine-readable dates, it is recommended that the "Creation Time"
+tEXt chunk use RFC 1123 format dates (e.g. "22 May 1997 18:07:10 GMT"),
+although this isn't a requirement. Unlike the tIME chunk, the
+"Creation Time" tEXt chunk is not expected to be automatically changed
+by the software. To facilitate the use of RFC 1123 dates, a function
+png_convert_to_rfc1123(png_timep) is provided to convert from PNG
+time to an RFC 1123 format string.
+
+Writing unknown chunks
+
+You can use the png_set_unknown_chunks function to queue up chunks
+for writing. You give it a chunk name, raw data, and a size; that's
+all there is to it. The chunks will be written by the next following
+png_write_info_before_PLTE, png_write_info, or png_write_end function.
+Any chunks previously read into the info structure's unknown-chunk
+list will also be written out in a sequence that satisfies the PNG
+specification's ordering rules.
+
+The high-level write interface
+
+At this point there are two ways to proceed; through the high-level
+write interface, or through a sequence of low-level write operations.
+You can use the high-level interface if your image data is present
+in the info structure. All defined output
+transformations are permitted, enabled by the following masks.
+
+ PNG_TRANSFORM_IDENTITY No transformation
+ PNG_TRANSFORM_PACKING Pack 1, 2 and 4-bit samples
+ PNG_TRANSFORM_PACKSWAP Change order of packed
+ pixels to LSB first
+ PNG_TRANSFORM_INVERT_MONO Invert monochrome images
+ PNG_TRANSFORM_SHIFT Normalize pixels to the
+ sBIT depth
+ PNG_TRANSFORM_BGR Flip RGB to BGR, RGBA
+ to BGRA
+ PNG_TRANSFORM_SWAP_ALPHA Flip RGBA to ARGB or GA
+ to AG
+ PNG_TRANSFORM_INVERT_ALPHA Change alpha from opacity
+ to transparency
+ PNG_TRANSFORM_SWAP_ENDIAN Byte-swap 16-bit samples
+ PNG_TRANSFORM_STRIP_FILLER Strip out filler bytes.
+
+If you have valid image data in the info structure (you can use
+png_set_rows() to put image data in the info structure), simply do this:
+
+ png_write_png(png_ptr, info_ptr, png_transforms, NULL)
+
+where png_transforms is an integer containing the bitwise OR of some set of
+transformation flags. This call is equivalent to png_write_info(),
+followed the set of transformations indicated by the transform mask,
+then png_write_image(), and finally png_write_end().
+
+(The final parameter of this call is not yet used. Someday it might point
+to transformation parameters required by some future output transform.)
+
+You must use png_transforms and not call any png_set_transform() functions
+when you use png_write_png().
+
+The low-level write interface
+
+If you are going the low-level route instead, you are now ready to
+write all the file information up to the actual image data. You do
+this with a call to png_write_info().
+
+ png_write_info(png_ptr, info_ptr);
+
+Note that there is one transformation you may need to do before
+png_write_info(). In PNG files, the alpha channel in an image is the
+level of opacity. If your data is supplied as a level of
+transparency, you can invert the alpha channel before you write it, so
+that 0 is fully transparent and 255 (in 8-bit or paletted images) or
+65535 (in 16-bit images) is fully opaque, with
+
+ png_set_invert_alpha(png_ptr);
+
+This must appear before png_write_info() instead of later with the
+other transformations because in the case of paletted images the tRNS
+chunk data has to be inverted before the tRNS chunk is written. If
+your image is not a paletted image, the tRNS data (which in such cases
+represents a single color to be rendered as transparent) won't need to
+be changed, and you can safely do this transformation after your
+png_write_info() call.
+
+If you need to write a private chunk that you want to appear before
+the PLTE chunk when PLTE is present, you can write the PNG info in
+two steps, and insert code to write your own chunk between them:
+
+ png_write_info_before_PLTE(png_ptr, info_ptr);
+ png_set_unknown_chunks(png_ptr, info_ptr, ...);
+ png_write_info(png_ptr, info_ptr);
+
+After you've written the file information, you can set up the library
+to handle any special transformations of the image data. The various
+ways to transform the data will be described in the order that they
+should occur. This is important, as some of these change the color
+type and/or bit depth of the data, and some others only work on
+certain color types and bit depths. Even though each transformation
+checks to see if it has data that it can do something with, you should
+make sure to only enable a transformation if it will be valid for the
+data. For example, don't swap red and blue on grayscale data.
+
+PNG files store RGB pixels packed into 3 or 6 bytes. This code tells
+the library to strip input data that has 4 or 8 bytes per pixel down
+to 3 or 6 bytes (or strip 2 or 4-byte grayscale+filler data to 1 or 2
+bytes per pixel).
+
+ png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
+
+where the 0 is unused, and the location is either PNG_FILLER_BEFORE or
+PNG_FILLER_AFTER, depending upon whether the filler byte in the pixel
+is stored XRGB or RGBX.
+
+PNG files pack pixels of bit depths 1, 2, and 4 into bytes as small as
+they can, resulting in, for example, 8 pixels per byte for 1 bit files.
+If the data is supplied at 1 pixel per byte, use this code, which will
+correctly pack the pixels into a single byte:
+
+ png_set_packing(png_ptr);
+
+PNG files reduce possible bit depths to 1, 2, 4, 8, and 16. If your
+data is of another bit depth, you can write an sBIT chunk into the
+file so that decoders can recover the original data if desired.
+
+ /* Set the true bit depth of the image data */
+ if (color_type & PNG_COLOR_MASK_COLOR)
+ {
+ sig_bit.red = true_bit_depth;
+ sig_bit.green = true_bit_depth;
+ sig_bit.blue = true_bit_depth;
+ }
+ else
+ {
+ sig_bit.gray = true_bit_depth;
+ }
+ if (color_type & PNG_COLOR_MASK_ALPHA)
+ {
+ sig_bit.alpha = true_bit_depth;
+ }
+
+ png_set_sBIT(png_ptr, info_ptr, &sig_bit);
+
+If the data is stored in the row buffer in a bit depth other than
+one supported by PNG (e.g. 3 bit data in the range 0-7 for a 4-bit PNG),
+this will scale the values to appear to be the correct bit depth as
+is required by PNG.
+
+ png_set_shift(png_ptr, &sig_bit);
+
+PNG files store 16 bit pixels in network byte order (big-endian,
+ie. most significant bits first). This code would be used if they are
+supplied the other way (little-endian, i.e. least significant bits
+first, the way PCs store them):
+
+ if (bit_depth > 8)
+ png_set_swap(png_ptr);
+
+If you are using packed-pixel images (1, 2, or 4 bits/pixel), and you
+need to change the order the pixels are packed into bytes, you can use:
+
+ if (bit_depth < 8)
+ png_set_packswap(png_ptr);
+
+PNG files store 3 color pixels in red, green, blue order. This code
+would be used if they are supplied as blue, green, red:
+
+ png_set_bgr(png_ptr);
+
+PNG files describe monochrome as black being zero and white being
+one. This code would be used if the pixels are supplied with this reversed
+(black being one and white being zero):
+
+ png_set_invert_mono(png_ptr);
+
+Finally, you can write your own transformation function if none of
+the existing ones meets your needs. This is done by setting a callback
+with
+
+ png_set_write_user_transform_fn(png_ptr,
+ write_transform_fn);
+
+You must supply the function
+
+ void write_transform_fn(png_ptr ptr, row_info_ptr
+ row_info, png_bytep data)
+
+See pngtest.c for a working example. Your function will be called
+before any of the other transformations are processed.
+
+You can also set up a pointer to a user structure for use by your
+callback function.
+
+ png_set_user_transform_info(png_ptr, user_ptr, 0, 0);
+
+The user_channels and user_depth parameters of this function are ignored
+when writing; you can set them to zero as shown.
+
+You can retrieve the pointer via the function png_get_user_transform_ptr().
+For example:
+
+ voidp write_user_transform_ptr =
+ png_get_user_transform_ptr(png_ptr);
+
+It is possible to have libpng flush any pending output, either manually,
+or automatically after a certain number of lines have been written. To
+flush the output stream a single time call:
+
+ png_write_flush(png_ptr);
+
+and to have libpng flush the output stream periodically after a certain
+number of scanlines have been written, call:
+
+ png_set_flush(png_ptr, nrows);
+
+Note that the distance between rows is from the last time png_write_flush()
+was called, or the first row of the image if it has never been called.
+So if you write 50 lines, and then png_set_flush 25, it will flush the
+output on the next scanline, and every 25 lines thereafter, unless
+png_write_flush() is called before 25 more lines have been written.
+If nrows is too small (less than about 10 lines for a 640 pixel wide
+RGB image) the image compression may decrease noticeably (although this
+may be acceptable for real-time applications). Infrequent flushing will
+only degrade the compression performance by a few percent over images
+that do not use flushing.
+
+Writing the image data
+
+That's it for the transformations. Now you can write the image data.
+The simplest way to do this is in one function call. If you have the
+whole image in memory, you can just call png_write_image() and libpng
+will write the image. You will need to pass in an array of pointers to
+each row. This function automatically handles interlacing, so you don't
+need to call png_set_interlace_handling() or call this function multiple
+times, or any of that other stuff necessary with png_write_rows().
+
+ png_write_image(png_ptr, row_pointers);
+
+where row_pointers is:
+
+ png_byte *row_pointers[height];
+
+You can point to void or char or whatever you use for pixels.
+
+If you don't want to write the whole image at once, you can
+use png_write_rows() instead. If the file is not interlaced,
+this is simple:
+
+ png_write_rows(png_ptr, row_pointers,
+ number_of_rows);
+
+row_pointers is the same as in the png_write_image() call.
+
+If you are just writing one row at a time, you can do this with
+a single row_pointer instead of an array of row_pointers:
+
+ png_bytep row_pointer = row;
+
+ png_write_row(png_ptr, row_pointer);
+
+When the file is interlaced, things can get a good deal more
+complicated. The only currently (as of the PNG Specification
+version 1.2, dated July 1999) defined interlacing scheme for PNG files
+is the "Adam7" interlace scheme, that breaks down an
+image into seven smaller images of varying size. libpng will build
+these images for you, or you can do them yourself. If you want to
+build them yourself, see the PNG specification for details of which
+pixels to write when.
+
+If you don't want libpng to handle the interlacing details, just
+use png_set_interlace_handling() and call png_write_rows() the
+correct number of times to write all seven sub-images.
+
+If you want libpng to build the sub-images, call this before you start
+writing any rows:
+
+ number_of_passes =
+ png_set_interlace_handling(png_ptr);
+
+This will return the number of passes needed. Currently, this
+is seven, but may change if another interlace type is added.
+
+Then write the complete image number_of_passes times.
+
+ png_write_rows(png_ptr, row_pointers,
+ number_of_rows);
+
+As some of these rows are not used, and thus return immediately,
+you may want to read about interlacing in the PNG specification,
+and only update the rows that are actually used.
+
+Finishing a sequential write
+
+After you are finished writing the image, you should finish writing
+the file. If you are interested in writing comments or time, you should
+pass an appropriately filled png_info pointer. If you are not interested,
+you can pass NULL.
+
+ png_write_end(png_ptr, info_ptr);
+
+When you are done, you can free all memory used by libpng like this:
+
+ png_destroy_write_struct(&png_ptr, &info_ptr);
+
+It is also possible to individually free the info_ptr members that
+point to libpng-allocated storage with the following function:
+
+ png_free_data(png_ptr, info_ptr, mask, seq)
+ mask - identifies data to be freed, a mask
+ containing the bitwise OR of one or
+ more of
+ PNG_FREE_PLTE, PNG_FREE_TRNS,
+ PNG_FREE_HIST, PNG_FREE_ICCP,
+ PNG_FREE_PCAL, PNG_FREE_ROWS,
+ PNG_FREE_SCAL, PNG_FREE_SPLT,
+ PNG_FREE_TEXT, PNG_FREE_UNKN,
+ or simply PNG_FREE_ALL
+ seq - sequence number of item to be freed
+ (-1 for all items)
+
+This function may be safely called when the relevant storage has
+already been freed, or has not yet been allocated, or was allocated
+by the user and not by libpng, and will in those
+cases do nothing. The "seq" parameter is ignored if only one item
+of the selected data type, such as PLTE, is allowed. If "seq" is not
+-1, and multiple items are allowed for the data type identified in
+the mask, such as text or sPLT, only the n'th item in the structure
+is freed, where n is "seq".
+
+If you allocated data such as a palette that you passed
+in to libpng with png_set_*, you must not free it until just before the call to
+png_destroy_write_struct().
+
+The default behavior is only to free data that was allocated internally
+by libpng. This can be changed, so that libpng will not free the data,
+or so that it will free data that was allocated by the user with png_malloc()
+or png_zalloc() and passed in via a png_set_*() function, with
+
+ png_data_freer(png_ptr, info_ptr, freer, mask)
+ mask - which data elements are affected
+ same choices as in png_free_data()
+ freer - one of
+ PNG_DESTROY_WILL_FREE_DATA
+ PNG_SET_WILL_FREE_DATA
+ PNG_USER_WILL_FREE_DATA
+
+For example, to transfer responsibility for some data from a read structure
+to a write structure, you could use
+
+ png_data_freer(read_ptr, read_info_ptr,
+ PNG_USER_WILL_FREE_DATA,
+ PNG_FREE_PLTE|PNG_FREE_tRNS|PNG_FREE_hIST)
+ png_data_freer(write_ptr, write_info_ptr,
+ PNG_DESTROY_WILL_FREE_DATA,
+ PNG_FREE_PLTE|PNG_FREE_tRNS|PNG_FREE_hIST)
+
+thereby briefly reassigning responsibility for freeing to the user but
+immediately afterwards reassigning it once more to the write_destroy
+function. Having done this, it would then be safe to destroy the read
+structure and continue to use the PLTE, tRNS, and hIST data in the write
+structure.
+
+This function only affects data that has already been allocated.
+You can call this function before calling after the png_set_*() functions
+to control whether the user or png_destroy_*() is supposed to free the data.
+When the user assumes responsibility for libpng-allocated data, the
+application must use
+png_free() to free it, and when the user transfers responsibility to libpng
+for data that the user has allocated, the user must have used png_malloc()
+or png_zalloc() to allocate it.
+
+If you allocated text_ptr.text, text_ptr.lang, and text_ptr.translated_keyword
+separately, do not transfer responsibility for freeing text_ptr to libpng,
+because when libpng fills a png_text structure it combines these members with
+the key member, and png_free_data() will free only text_ptr.key. Similarly,
+if you transfer responsibility for free'ing text_ptr from libpng to your
+application, your application must not separately free those members.
+For a more compact example of writing a PNG image, see the file example.c.
+
+V. Modifying/Customizing libpng:
+
+There are three issues here. The first is changing how libpng does
+standard things like memory allocation, input/output, and error handling.
+The second deals with more complicated things like adding new chunks,
+adding new transformations, and generally changing how libpng works.
+Both of those are compile-time issues; that is, they are generally
+determined at the time the code is written, and there is rarely a need
+to provide the user with a means of changing them. The third is a
+run-time issue: choosing between and/or tuning one or more alternate
+versions of computationally intensive routines; specifically, optimized
+assembly-language (and therefore compiler- and platform-dependent)
+versions.
+
+Memory allocation, input/output, and error handling
+
+All of the memory allocation, input/output, and error handling in libpng
+goes through callbacks that are user-settable. The default routines are
+in pngmem.c, pngrio.c, pngwio.c, and pngerror.c, respectively. To change
+these functions, call the appropriate png_set_*_fn() function.
+
+Memory allocation is done through the functions png_malloc()
+and png_free(). These currently just call the standard C functions. If
+your pointers can't access more then 64K at a time, you will want to set
+MAXSEG_64K in zlib.h. Since it is unlikely that the method of handling
+memory allocation on a platform will change between applications, these
+functions must be modified in the library at compile time. If you prefer
+to use a different method of allocating and freeing data, you can use
+png_create_read_struct_2() or png_create_write_struct_2() to register
+your own functions as described above.
+These functions also provide a void pointer that can be retrieved via
+
+ mem_ptr=png_get_mem_ptr(png_ptr);
+
+Your replacement memory functions must have prototypes as follows:
+
+ png_voidp malloc_fn(png_structp png_ptr,
+ png_size_t size);
+ void free_fn(png_structp png_ptr, png_voidp ptr);
+
+Your malloc_fn() must return NULL in case of failure. The png_malloc()
+function will normally call png_error() if it receives a NULL from the
+system memory allocator or from your replacement malloc_fn().
+
+Input/Output in libpng is done through png_read() and png_write(),
+which currently just call fread() and fwrite(). The FILE * is stored in
+png_struct and is initialized via png_init_io(). If you wish to change
+the method of I/O, the library supplies callbacks that you can set
+through the function png_set_read_fn() and png_set_write_fn() at run
+time, instead of calling the png_init_io() function. These functions
+also provide a void pointer that can be retrieved via the function
+png_get_io_ptr(). For example:
+
+ png_set_read_fn(png_structp read_ptr,
+ voidp read_io_ptr, png_rw_ptr read_data_fn)
+
+ png_set_write_fn(png_structp write_ptr,
+ voidp write_io_ptr, png_rw_ptr write_data_fn,
+ png_flush_ptr output_flush_fn);
+
+ voidp read_io_ptr = png_get_io_ptr(read_ptr);
+ voidp write_io_ptr = png_get_io_ptr(write_ptr);
+
+The replacement I/O functions must have prototypes as follows:
+
+ void user_read_data(png_structp png_ptr,
+ png_bytep data, png_size_t length);
+ void user_write_data(png_structp png_ptr,
+ png_bytep data, png_size_t length);
+ void user_flush_data(png_structp png_ptr);
+
+Supplying NULL for the read, write, or flush functions sets them back
+to using the default C stream functions. It is an error to read from
+a write stream, and vice versa.
+
+Error handling in libpng is done through png_error() and png_warning().
+Errors handled through png_error() are fatal, meaning that png_error()
+should never return to its caller. Currently, this is handled via
+setjmp() and longjmp() (unless you have compiled libpng with
+PNG_SETJMP_NOT_SUPPORTED, in which case it is handled via PNG_ABORT()),
+but you could change this to do things like exit() if you should wish.
+
+On non-fatal errors, png_warning() is called
+to print a warning message, and then control returns to the calling code.
+By default png_error() and png_warning() print a message on stderr via
+fprintf() unless the library is compiled with PNG_NO_CONSOLE_IO defined
+(because you don't want the messages) or PNG_NO_STDIO defined (because
+fprintf() isn't available). If you wish to change the behavior of the error
+functions, you will need to set up your own message callbacks. These
+functions are normally supplied at the time that the png_struct is created.
+It is also possible to redirect errors and warnings to your own replacement
+functions after png_create_*_struct() has been called by calling:
+
+ png_set_error_fn(png_structp png_ptr,
+ png_voidp error_ptr, png_error_ptr error_fn,
+ png_error_ptr warning_fn);
+
+ png_voidp error_ptr = png_get_error_ptr(png_ptr);
+
+If NULL is supplied for either error_fn or warning_fn, then the libpng
+default function will be used, calling fprintf() and/or longjmp() if a
+problem is encountered. The replacement error functions should have
+parameters as follows:
+
+ void user_error_fn(png_structp png_ptr,
+ png_const_charp error_msg);
+ void user_warning_fn(png_structp png_ptr,
+ png_const_charp warning_msg);
+
+The motivation behind using setjmp() and longjmp() is the C++ throw and
+catch exception handling methods. This makes the code much easier to write,
+as there is no need to check every return code of every function call.
+However, there are some uncertainties about the status of local variables
+after a longjmp, so the user may want to be careful about doing anything after
+setjmp returns non-zero besides returning itself. Consult your compiler
+documentation for more details. For an alternative approach, you may wish
+to use the "cexcept" facility (see http://cexcept.sourceforge.net).
+
+Custom chunks
+
+If you need to read or write custom chunks, you may need to get deeper
+into the libpng code. The library now has mechanisms for storing
+and writing chunks of unknown type; you can even declare callbacks
+for custom chunks. However, this may not be good enough if the
+library code itself needs to know about interactions between your
+chunk and existing `intrinsic' chunks.
+
+If you need to write a new intrinsic chunk, first read the PNG
+specification. Acquire a first level of
+understanding of how it works. Pay particular attention to the
+sections that describe chunk names, and look at how other chunks were
+designed, so you can do things similarly. Second, check out the
+sections of libpng that read and write chunks. Try to find a chunk
+that is similar to yours and use it as a template. More details can
+be found in the comments inside the code. It is best to handle unknown
+chunks in a generic method, via callback functions, instead of by
+modifying libpng functions.
+
+If you wish to write your own transformation for the data, look through
+the part of the code that does the transformations, and check out some of
+the simpler ones to get an idea of how they work. Try to find a similar
+transformation to the one you want to add and copy off of it. More details
+can be found in the comments inside the code itself.
+
+Configuring for 16 bit platforms
+
+You will want to look into zconf.h to tell zlib (and thus libpng) that
+it cannot allocate more then 64K at a time. Even if you can, the memory
+won't be accessible. So limit zlib and libpng to 64K by defining MAXSEG_64K.
+
+Configuring for DOS
+
+For DOS users who only have access to the lower 640K, you will
+have to limit zlib's memory usage via a png_set_compression_mem_level()
+call. See zlib.h or zconf.h in the zlib library for more information.
+
+Configuring for Medium Model
+
+Libpng's support for medium model has been tested on most of the popular
+compilers. Make sure MAXSEG_64K gets defined, USE_FAR_KEYWORD gets
+defined, and FAR gets defined to far in pngconf.h, and you should be
+all set. Everything in the library (except for zlib's structure) is
+expecting far data. You must use the typedefs with the p or pp on
+the end for pointers (or at least look at them and be careful). Make
+note that the rows of data are defined as png_bytepp, which is an
+unsigned char far * far *.
+
+Configuring for gui/windowing platforms:
+
+You will need to write new error and warning functions that use the GUI
+interface, as described previously, and set them to be the error and
+warning functions at the time that png_create_*_struct() is called,
+in order to have them available during the structure initialization.
+They can be changed later via png_set_error_fn(). On some compilers,
+you may also have to change the memory allocators (png_malloc, etc.).
+
+Configuring for compiler xxx:
+
+All includes for libpng are in pngconf.h. If you need to add/change/delete
+an include, this is the place to do it. The includes that are not
+needed outside libpng are protected by the PNG_INTERNAL definition,
+which is only defined for those routines inside libpng itself. The
+files in libpng proper only include png.h, which includes pngconf.h.
+
+Configuring zlib:
+
+There are special functions to configure the compression. Perhaps the
+most useful one changes the compression level, which currently uses
+input compression values in the range 0 - 9. The library normally
+uses the default compression level (Z_DEFAULT_COMPRESSION = 6). Tests
+have shown that for a large majority of images, compression values in
+the range 3-6 compress nearly as well as higher levels, and do so much
+faster. For online applications it may be desirable to have maximum speed
+(Z_BEST_SPEED = 1). With versions of zlib after v0.99, you can also
+specify no compression (Z_NO_COMPRESSION = 0), but this would create
+files larger than just storing the raw bitmap. You can specify the
+compression level by calling:
+
+ png_set_compression_level(png_ptr, level);
+
+Another useful one is to reduce the memory level used by the library.
+The memory level defaults to 8, but it can be lowered if you are
+short on memory (running DOS, for example, where you only have 640K).
+Note that the memory level does have an effect on compression; among
+other things, lower levels will result in sections of incompressible
+data being emitted in smaller stored blocks, with a correspondingly
+larger relative overhead of up to 15% in the worst case.
+
+ png_set_compression_mem_level(png_ptr, level);
+
+The other functions are for configuring zlib. They are not recommended
+for normal use and may result in writing an invalid PNG file. See
+zlib.h for more information on what these mean.
+
+ png_set_compression_strategy(png_ptr,
+ strategy);
+ png_set_compression_window_bits(png_ptr,
+ window_bits);
+ png_set_compression_method(png_ptr, method);
+ png_set_compression_buffer_size(png_ptr, size);
+
+Controlling row filtering
+
+If you want to control whether libpng uses filtering or not, which
+filters are used, and how it goes about picking row filters, you
+can call one of these functions. The selection and configuration
+of row filters can have a significant impact on the size and
+encoding speed and a somewhat lesser impact on the decoding speed
+of an image. Filtering is enabled by default for RGB and grayscale
+images (with and without alpha), but not for paletted images nor
+for any images with bit depths less than 8 bits/pixel.
+
+The 'method' parameter sets the main filtering method, which is
+currently only '0' in the PNG 1.2 specification. The 'filters'
+parameter sets which filter(s), if any, should be used for each
+scanline. Possible values are PNG_ALL_FILTERS and PNG_NO_FILTERS
+to turn filtering on and off, respectively.
+
+Individual filter types are PNG_FILTER_NONE, PNG_FILTER_SUB,
+PNG_FILTER_UP, PNG_FILTER_AVG, PNG_FILTER_PAETH, which can be bitwise
+ORed together with '|' to specify one or more filters to use.
+These filters are described in more detail in the PNG specification.
+If you intend to change the filter type during the course of writing
+the image, you should start with flags set for all of the filters
+you intend to use so that libpng can initialize its internal
+structures appropriately for all of the filter types. (Note that this
+means the first row must always be adaptively filtered, because libpng
+currently does not allocate the filter buffers until png_write_row()
+is called for the first time.)
+
+ filters = PNG_FILTER_NONE | PNG_FILTER_SUB
+ PNG_FILTER_UP | PNG_FILTER_AVE |
+ PNG_FILTER_PAETH | PNG_ALL_FILTERS;
+
+ png_set_filter(png_ptr, PNG_FILTER_TYPE_BASE,
+ filters);
+ The second parameter can also be
+ PNG_INTRAPIXEL_DIFFERENCING if you are
+ writing a PNG to be embedded in a MNG
+ datastream. This parameter must be the
+ same as the value of filter_method used
+ in png_set_IHDR().
+
+It is also possible to influence how libpng chooses from among the
+available filters. This is done in one or both of two ways - by
+telling it how important it is to keep the same filter for successive
+rows, and by telling it the relative computational costs of the filters.
+
+ double weights[3] = {1.5, 1.3, 1.1},
+ costs[PNG_FILTER_VALUE_LAST] =
+ {1.0, 1.3, 1.3, 1.5, 1.7};
+
+ png_set_filter_heuristics(png_ptr,
+ PNG_FILTER_HEURISTIC_WEIGHTED, 3,
+ weights, costs);
+
+The weights are multiplying factors that indicate to libpng that the
+row filter should be the same for successive rows unless another row filter
+is that many times better than the previous filter. In the above example,
+if the previous 3 filters were SUB, SUB, NONE, the SUB filter could have a
+"sum of absolute differences" 1.5 x 1.3 times higher than other filters
+and still be chosen, while the NONE filter could have a sum 1.1 times
+higher than other filters and still be chosen. Unspecified weights are
+taken to be 1.0, and the specified weights should probably be declining
+like those above in order to emphasize recent filters over older filters.
+
+The filter costs specify for each filter type a relative decoding cost
+to be considered when selecting row filters. This means that filters
+with higher costs are less likely to be chosen over filters with lower
+costs, unless their "sum of absolute differences" is that much smaller.
+The costs do not necessarily reflect the exact computational speeds of
+the various filters, since this would unduly influence the final image
+size.
+
+Note that the numbers above were invented purely for this example and
+are given only to help explain the function usage. Little testing has
+been done to find optimum values for either the costs or the weights.
+
+Removing unwanted object code
+
+There are a bunch of #define's in pngconf.h that control what parts of
+libpng are compiled. All the defines end in _SUPPORTED. If you are
+never going to use a capability, you can change the #define to #undef
+before recompiling libpng and save yourself code and data space, or
+you can turn off individual capabilities with defines that begin with
+PNG_NO_.
+
+You can also turn all of the transforms and ancillary chunk capabilities
+off en masse with compiler directives that define
+PNG_NO_READ[or WRITE]_TRANSFORMS, or PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS,
+or all four,
+along with directives to turn on any of the capabilities that you do
+want. The PNG_NO_READ[or WRITE]_TRANSFORMS directives disable
+the extra transformations but still leave the library fully capable of reading
+and writing PNG files with all known public chunks
+Use of the PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS directive
+produces a library that is incapable of reading or writing ancillary chunks.
+If you are not using the progressive reading capability, you can
+turn that off with PNG_NO_PROGRESSIVE_READ (don't confuse
+this with the INTERLACING capability, which you'll still have).
+
+All the reading and writing specific code are in separate files, so the
+linker should only grab the files it needs. However, if you want to
+make sure, or if you are building a stand alone library, all the
+reading files start with pngr and all the writing files start with
+pngw. The files that don't match either (like png.c, pngtrans.c, etc.)
+are used for both reading and writing, and always need to be included.
+The progressive reader is in pngpread.c
+
+If you are creating or distributing a dynamically linked library (a .so
+or DLL file), you should not remove or disable any parts of the library,
+as this will cause applications linked with different versions of the
+library to fail if they call functions not available in your library.
+The size of the library itself should not be an issue, because only
+those sections that are actually used will be loaded into memory.
+
+Requesting debug printout
+
+The macro definition PNG_DEBUG can be used to request debugging
+printout. Set it to an integer value in the range 0 to 3. Higher
+numbers result in increasing amounts of debugging information. The
+information is printed to the "stderr" file, unless another file
+name is specified in the PNG_DEBUG_FILE macro definition.
+
+When PNG_DEBUG > 0, the following functions (macros) become available:
+
+ png_debug(level, message)
+ png_debug1(level, message, p1)
+ png_debug2(level, message, p1, p2)
+
+in which "level" is compared to PNG_DEBUG to decide whether to print
+the message, "message" is the formatted string to be printed,
+and p1 and p2 are parameters that are to be embedded in the string
+according to printf-style formatting directives. For example,
+
+ png_debug1(2, "foo=%d\n", foo);
+
+is expanded to
+
+ if(PNG_DEBUG > 2)
+ fprintf(PNG_DEBUG_FILE, "foo=%d\n", foo);
+
+When PNG_DEBUG is defined but is zero, the macros aren't defined, but you
+can still use PNG_DEBUG to control your own debugging:
+
+ #ifdef PNG_DEBUG
+ fprintf(stderr, ...
+ #endif
+
+When PNG_DEBUG = 1, the macros are defined, but only png_debug statements
+having level = 0 will be printed. There aren't any such statements in
+this version of libpng, but if you insert some they will be printed.
+
+VI. Runtime optimization
+
+A new feature in libpng 1.2.0 is the ability to dynamically switch between
+standard and optimized versions of some routines. Currently these are
+limited to three computationally intensive tasks when reading PNG files:
+decoding row filters, expanding interlacing, and combining interlaced or
+transparent row data with previous row data. Currently the optimized
+versions are available only for x86 (Intel, AMD, etc.) platforms with
+MMX support, though this may change in future versions. (For example,
+the non-MMX assembler optimizations for zlib might become similarly
+runtime-selectable in future releases, in which case libpng could be
+extended to support them. Alternatively, the compile-time choice of
+floating-point versus integer routines for gamma correction might become
+runtime-selectable.)
+
+Because such optimizations tend to be very platform- and compiler-dependent,
+both in how they are written and in how they perform, the new runtime code
+in libpng has been written to allow programs to query, enable, and disable
+either specific optimizations or all such optimizations. For example, to
+enable all possible optimizations (bearing in mind that some "optimizations"
+may actually run more slowly in rare cases):
+
+ #if defined(PNG_LIBPNG_VER) && (PNG_LIBPNG_VER >= 10200)
+ png_uint_32 mask, flags;
+
+ flags = png_get_asm_flags(png_ptr);
+ mask = png_get_asm_flagmask(PNG_SELECT_READ | PNG_SELECT_WRITE);
+ png_set_asm_flags(png_ptr, flags | mask);
+ #endif
+
+To enable only optimizations relevant to reading PNGs, use PNG_SELECT_READ
+by itself when calling png_get_asm_flagmask(); similarly for optimizing
+only writing. To disable all optimizations:
+
+ #if defined(PNG_LIBPNG_VER) && (PNG_LIBPNG_VER >= 10200)
+ flags = png_get_asm_flags(png_ptr);
+ mask = png_get_asm_flagmask(PNG_SELECT_READ | PNG_SELECT_WRITE);
+ png_set_asm_flags(png_ptr, flags & ~mask);
+ #endif
+
+To enable or disable only MMX-related features, use png_get_mmx_flagmask()
+in place of png_get_asm_flagmask(). The mmx version takes one additional
+parameter:
+
+ #if defined(PNG_LIBPNG_VER) && (PNG_LIBPNG_VER >= 10200)
+ int selection = PNG_SELECT_READ | PNG_SELECT_WRITE;
+ int compilerID;
+
+ mask = png_get_mmx_flagmask(selection, &compilerID);
+ #endif
+
+On return, compilerID will indicate which version of the MMX assembler
+optimizations was compiled. Currently two flavors exist: Microsoft
+Visual C++ (compilerID == 1) and GNU C (a.k.a. gcc/gas, compilerID == 2).
+On non-x86 platforms or on systems compiled without MMX optimizations, a
+value of -1 is used.
+
+Note that both png_get_asm_flagmask() and png_get_mmx_flagmask() return
+all valid, settable optimization bits for the version of the library that's
+currently in use. In the case of shared (dynamically linked) libraries,
+this may include optimizations that did not exist at the time the code was
+written and compiled. It is also possible, of course, to enable only known,
+specific optimizations; for example:
+
+ #if defined(PNG_LIBPNG_VER) && (PNG_LIBPNG_VER >= 10200)
+ flags = PNG_ASM_FLAG_MMX_READ_COMBINE_ROW \
+ | PNG_ASM_FLAG_MMX_READ_INTERLACE \
+ | PNG_ASM_FLAG_MMX_READ_FILTER_SUB \
+ | PNG_ASM_FLAG_MMX_READ_FILTER_UP \
+ | PNG_ASM_FLAG_MMX_READ_FILTER_AVG \
+ | PNG_ASM_FLAG_MMX_READ_FILTER_PAETH ;
+ png_set_asm_flags(png_ptr, flags);
+ #endif
+
+This method would enable only the MMX read-optimizations available at the
+time of libpng 1.2.0's release, regardless of whether a later version of
+the DLL were actually being used. (Also note that these functions did not
+exist in versions older than 1.2.0, so any attempt to run a dynamically
+linked app on such an older version would fail.)
+
+To determine whether the processor supports MMX instructions at all, use
+the png_mmx_support() function:
+
+ #if defined(PNG_LIBPNG_VER) && (PNG_LIBPNG_VER >= 10200)
+ mmxsupport = png_mmx_support();
+ #endif
+
+It returns -1 if MMX support is not compiled into libpng, 0 if MMX code
+is compiled but MMX is not supported by the processor, or 1 if MMX support
+is fully available. Note that png_mmx_support(), png_get_mmx_flagmask(),
+and png_get_asm_flagmask() all may be called without allocating and ini-
+tializing any PNG structures (for example, as part of a usage screen or
+"about" box).
+
+The following code can be used to prevent an application from using the
+thread_unsafe features, even if libpng was built with PNG_THREAD_UNSAFE_OK
+defined:
+
+#if defined(PNG_USE_PNGGCCRD) && defined(PNG_ASSEMBLER_CODE_SUPPORTED) \
+ && defined(PNG_THREAD_UNSAFE_OK)
+ /* Disable thread-unsafe features of pnggccrd */
+ if (png_access_version_number() >= 10200)
+ {
+ png_uint_32 mmx_disable_mask = 0;
+ png_uint_32 asm_flags;
+
+ mmx_disable_mask |= ( PNG_ASM_FLAG_MMX_READ_COMBINE_ROW \
+ | PNG_ASM_FLAG_MMX_READ_FILTER_SUB \
+ | PNG_ASM_FLAG_MMX_READ_FILTER_AVG \
+ | PNG_ASM_FLAG_MMX_READ_FILTER_PAETH );
+ asm_flags = png_get_asm_flags(png_ptr);
+ png_set_asm_flags(png_ptr, asm_flags & ~mmx_disable_mask);
+ }
+#endif
+
+For more extensive examples of runtime querying, enabling and disabling
+of optimized features, see contrib/gregbook/readpng2.c in the libpng
+source-code distribution.
+
+VII. MNG support
+
+The MNG specification (available at http://www.libpng.org/pub/mng) allows
+certain extensions to PNG for PNG images that are embedded in MNG datastreams.
+Libpng can support some of these extensions. To enable them, use the
+png_permit_mng_features() function:
+
+ feature_set = png_permit_mng_features(png_ptr, mask)
+ mask is a png_uint_32 containing the bitwise OR of the
+ features you want to enable. These include
+ PNG_FLAG_MNG_EMPTY_PLTE
+ PNG_FLAG_MNG_FILTER_64
+ PNG_ALL_MNG_FEATURES
+ feature_set is a png_uint_32 that is the bitwise AND of
+ your mask with the set of MNG features that is
+ supported by the version of libpng that you are using.
+
+It is an error to use this function when reading or writing a standalone
+PNG file with the PNG 8-byte signature. The PNG datastream must be wrapped
+in a MNG datastream. As a minimum, it must have the MNG 8-byte signature
+and the MHDR and MEND chunks. Libpng does not provide support for these
+or any other MNG chunks; your application must provide its own support for
+them. You may wish to consider using libmng (available at
+http://www.libmng.com) instead.
+
+VIII. Changes to Libpng from version 0.88
+
+It should be noted that versions of libpng later than 0.96 are not
+distributed by the original libpng author, Guy Schalnat, nor by
+Andreas Dilger, who had taken over from Guy during 1996 and 1997, and
+distributed versions 0.89 through 0.96, but rather by another member
+of the original PNG Group, Glenn Randers-Pehrson. Guy and Andreas are
+still alive and well, but they have moved on to other things.
+
+The old libpng functions png_read_init(), png_write_init(),
+png_info_init(), png_read_destroy(), and png_write_destroy() have been
+moved to PNG_INTERNAL in version 0.95 to discourage their use. These
+functions will be removed from libpng version 2.0.0.
+
+The preferred method of creating and initializing the libpng structures is
+via the png_create_read_struct(), png_create_write_struct(), and
+png_create_info_struct() because they isolate the size of the structures
+from the application, allow version error checking, and also allow the
+use of custom error handling routines during the initialization, which
+the old functions do not. The functions png_read_destroy() and
+png_write_destroy() do not actually free the memory that libpng
+allocated for these structs, but just reset the data structures, so they
+can be used instead of png_destroy_read_struct() and
+png_destroy_write_struct() if you feel there is too much system overhead
+allocating and freeing the png_struct for each image read.
+
+Setting the error callbacks via png_set_message_fn() before
+png_read_init() as was suggested in libpng-0.88 is no longer supported
+because this caused applications that do not use custom error functions
+to fail if the png_ptr was not initialized to zero. It is still possible
+to set the error callbacks AFTER png_read_init(), or to change them with
+png_set_error_fn(), which is essentially the same function, but with a new
+name to force compilation errors with applications that try to use the old
+method.
+
+Starting with version 1.0.7, you can find out which version of the library
+you are using at run-time:
+
+ png_uint_32 libpng_vn = png_access_version_number();
+
+The number libpng_vn is constructed from the major version, minor
+version with leading zero, and release number with leading zero,
+(e.g., libpng_vn for version 1.0.7 is 10007).
+
+You can also check which version of png.h you used when compiling your
+application:
+
+ png_uint_32 application_vn = PNG_LIBPNG_VER;
+
+IX. Y2K Compliance in libpng
+
+May 15, 2007
+
+Since the PNG Development group is an ad-hoc body, we can't make
+an official declaration.
+
+This is your unofficial assurance that libpng from version 0.71 and
+upward through 1.2.18 are Y2K compliant. It is my belief that earlier
+versions were also Y2K compliant.
+
+Libpng only has three year fields. One is a 2-byte unsigned integer that
+will hold years up to 65535. The other two hold the date in text
+format, and will hold years up to 9999.
+
+The integer is
+ "png_uint_16 year" in png_time_struct.
+
+The strings are
+ "png_charp time_buffer" in png_struct and
+ "near_time_buffer", which is a local character string in png.c.
+
+There are seven time-related functions:
+
+ png_convert_to_rfc_1123() in png.c
+ (formerly png_convert_to_rfc_1152() in error)
+ png_convert_from_struct_tm() in pngwrite.c, called
+ in pngwrite.c
+ png_convert_from_time_t() in pngwrite.c
+ png_get_tIME() in pngget.c
+ png_handle_tIME() in pngrutil.c, called in pngread.c
+ png_set_tIME() in pngset.c
+ png_write_tIME() in pngwutil.c, called in pngwrite.c
+
+All appear to handle dates properly in a Y2K environment. The
+png_convert_from_time_t() function calls gmtime() to convert from system
+clock time, which returns (year - 1900), which we properly convert to
+the full 4-digit year. There is a possibility that applications using
+libpng are not passing 4-digit years into the png_convert_to_rfc_1123()
+function, or that they are incorrectly passing only a 2-digit year
+instead of "year - 1900" into the png_convert_from_struct_tm() function,
+but this is not under our control. The libpng documentation has always
+stated that it works with 4-digit years, and the APIs have been
+documented as such.
+
+The tIME chunk itself is also Y2K compliant. It uses a 2-byte unsigned
+integer to hold the year, and can hold years as large as 65535.
+
+zlib, upon which libpng depends, is also Y2K compliant. It contains
+no date-related code.
+
+
+ Glenn Randers-Pehrson
+ libpng maintainer
+ PNG Development Group
diff --git a/Build/source/libs/libpng/libpng.3 b/Build/source/libs/libpng/libpng.3
index 3b52771edb3..a94c616db7f 100644
--- a/Build/source/libs/libpng/libpng.3
+++ b/Build/source/libs/libpng/libpng.3
@@ -1,6 +1,6 @@
-.TH LIBPNG 3 "January 5, 2007"
+.TH LIBPNG 3 "May 15, 2007"
.SH NAME
-libpng \- Portable Network Graphics (PNG) Reference Library 1.2.15
+libpng \- Portable Network Graphics (PNG) Reference Library 1.2.18
.SH SYNOPSIS
\fB
#include <png.h>\fP
@@ -410,10 +410,10 @@ Following is a copy of the libpng.txt file that accompanies libpng.
.SH LIBPNG.TXT
libpng.txt - A description on how to use and modify libpng
- libpng version 1.2.15 - January 5, 2007
+ libpng version 1.2.18 - May 15, 2007
Updated and distributed by Glenn Randers-Pehrson
<glennrp at users.sourceforge.net>
- Copyright (c) 1998-2005 Glenn Randers-Pehrson
+ Copyright (c) 1998-2007 Glenn Randers-Pehrson
For conditions of distribution and use, see copyright
notice in png.h.
@@ -443,6 +443,10 @@ it is heavily commented and should include everything most people
will need. We assume that libpng is already installed; see the
INSTALL file for instructions on how to install libpng.
+For examples of libpng usage, see the files "example.c", "pngtest.c",
+and the files in the "contrib" directory, all of which are included in the
+libpng distribution.
+
Libpng was written as a companion to the PNG specification, as a way
of reducing the amount of time and effort it takes to support the PNG
file format in application programs.
@@ -3327,13 +3331,13 @@ application:
.SH IX. Y2K Compliance in libpng
-January 5, 2007
+May 15, 2007
Since the PNG Development group is an ad-hoc body, we can't make
an official declaration.
This is your unofficial assurance that libpng from version 0.71 and
-upward through 1.2.15 are Y2K compliant. It is my belief that earlier
+upward through 1.2.18 are Y2K compliant. It is my belief that earlier
versions were also Y2K compliant.
Libpng only has three year fields. One is a 2-byte unsigned integer that
@@ -3511,6 +3515,17 @@ the first widely used release:
1.2.15rc1-5 13 10215 12.so.0.15[.0]
1.0.23 10 10023 10.so.0.23[.0]
1.2.15 13 10215 12.so.0.15[.0]
+ 1.2.16beta1-2 13 10216 12.so.0.16[.0]
+ 1.2.16rc1 13 10216 12.so.0.16[.0]
+ 1.0.24 10 10024 10.so.0.24[.0]
+ 1.2.16 13 10216 12.so.0.16[.0]
+ 1.2.17beta1-2 13 10217 12.so.0.17[.0]
+ 1.0.25rc1 10 10025 10.so.0.25[.0]
+ 1.2.17rc1-3 13 10217 12.so.0.17[.0]
+ 1.0.25 10 10025 10.so.0.25[.0]
+ 1.2.17 13 10217 12.so.0.17[.0]
+ 1.0.26 10 10026 10.so.0.26[.0]
+ 1.2.18 13 10218 12.so.0.18[.0]
Henceforth the source version will match the shared-library minor
and patch numbers; the shared-library major version number will be
@@ -3566,7 +3581,7 @@ possible without all of you.
Thanks to Frank J. T. Wojcik for helping with the documentation.
-Libpng version 1.2.15 - January 5, 2007:
+Libpng version 1.2.18 - May 15, 2007:
Initially created in 1995 by Guy Eric Schalnat, then of Group 42, Inc.
Currently maintained by Glenn Randers-Pehrson (glennrp at users.sourceforge.net).
@@ -3587,8 +3602,8 @@ included in the libpng distribution, the latter shall prevail.)
If you modify libpng you may insert additional notices immediately following
this sentence.
-libpng versions 1.2.6, August 15, 2004, through 1.2.15, January 5, 2007, are
-Copyright (c) 2004-2006 Glenn Randers-Pehrson, and are
+libpng versions 1.2.6, August 15, 2004, through 1.2.18, May 15, 2007, are
+Copyright (c) 2004,2006-2007 Glenn Randers-Pehrson, and are
distributed according to the same disclaimer and license as libpng-1.2.5
with the following individual added to the list of Contributing Authors
@@ -3686,7 +3701,7 @@ certification mark of the Open Source Initiative.
Glenn Randers-Pehrson
glennrp at users.sourceforge.net
-January 5, 2007
+May 15, 2007
.\" end of man page
diff --git a/Build/source/libs/libpng/libpngpf.3 b/Build/source/libs/libpng/libpngpf.3
index e9ed0816b2e..f5723cddc72 100644
--- a/Build/source/libs/libpng/libpngpf.3
+++ b/Build/source/libs/libpng/libpngpf.3
@@ -1,6 +1,6 @@
-.TH LIBPNGPF 3 "January 5, 2007"
+.TH LIBPNGPF 3 "May 15, 2007"
.SH NAME
-libpng \- Portable Network Graphics (PNG) Reference Library 1.2.15
+libpng \- Portable Network Graphics (PNG) Reference Library 1.2.18
(private functions)
.SH SYNOPSIS
\fB#include <png.h>\fP
diff --git a/Build/source/libs/libpng/png.5 b/Build/source/libs/libpng/png.5
index 8a5210b53ad..bf6c6fd5b7c 100644
--- a/Build/source/libs/libpng/png.5
+++ b/Build/source/libs/libpng/png.5
@@ -1,4 +1,4 @@
-.TH PNG 5 "January 5, 2007"
+.TH PNG 5 "May 15, 2007"
.SH NAME
png \- Portable Network Graphics (PNG) format
.SH DESCRIPTION
diff --git a/Build/source/libs/libpng/png.c b/Build/source/libs/libpng/png.c
index 86e8536b05b..9665c2c1c3b 100644
--- a/Build/source/libs/libpng/png.c
+++ b/Build/source/libs/libpng/png.c
@@ -1,7 +1,7 @@
/* png.c - location for general purpose libpng functions
*
- * Last changed in libpng 1.2.15 January 5, 2007
+ * Last changed in libpng 1.2.17 May 15, 2007
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2007 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
@@ -13,7 +13,7 @@
#include "png.h"
/* Generate a compiler error if there is an old png.h in the search path. */
-typedef version_1_2_15 Your_png_h_is_not_version_1_2_15;
+typedef version_1_2_18 Your_png_h_is_not_version_1_2_18;
/* Version information for C files. This had better match the version
* string defined in png.h. */
@@ -68,7 +68,7 @@ const int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
const int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
/* width of interlace block (used in assembler routines only) */
-#ifdef PNG_HAVE_ASSEMBLER_COMBINE_ROW
+#ifdef PNG_HAVE_MMX_COMBINE_ROW
const int FARDATA png_pass_width[] = {8, 4, 4, 2, 2, 1, 1};
#endif
@@ -490,6 +490,11 @@ if (mask & PNG_FREE_SPLT)
#endif
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
+ if(png_ptr->unknown_chunk.data)
+ {
+ png_free(png_ptr, png_ptr->unknown_chunk.data);
+ png_ptr->unknown_chunk.data = NULL;
+ }
#ifdef PNG_FREE_ME_SUPPORTED
if ((mask & PNG_FREE_UNKN) & info_ptr->free_me)
#else
@@ -701,7 +706,7 @@ png_charp PNGAPI
png_get_copyright(png_structp png_ptr)
{
if (&png_ptr != NULL) /* silence compiler warning about unused png_ptr */
- return ((png_charp) "\n libpng version 1.2.15 - January 5, 2007\n\
+ return ((png_charp) "\n libpng version 1.2.18 - May 15, 2007\n\
Copyright (c) 1998-2007 Glenn Randers-Pehrson\n\
Copyright (c) 1996-1997 Andreas Dilger\n\
Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.\n");
@@ -796,13 +801,13 @@ png_init_mmx_flags (png_structp png_ptr)
if (png_mmx_support() > 0) {
png_ptr->asm_flags |= PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU
-# ifdef PNG_HAVE_ASSEMBLER_COMBINE_ROW
+# ifdef PNG_HAVE_MMX_COMBINE_ROW
| PNG_ASM_FLAG_MMX_READ_COMBINE_ROW
# endif
-# ifdef PNG_HAVE_ASSEMBLER_READ_INTERLACE
+# ifdef PNG_HAVE_MMX_READ_INTERLACE
| PNG_ASM_FLAG_MMX_READ_INTERLACE
# endif
-# ifndef PNG_HAVE_ASSEMBLER_READ_FILTER_ROW
+# ifndef PNG_HAVE_MMX_READ_FILTER_ROW
;
# else
| PNG_ASM_FLAG_MMX_READ_FILTER_SUB
diff --git a/Build/source/libs/libpng/png.h b/Build/source/libs/libpng/png.h
index 1b9f371eb14..7bb0f301ea8 100644
--- a/Build/source/libs/libpng/png.h
+++ b/Build/source/libs/libpng/png.h
@@ -1,7 +1,7 @@
/* png.h - header file for PNG reference library
*
- * libpng version 1.2.15 - January 5, 2007
+ * libpng version 1.2.18 - May 15, 2007
* Copyright (c) 1998-2007 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
@@ -9,7 +9,7 @@
* Authors and maintainers:
* libpng versions 0.71, May 1995, through 0.88, January 1996: Guy Schalnat
* libpng versions 0.89c, June 1996, through 0.96, May 1997: Andreas Dilger
- * libpng versions 0.97, January 1998, through 1.2.15 - January 5, 2007: Glenn
+ * libpng versions 0.97, January 1998, through 1.2.18 - May 15, 2007: Glenn
* See also "Contributing Authors", below.
*
* Note about libpng version numbers:
@@ -139,6 +139,17 @@
* 1.2.15rc1-5 13 10215 12.so.0.15[.0]
* 1.0.23 10 10023 10.so.0.23[.0]
* 1.2.15 13 10215 12.so.0.15[.0]
+ * 1.2.16beta1-2 13 10216 12.so.0.16[.0]
+ * 1.2.16rc1 13 10216 12.so.0.16[.0]
+ * 1.0.24 10 10024 10.so.0.24[.0]
+ * 1.2.16 13 10216 12.so.0.16[.0]
+ * 1.2.17beta1-2 13 10217 12.so.0.17[.0]
+ * 1.0.25rc1 10 10025 10.so.0.25[.0]
+ * 1.2.17rc1-3 13 10217 12.so.0.17[.0]
+ * 1.0.25 10 10025 10.so.0.25[.0]
+ * 1.2.17 13 10217 12.so.0.17[.0]
+ * 1.0.26 10 10026 10.so.0.26[.0]
+ * 1.2.18 13 10218 12.so.0.18[.0]
*
* Henceforth the source version will match the shared-library major
* and minor numbers; the shared-library major version number will be
@@ -168,8 +179,8 @@
* If you modify libpng you may insert additional notices immediately following
* this sentence.
*
- * libpng versions 1.2.6, August 15, 2004, through 1.2.15, January 5, 2007, are
- * Copyright (c) 2004, 2007 Glenn Randers-Pehrson, and are
+ * libpng versions 1.2.6, August 15, 2004, through 1.2.18, May 15, 2007, are
+ * Copyright (c) 2004, 2006-2007 Glenn Randers-Pehrson, and are
* distributed according to the same disclaimer and license as libpng-1.2.5
* with the following individual added to the list of Contributing Authors:
*
@@ -280,13 +291,13 @@
* Y2K compliance in libpng:
* =========================
*
- * January 5, 2007
+ * May 15, 2007
*
* Since the PNG Development group is an ad-hoc body, we can't make
* an official declaration.
*
* This is your unofficial assurance that libpng from version 0.71 and
- * upward through 1.2.15 are Y2K compliant. It is my belief that earlier
+ * upward through 1.2.18 are Y2K compliant. It is my belief that earlier
* versions were also Y2K compliant.
*
* Libpng only has three year fields. One is a 2-byte unsigned integer
@@ -342,9 +353,9 @@
*/
/* Version information for png.h - this should match the version in png.c */
-#define PNG_LIBPNG_VER_STRING "1.2.15"
+#define PNG_LIBPNG_VER_STRING "1.2.18"
#define PNG_HEADER_VERSION_STRING \
- " libpng version 1.2.15 - January 5, 2007 (header)\n"
+ " libpng version 1.2.18 - May 15, 2007 (header)\n"
#define PNG_LIBPNG_VER_SONUM 0
#define PNG_LIBPNG_VER_DLLNUM 13
@@ -352,7 +363,7 @@
/* These should match the first 3 components of PNG_LIBPNG_VER_STRING: */
#define PNG_LIBPNG_VER_MAJOR 1
#define PNG_LIBPNG_VER_MINOR 2
-#define PNG_LIBPNG_VER_RELEASE 15
+#define PNG_LIBPNG_VER_RELEASE 18
/* This should match the numeric part of the final component of
* PNG_LIBPNG_VER_STRING, omitting any leading zero: */
@@ -380,7 +391,7 @@
* Versions 0.7 through 1.0.0 were in the range 0 to 100 here (only
* version 1.0.0 was mis-numbered 100 instead of 10000). From
* version 1.0.1 it's xxyyzz, where x=major, y=minor, z=release */
-#define PNG_LIBPNG_VER 10215 /* 1.2.15 */
+#define PNG_LIBPNG_VER 10218 /* 1.2.18 */
#ifndef PNG_VERSION_INFO_ONLY
/* include the compression library's header */
@@ -1384,13 +1395,18 @@ struct png_struct_def
png_uint_32 user_height_max;
#endif
+/* New member added in libpng-1.0.25 and 1.2.17 */
+#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
+ /* storage for unknown chunk that the library doesn't recognize. */
+ png_unknown_chunk unknown_chunk;
+#endif
};
/* This triggers a compiler error in png.c, if png.c and png.h
* do not agree upon the version number.
*/
-typedef png_structp version_1_2_15;
+typedef png_structp version_1_2_18;
typedef png_struct FAR * FAR * png_structpp;
@@ -2386,7 +2402,7 @@ extern PNG_EXPORT(void,png_set_sCAL_s) PNGARG((png_structp png_ptr,
handling or default unknown chunk handling is not desired. Any chunks not
listed will be handled in the default manner. The IHDR and IEND chunks
must not be listed.
- keep = 0: follow default behavour
+ keep = 0: follow default behaviour
= 1: do not keep
= 2: keep only if safe-to-copy
= 3: keep even if unsafe-to-copy
@@ -2667,16 +2683,21 @@ extern PNG_EXPORT(void,png_save_uint_16)
* be found in the files where the functions are located.
*/
-#if defined(PNG_INTERNAL)
-/* Various modes of operation. Note that after an init, mode is set to
- * zero automatically when the structure is created.
+/* Various modes of operation, that are visible to applications because
+ * they are used for unknown chunk location.
*/
#define PNG_HAVE_IHDR 0x01
#define PNG_HAVE_PLTE 0x02
#define PNG_HAVE_IDAT 0x04
#define PNG_AFTER_IDAT 0x08 /* Have complete zlib datastream */
#define PNG_HAVE_IEND 0x10
+
+#if defined(PNG_INTERNAL)
+
+/* More modes of operation. Note that after an init, mode is set to
+ * zero automatically when the structure is created.
+ */
#define PNG_HAVE_gAMA 0x20
#define PNG_HAVE_cHRM 0x40
#define PNG_HAVE_sRGB 0x80
diff --git a/Build/source/libs/libpng/pngconf.h b/Build/source/libs/libpng/pngconf.h
index 07344bacb84..a5047325f77 100644
--- a/Build/source/libs/libpng/pngconf.h
+++ b/Build/source/libs/libpng/pngconf.h
@@ -1,7 +1,7 @@
/* pngconf.h - machine configurable file for libpng
*
- * libpng version 1.2.15 - January 5, 2007
+ * libpng version 1.2.18 - May 15, 2007
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2007 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
@@ -1458,9 +1458,9 @@ typedef z_stream FAR * png_zstreamp;
* MMX will be detected at run time and used if present.
*/
#ifdef PNG_USE_PNGVCRD
-# define PNG_HAVE_ASSEMBLER_COMBINE_ROW
-# define PNG_HAVE_ASSEMBLER_READ_INTERLACE
-# define PNG_HAVE_ASSEMBLER_READ_FILTER_ROW
+# define PNG_HAVE_MMX_COMBINE_ROW
+# define PNG_HAVE_MMX_READ_INTERLACE
+# define PNG_HAVE_MMX_READ_FILTER_ROW
#endif
/* Set this in the makefile for gcc/as on Pentium, not here. */
@@ -1468,9 +1468,9 @@ typedef z_stream FAR * png_zstreamp;
* MMX will be detected at run time and used if present.
*/
#ifdef PNG_USE_PNGGCCRD
-# define PNG_HAVE_ASSEMBLER_COMBINE_ROW
-# define PNG_HAVE_ASSEMBLER_READ_INTERLACE
-# define PNG_HAVE_ASSEMBLER_READ_FILTER_ROW
+# define PNG_HAVE_MMX_COMBINE_ROW
+# define PNG_HAVE_MMX_READ_INTERLACE
+# define PNG_HAVE_MMX_READ_FILTER_ROW
#endif
/* - see pnggccrd.c for info about what is currently enabled */
diff --git a/Build/source/libs/libpng/pngerror.c b/Build/source/libs/libpng/pngerror.c
index c8c58b91d09..f50f6534427 100644
--- a/Build/source/libs/libpng/pngerror.c
+++ b/Build/source/libs/libpng/pngerror.c
@@ -113,7 +113,7 @@ png_warning(png_structp png_ptr, png_const_charp warning_message)
* if the character is invalid.
*/
#define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
-static PNG_CONST char png_digit[16] = {
+const static PNG_CONST char png_digit[16] = {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'A', 'B', 'C', 'D', 'E', 'F'
};
diff --git a/Build/source/libs/libpng/pnggccrd.c b/Build/source/libs/libpng/pnggccrd.c
index 7983f8ea102..fab523c0bdc 100644
--- a/Build/source/libs/libpng/pnggccrd.c
+++ b/Build/source/libs/libpng/pnggccrd.c
@@ -250,9 +250,9 @@
int PNGAPI png_mmx_support(void);
#ifdef PNG_USE_LOCAL_ARRAYS
-static const int FARDATA png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
-static const int FARDATA png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
-static const int FARDATA png_pass_width[7] = {8, 4, 4, 2, 2, 1, 1};
+const static int FARDATA png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
+const static int FARDATA png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
+const static int FARDATA png_pass_width[7] = {8, 4, 4, 2, 2, 1, 1};
#endif
#if defined(PNG_MMX_CODE_SUPPORTED)
@@ -311,30 +311,30 @@ static const int FARDATA png_pass_width[7] = {8, 4, 4, 2, 2, 1, 1};
static int _unmask;
#endif
-static unsigned long long _mask8_0 = 0x0102040810204080LL;
+const static unsigned long long _mask8_0 = 0x0102040810204080LL;
-static unsigned long long _mask16_1 = 0x0101020204040808LL;
-static unsigned long long _mask16_0 = 0x1010202040408080LL;
+const static unsigned long long _mask16_1 = 0x0101020204040808LL;
+const static unsigned long long _mask16_0 = 0x1010202040408080LL;
-static unsigned long long _mask24_2 = 0x0101010202020404LL;
-static unsigned long long _mask24_1 = 0x0408080810101020LL;
-static unsigned long long _mask24_0 = 0x2020404040808080LL;
+const static unsigned long long _mask24_2 = 0x0101010202020404LL;
+const static unsigned long long _mask24_1 = 0x0408080810101020LL;
+const static unsigned long long _mask24_0 = 0x2020404040808080LL;
-static unsigned long long _mask32_3 = 0x0101010102020202LL;
-static unsigned long long _mask32_2 = 0x0404040408080808LL;
-static unsigned long long _mask32_1 = 0x1010101020202020LL;
-static unsigned long long _mask32_0 = 0x4040404080808080LL;
+const static unsigned long long _mask32_3 = 0x0101010102020202LL;
+const static unsigned long long _mask32_2 = 0x0404040408080808LL;
+const static unsigned long long _mask32_1 = 0x1010101020202020LL;
+const static unsigned long long _mask32_0 = 0x4040404080808080LL;
-static unsigned long long _mask48_5 = 0x0101010101010202LL;
-static unsigned long long _mask48_4 = 0x0202020204040404LL;
-static unsigned long long _mask48_3 = 0x0404080808080808LL;
-static unsigned long long _mask48_2 = 0x1010101010102020LL;
-static unsigned long long _mask48_1 = 0x2020202040404040LL;
-static unsigned long long _mask48_0 = 0x4040808080808080LL;
+const static unsigned long long _mask48_5 = 0x0101010101010202LL;
+const static unsigned long long _mask48_4 = 0x0202020204040404LL;
+const static unsigned long long _mask48_3 = 0x0404080808080808LL;
+const static unsigned long long _mask48_2 = 0x1010101010102020LL;
+const static unsigned long long _mask48_1 = 0x2020202040404040LL;
+const static unsigned long long _mask48_0 = 0x4040808080808080LL;
-static unsigned long long _const4 = 0x0000000000FFFFFFLL;
-//static unsigned long long _const5 = 0x000000FFFFFF0000LL; // NOT USED
-static unsigned long long _const6 = 0x00000000000000FFLL;
+const static unsigned long long _const4 = 0x0000000000FFFFFFLL;
+//const static unsigned long long _const5 = 0x000000FFFFFF0000LL; // NOT USED
+const static unsigned long long _const6 = 0x00000000000000FFLL;
// These are used in the row-filter routines and should/would be local
// variables if not for gcc addressing limitations.
diff --git a/Build/source/libs/libpng/pngpread.c b/Build/source/libs/libpng/pngpread.c
index d226c75d364..1470b0fe0f6 100644
--- a/Build/source/libs/libpng/pngpread.c
+++ b/Build/source/libs/libpng/pngpread.c
@@ -1,9 +1,9 @@
/* pngpread.c - read a png file in push mode
*
- * Last changed in libpng 1.2.13 November 13, 2006
+ * Last changed in libpng 1.2.17 May 15, 2007
* For conditions of distribution and use, see copyright notice in png.h
- * Copyright (c) 1998-2006 Glenn Randers-Pehrson
+ * Copyright (c) 1998-2007 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*/
@@ -1488,8 +1488,6 @@ png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32
#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
if (png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS)
{
- png_unknown_chunk chunk;
-
#ifdef PNG_MAX_MALLOC_64K
if (length > (png_uint_32)65535L)
{
@@ -1498,28 +1496,35 @@ png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32
length = (png_uint_32)65535L;
}
#endif
-
- png_strcpy((png_charp)chunk.name, (png_charp)png_ptr->chunk_name);
- chunk.data = (png_bytep)png_malloc(png_ptr, length);
- png_crc_read(png_ptr, chunk.data, length);
- chunk.size = length;
+ png_strcpy((png_charp)png_ptr->unknown_chunk.name,
+ (png_charp)png_ptr->chunk_name);
+ png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
+ png_ptr->unknown_chunk.size = (png_size_t)length;
+ png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
#if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
if(png_ptr->read_user_chunk_fn != NULL)
{
/* callback to user unknown chunk handler */
- if ((*(png_ptr->read_user_chunk_fn)) (png_ptr, &chunk) <= 0)
+ int ret;
+ ret = (*(png_ptr->read_user_chunk_fn))
+ (png_ptr, &png_ptr->unknown_chunk);
+ if (ret < 0)
+ png_chunk_error(png_ptr, "error in user chunk");
+ if (ret == 0)
{
if (!(png_ptr->chunk_name[0] & 0x20))
if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
PNG_HANDLE_CHUNK_ALWAYS)
png_chunk_error(png_ptr, "unknown critical chunk");
+ png_set_unknown_chunks(png_ptr, info_ptr,
+ &png_ptr->unknown_chunk, 1);
}
- png_set_unknown_chunks(png_ptr, info_ptr, &chunk, 1);
}
- else
+#else
+ png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
#endif
- png_set_unknown_chunks(png_ptr, info_ptr, &chunk, 1);
- png_free(png_ptr, chunk.data);
+ png_free(png_ptr, png_ptr->unknown_chunk.data);
+ png_ptr->unknown_chunk.data = NULL;
}
else
#endif
@@ -1553,11 +1558,11 @@ void PNGAPI
png_progressive_combine_row (png_structp png_ptr,
png_bytep old_row, png_bytep new_row)
{
- if(png_ptr == NULL) return;
#ifdef PNG_USE_LOCAL_ARRAYS
const int FARDATA png_pass_dsp_mask[7] =
{0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
#endif
+ if(png_ptr == NULL) return;
if (new_row != NULL) /* new_row must == png_ptr->row_buf here. */
png_combine_row(png_ptr, old_row, png_pass_dsp_mask[png_ptr->pass]);
}
diff --git a/Build/source/libs/libpng/pngrtran.c b/Build/source/libs/libpng/pngrtran.c
index 2fa96f312ca..6ef0a1c0730 100644
--- a/Build/source/libs/libpng/pngrtran.c
+++ b/Build/source/libs/libpng/pngrtran.c
@@ -583,7 +583,7 @@ png_set_expand_gray_1_2_4_to_8(png_structp png_ptr)
{
png_debug(1, "in png_set_expand_gray_1_2_4_to_8\n");
if(png_ptr == NULL) return;
- png_ptr->transformations |= PNG_EXPAND_tRNS;
+ png_ptr->transformations |= PNG_EXPAND;
}
#endif
@@ -1293,9 +1293,9 @@ png_do_read_transformations(png_structp png_ptr)
if(rgb_error)
{
png_ptr->rgb_to_gray_status=1;
- if(png_ptr->transformations == PNG_RGB_TO_GRAY_WARN)
+ if(png_ptr->transformations & PNG_RGB_TO_GRAY_WARN)
png_warning(png_ptr, "png_do_rgb_to_gray found nongray pixel");
- if(png_ptr->transformations == PNG_RGB_TO_GRAY_ERR)
+ if(png_ptr->transformations & PNG_RGB_TO_GRAY_ERR)
png_error(png_ptr, "png_do_rgb_to_gray found nongray pixel");
}
}
@@ -3965,7 +3965,7 @@ png_do_dither(png_row_infop row_info, png_bytep row,
#ifdef PNG_FLOATING_POINT_SUPPORTED
#if defined(PNG_READ_GAMMA_SUPPORTED)
-static int png_gamma_shift[] =
+const static int png_gamma_shift[] =
{0x10, 0x21, 0x42, 0x84, 0x110, 0x248, 0x550, 0xff0, 0x00};
/* We build the 8- or 16-bit gamma tables here. Note that for 16-bit
diff --git a/Build/source/libs/libpng/pngrutil.c b/Build/source/libs/libpng/pngrutil.c
index 6157b3de46e..2abca7cc54b 100644
--- a/Build/source/libs/libpng/pngrutil.c
+++ b/Build/source/libs/libpng/pngrutil.c
@@ -1,7 +1,7 @@
/* pngrutil.c - utilities to read a PNG file
*
- * Last changed in libpng 1.2.15 January 5, 2007
+ * Last changed in libpng 1.2.17 May 15, 2007
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2007 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
@@ -181,7 +181,7 @@ png_decompress_chunk(png_structp png_ptr, int comp_type,
png_charp chunkdata, png_size_t chunklength,
png_size_t prefix_size, png_size_t *newlength)
{
- static char msg[] = "Error decoding compressed text";
+ const static char msg[] = "Error decoding compressed text";
png_charp text;
png_size_t text_size;
@@ -1314,7 +1314,10 @@ png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
}
if (png_crc_finish(png_ptr, 0))
+ {
+ png_ptr->num_trans = 0;
return;
+ }
png_set_tRNS(png_ptr, info_ptr, readbuf, png_ptr->num_trans,
&(png_ptr->trans_values));
@@ -2173,8 +2176,6 @@ png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
if ((png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS) ||
(png_ptr->read_user_chunk_fn != NULL))
{
- png_unknown_chunk chunk;
-
#ifdef PNG_MAX_MALLOC_64K
if (length > (png_uint_32)65535L)
{
@@ -2183,30 +2184,35 @@ png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
length = (png_uint_32)65535L;
}
#endif
- png_strcpy((png_charp)chunk.name, (png_charp)png_ptr->chunk_name);
- chunk.data = (png_bytep)png_malloc(png_ptr, length);
- chunk.size = (png_size_t)length;
- png_crc_read(png_ptr, (png_bytep)chunk.data, length);
+ png_strcpy((png_charp)png_ptr->unknown_chunk.name,
+ (png_charp)png_ptr->chunk_name);
+ png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
+ png_ptr->unknown_chunk.size = (png_size_t)length;
+ png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
#if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
if(png_ptr->read_user_chunk_fn != NULL)
{
/* callback to user unknown chunk handler */
- if ((*(png_ptr->read_user_chunk_fn)) (png_ptr, &chunk) <= 0)
+ int ret;
+ ret = (*(png_ptr->read_user_chunk_fn))
+ (png_ptr, &png_ptr->unknown_chunk);
+ if (ret < 0)
+ png_chunk_error(png_ptr, "error in user chunk");
+ if (ret == 0)
{
if (!(png_ptr->chunk_name[0] & 0x20))
if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
PNG_HANDLE_CHUNK_ALWAYS)
- {
- png_free(png_ptr, chunk.data);
png_chunk_error(png_ptr, "unknown critical chunk");
- }
- png_set_unknown_chunks(png_ptr, info_ptr, &chunk, 1);
+ png_set_unknown_chunks(png_ptr, info_ptr,
+ &png_ptr->unknown_chunk, 1);
}
}
- else
+#else
+ png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
#endif
- png_set_unknown_chunks(png_ptr, info_ptr, &chunk, 1);
- png_free(png_ptr, chunk.data);
+ png_free(png_ptr, png_ptr->unknown_chunk.data);
+ png_ptr->unknown_chunk.data = NULL;
}
else
#endif
diff --git a/Build/source/libs/libpng/pngset.c b/Build/source/libs/libpng/pngset.c
index 24fa24dea90..f1a1ef6100f 100644
--- a/Build/source/libs/libpng/pngset.c
+++ b/Build/source/libs/libpng/pngset.c
@@ -1,7 +1,7 @@
/* pngset.c - storage of image information into info struct
*
- * Last changed in libpng 1.2.15 January 5, 2007
+ * Last changed in libpng 1.2.17 May 15, 2007
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2007 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
@@ -877,7 +877,9 @@ png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
textp->itxt_length = 0;
#endif
}
+#if 0 /* appears to be redundant; */
info_ptr->text[info_ptr->num_text]= *textp;
+#endif
info_ptr->num_text++;
png_debug1(3, "transferred text chunk %d\n", info_ptr->num_text);
}
@@ -1200,13 +1202,13 @@ png_set_asm_flags (png_structp png_ptr, png_uint_32 asm_flags)
#ifdef PNG_MMX_CODE_SUPPORTED
settable_mmx_flags =
-#ifdef PNG_HAVE_ASSEMBLER_COMBINE_ROW
+#ifdef PNG_HAVE_MMX_COMBINE_ROW
PNG_ASM_FLAG_MMX_READ_COMBINE_ROW |
#endif
-#ifdef PNG_HAVE_ASSEMBLER_READ_INTERLACE
+#ifdef PNG_HAVE_MMX_READ_INTERLACE
PNG_ASM_FLAG_MMX_READ_INTERLACE |
#endif
-#ifdef PNG_HAVE_ASSEMBLER_READ_FILTER_ROW
+#ifdef PNG_HAVE_MMX_READ_FILTER_ROW
PNG_ASM_FLAG_MMX_READ_FILTER_SUB |
PNG_ASM_FLAG_MMX_READ_FILTER_UP |
PNG_ASM_FLAG_MMX_READ_FILTER_AVG |
diff --git a/Build/source/libs/libpng/pngtest.c b/Build/source/libs/libpng/pngtest.c
index e2841d72044..299e2947de2 100644
--- a/Build/source/libs/libpng/pngtest.c
+++ b/Build/source/libs/libpng/pngtest.c
@@ -1551,4 +1551,4 @@ main(int argc, char *argv[])
}
/* Generate a compiler error if there is an old png.h in the search path. */
-typedef version_1_2_15 your_png_h_is_not_version_1_2_15;
+typedef version_1_2_18 your_png_h_is_not_version_1_2_18;
diff --git a/Build/source/libs/libpng/pngtrans.c b/Build/source/libs/libpng/pngtrans.c
index 25f42c871be..8cb4b886165 100644
--- a/Build/source/libs/libpng/pngtrans.c
+++ b/Build/source/libs/libpng/pngtrans.c
@@ -252,7 +252,7 @@ png_do_swap(png_row_infop row_info, png_bytep row)
#endif
#if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED)
-static PNG_CONST png_byte onebppswaptable[256] = {
+const static PNG_CONST png_byte onebppswaptable[256] = {
0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0,
0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8,
@@ -287,7 +287,7 @@ static PNG_CONST png_byte onebppswaptable[256] = {
0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
};
-static PNG_CONST png_byte twobppswaptable[256] = {
+const static PNG_CONST png_byte twobppswaptable[256] = {
0x00, 0x40, 0x80, 0xC0, 0x10, 0x50, 0x90, 0xD0,
0x20, 0x60, 0xA0, 0xE0, 0x30, 0x70, 0xB0, 0xF0,
0x04, 0x44, 0x84, 0xC4, 0x14, 0x54, 0x94, 0xD4,
@@ -322,7 +322,7 @@ static PNG_CONST png_byte twobppswaptable[256] = {
0x2F, 0x6F, 0xAF, 0xEF, 0x3F, 0x7F, 0xBF, 0xFF
};
-static PNG_CONST png_byte fourbppswaptable[256] = {
+const static PNG_CONST png_byte fourbppswaptable[256] = {
0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70,
0x80, 0x90, 0xA0, 0xB0, 0xC0, 0xD0, 0xE0, 0xF0,
0x01, 0x11, 0x21, 0x31, 0x41, 0x51, 0x61, 0x71,
@@ -652,10 +652,11 @@ png_set_user_transform_info(png_structp png_ptr, png_voidp
png_voidp PNGAPI
png_get_user_transform_ptr(png_structp png_ptr)
{
- if (png_ptr == NULL) return (NULL);
#if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
+ if (png_ptr == NULL) return (NULL);
return ((png_voidp)png_ptr->user_transform_ptr);
-#endif
+#else
return (NULL);
+#endif
}
#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
diff --git a/Build/source/libs/libpng/pngwutil.c b/Build/source/libs/libpng/pngwutil.c
index e108c61064e..314bea20d1c 100644
--- a/Build/source/libs/libpng/pngwutil.c
+++ b/Build/source/libs/libpng/pngwutil.c
@@ -523,9 +523,10 @@ png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height,
png_ptr->zlib_window_bits = 15;
if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_METHOD))
png_ptr->zlib_method = 8;
- deflateInit2(&png_ptr->zstream, png_ptr->zlib_level,
+ if (deflateInit2(&png_ptr->zstream, png_ptr->zlib_level,
png_ptr->zlib_method, png_ptr->zlib_window_bits,
- png_ptr->zlib_mem_level, png_ptr->zlib_strategy);
+ png_ptr->zlib_mem_level, png_ptr->zlib_strategy) != Z_OK)
+ png_error(png_ptr, "zlib failed to initialize compressor");
png_ptr->zstream.next_out = png_ptr->zbuf;
png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
/* libpng is not interested in zstream.data_type */
diff --git a/Build/source/libs/obsdcompat/README b/Build/source/libs/obsdcompat/README
index 87c161ad23e..8fa2f89491c 100644
--- a/Build/source/libs/obsdcompat/README
+++ b/Build/source/libs/obsdcompat/README
@@ -1,10 +1,11 @@
-OpenBSD-Compat for pdfTeX 0.1
-=============================
+OpenBSD-Compat for pdfTeX v0.2
+==============================
+$Id: README 108 2007-05-20 20:03:54Z ms $
Herein is a (heavily butchered) version of the openbsd-compat "library" of
-openssh 4.3 for use with pdfTeX. All files have their respective copyrights and
+openssh 4.6 for use with pdfTeX. All files have their respective copyrights and
licenses (either BSD or public domain). Check them for license etc.
Please send bug reports, offers of help, etc. to martin@pdftex.org
-Martin Schröder, 2006-07-26
+Martin Schröder, $Date: 2007-07-11 15:11:12 +0200 (Mi, 11 Jul 2007) $
diff --git a/Build/source/libs/obsdcompat/bsd-asprintf.c b/Build/source/libs/obsdcompat/bsd-asprintf.c
index 67480139ebd..00fa0dfd8a7 100644
--- a/Build/source/libs/obsdcompat/bsd-asprintf.c
+++ b/Build/source/libs/obsdcompat/bsd-asprintf.c
@@ -39,7 +39,8 @@
#define INIT_SZ 128
-int vasprintf(char **str, const char *fmt, va_list ap)
+int
+vasprintf(char **str, const char *fmt, va_list ap)
{
int ret = -1;
va_list ap2;
@@ -53,7 +54,7 @@ int vasprintf(char **str, const char *fmt, va_list ap)
ret = vsnprintf(string, INIT_SZ, fmt, ap2);
if (ret >= 0 && ret < INIT_SZ) { /* succeeded with initial alloc */
*str = string;
- } else if (ret == INT_MAX) { /* shouldn't happen */
+ } else if (ret == INT_MAX || ret < 0) { /* Bad length */
goto fail;
} else { /* bigger than initial, realloc allowing for nul */
len = (size_t)ret + 1;
diff --git a/Build/source/libs/obsdcompat/bsd-snprintf.c b/Build/source/libs/obsdcompat/bsd-snprintf.c
index 04651e1d438..41d2be23899 100644
--- a/Build/source/libs/obsdcompat/bsd-snprintf.c
+++ b/Build/source/libs/obsdcompat/bsd-snprintf.c
@@ -85,6 +85,11 @@
*
* Move #endif to make sure VA_COPY, LDOUBLE, etc are defined even
* if the C library has some snprintf functions already.
+ *
+ * Damien Miller (djm@mindrot.org) Jan 2007
+ * Fix integer overflows in return value.
+ * Make formatting quite a bit faster by inlining dopr_outch()
+ *
**************************************************************/
#include "includes.h"
@@ -112,6 +117,8 @@
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
+#include <limits.h>
+#include <errno.h>
#ifdef HAVE_LONG_DOUBLE
# define LDOUBLE long double
@@ -159,17 +166,28 @@
# define MAX(p,q) (((p) >= (q)) ? (p) : (q))
#endif
-static size_t dopr(char *buffer, size_t maxlen, const char *format,
- va_list args_in);
-static void fmtstr(char *buffer, size_t *currlen, size_t maxlen,
- char *value, int flags, int min, int max);
-static void fmtint(char *buffer, size_t *currlen, size_t maxlen,
- LLONG value, int base, int min, int max, int flags);
-static void fmtfp(char *buffer, size_t *currlen, size_t maxlen,
- LDOUBLE fvalue, int min, int max, int flags);
-static void dopr_outch(char *buffer, size_t *currlen, size_t maxlen, char c);
-
-static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args_in)
+#define DOPR_OUTCH(buf, pos, buflen, thechar) \
+ do { \
+ if (pos + 1 >= INT_MAX) { \
+ errno = ERANGE; \
+ return -1; \
+ } \
+ if (pos < buflen) \
+ buf[pos] = thechar; \
+ (pos)++; \
+ } while (0)
+
+static int dopr(char *buffer, size_t maxlen, const char *format,
+ va_list args_in);
+static int fmtstr(char *buffer, size_t *currlen, size_t maxlen,
+ char *value, int flags, int min, int max);
+static int fmtint(char *buffer, size_t *currlen, size_t maxlen,
+ LLONG value, int base, int min, int max, int flags);
+static int fmtfp(char *buffer, size_t *currlen, size_t maxlen,
+ LDOUBLE fvalue, int min, int max, int flags);
+
+static int
+dopr(char *buffer, size_t maxlen, const char *format, va_list args_in)
{
char ch;
LLONG value;
@@ -198,8 +216,8 @@ static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args
case DP_S_DEFAULT:
if (ch == '%')
state = DP_S_FLAGS;
- else
- dopr_outch (buffer, &currlen, maxlen, ch);
+ else
+ DOPR_OUTCH(buffer, currlen, maxlen, ch);
ch = *format++;
break;
case DP_S_FLAGS:
@@ -298,7 +316,9 @@ static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args
value = va_arg (args, LLONG);
else
value = va_arg (args, int);
- fmtint (buffer, &currlen, maxlen, value, 10, min, max, flags);
+ if (fmtint(buffer, &currlen, maxlen,
+ value, 10, min, max, flags) == -1)
+ return -1;
break;
case 'o':
flags |= DP_F_UNSIGNED;
@@ -310,7 +330,9 @@ static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args
value = (long)va_arg (args, unsigned LLONG);
else
value = (long)va_arg (args, unsigned int);
- fmtint (buffer, &currlen, maxlen, value, 8, min, max, flags);
+ if (fmtint(buffer, &currlen, maxlen, value,
+ 8, min, max, flags) == -1)
+ return -1;
break;
case 'u':
flags |= DP_F_UNSIGNED;
@@ -322,7 +344,9 @@ static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args
value = (LLONG)va_arg (args, unsigned LLONG);
else
value = (long)va_arg (args, unsigned int);
- fmtint (buffer, &currlen, maxlen, value, 10, min, max, flags);
+ if (fmtint(buffer, &currlen, maxlen, value,
+ 10, min, max, flags) == -1)
+ return -1;
break;
case 'X':
flags |= DP_F_UP;
@@ -336,15 +360,18 @@ static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args
value = (LLONG)va_arg (args, unsigned LLONG);
else
value = (long)va_arg (args, unsigned int);
- fmtint (buffer, &currlen, maxlen, value, 16, min, max, flags);
+ if (fmtint(buffer, &currlen, maxlen, value,
+ 16, min, max, flags) == -1)
+ return -1;
break;
case 'f':
if (cflags == DP_C_LDOUBLE)
fvalue = va_arg (args, LDOUBLE);
else
fvalue = va_arg (args, double);
- /* um, floating point? */
- fmtfp (buffer, &currlen, maxlen, fvalue, min, max, flags);
+ if (fmtfp(buffer, &currlen, maxlen, fvalue,
+ min, max, flags) == -1)
+ return -1;
break;
case 'E':
flags |= DP_F_UP;
@@ -353,7 +380,9 @@ static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args
fvalue = va_arg (args, LDOUBLE);
else
fvalue = va_arg (args, double);
- fmtfp (buffer, &currlen, maxlen, fvalue, min, max, flags);
+ if (fmtfp(buffer, &currlen, maxlen, fvalue,
+ min, max, flags) == -1)
+ return -1;
break;
case 'G':
flags |= DP_F_UP;
@@ -362,10 +391,13 @@ static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args
fvalue = va_arg (args, LDOUBLE);
else
fvalue = va_arg (args, double);
- fmtfp (buffer, &currlen, maxlen, fvalue, min, max, flags);
+ if (fmtfp(buffer, &currlen, maxlen, fvalue,
+ min, max, flags) == -1)
+ return -1;
break;
case 'c':
- dopr_outch (buffer, &currlen, maxlen, va_arg (args, int));
+ DOPR_OUTCH(buffer, currlen, maxlen,
+ va_arg (args, int));
break;
case 's':
strvalue = va_arg (args, char *);
@@ -374,11 +406,15 @@ static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args
max = strlen(strvalue);
}
if (min > 0 && max >= 0 && min > max) max = min;
- fmtstr (buffer, &currlen, maxlen, strvalue, flags, min, max);
+ if (fmtstr(buffer, &currlen, maxlen,
+ strvalue, flags, min, max) == -1)
+ return -1;
break;
case 'p':
strvalue = va_arg (args, void *);
- fmtint (buffer, &currlen, maxlen, (long) strvalue, 16, min, max, flags);
+ if (fmtint(buffer, &currlen, maxlen,
+ (long) strvalue, 16, min, max, flags) == -1)
+ return -1;
break;
case 'n':
if (cflags == DP_C_SHORT) {
@@ -400,7 +436,7 @@ static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args
}
break;
case '%':
- dopr_outch (buffer, &currlen, maxlen, ch);
+ DOPR_OUTCH(buffer, currlen, maxlen, ch);
break;
case 'w':
/* not supported yet, treat as next char */
@@ -429,11 +465,12 @@ static size_t dopr(char *buffer, size_t maxlen, const char *format, va_list args
buffer[maxlen - 1] = '\0';
}
- return currlen;
+ return currlen < INT_MAX ? (int)currlen : -1;
}
-static void fmtstr(char *buffer, size_t *currlen, size_t maxlen,
- char *value, int flags, int min, int max)
+static int
+fmtstr(char *buffer, size_t *currlen, size_t maxlen,
+ char *value, int flags, int min, int max)
{
int padlen, strln; /* amount to pad */
int cnt = 0;
@@ -453,24 +490,27 @@ static void fmtstr(char *buffer, size_t *currlen, size_t maxlen,
padlen = -padlen; /* Left Justify */
while ((padlen > 0) && (cnt < max)) {
- dopr_outch (buffer, currlen, maxlen, ' ');
+ DOPR_OUTCH(buffer, *currlen, maxlen, ' ');
--padlen;
++cnt;
}
while (*value && (cnt < max)) {
- dopr_outch (buffer, currlen, maxlen, *value++);
+ DOPR_OUTCH(buffer, *currlen, maxlen, *value);
+ *value++;
++cnt;
}
while ((padlen < 0) && (cnt < max)) {
- dopr_outch (buffer, currlen, maxlen, ' ');
+ DOPR_OUTCH(buffer, *currlen, maxlen, ' ');
++padlen;
++cnt;
}
+ return 0;
}
/* Have to handle DP_F_NUM (ie 0x and 0 alternates) */
-static void fmtint(char *buffer, size_t *currlen, size_t maxlen,
+static int
+fmtint(char *buffer, size_t *currlen, size_t maxlen,
LLONG value, int base, int min, int max, int flags)
{
int signvalue = 0;
@@ -527,31 +567,34 @@ static void fmtint(char *buffer, size_t *currlen, size_t maxlen,
/* Spaces */
while (spadlen > 0) {
- dopr_outch (buffer, currlen, maxlen, ' ');
+ DOPR_OUTCH(buffer, *currlen, maxlen, ' ');
--spadlen;
}
/* Sign */
if (signvalue)
- dopr_outch (buffer, currlen, maxlen, signvalue);
+ DOPR_OUTCH(buffer, *currlen, maxlen, signvalue);
/* Zeros */
if (zpadlen > 0) {
while (zpadlen > 0) {
- dopr_outch (buffer, currlen, maxlen, '0');
+ DOPR_OUTCH(buffer, *currlen, maxlen, '0');
--zpadlen;
}
}
/* Digits */
- while (place > 0)
- dopr_outch (buffer, currlen, maxlen, convert[--place]);
+ while (place > 0) {
+ --place;
+ DOPR_OUTCH(buffer, *currlen, maxlen, convert[place]);
+ }
/* Left Justified spaces */
while (spadlen < 0) {
- dopr_outch (buffer, currlen, maxlen, ' ');
+ DOPR_OUTCH(buffer, *currlen, maxlen, ' ');
++spadlen;
}
+ return 0;
}
static LDOUBLE abs_val(LDOUBLE value)
@@ -564,13 +607,13 @@ static LDOUBLE abs_val(LDOUBLE value)
return result;
}
-static LDOUBLE POW10(int exp)
+static LDOUBLE POW10(int val)
{
LDOUBLE result = 1;
- while (exp) {
+ while (val) {
result *= 10;
- exp--;
+ val--;
}
return result;
@@ -604,7 +647,10 @@ static double my_modf(double x0, double *iptr)
}
if (i == 100) {
- /* yikes! the number is beyond what we can handle. What do we do? */
+ /*
+ * yikes! the number is beyond what we can handle.
+ * What do we do?
+ */
(*iptr) = 0;
return 0;
}
@@ -623,8 +669,9 @@ static double my_modf(double x0, double *iptr)
}
-static void fmtfp (char *buffer, size_t *currlen, size_t maxlen,
- LDOUBLE fvalue, int min, int max, int flags)
+static int
+fmtfp (char *buffer, size_t *currlen, size_t maxlen,
+ LDOUBLE fvalue, int min, int max, int flags)
{
int signvalue = 0;
double ufvalue;
@@ -729,24 +776,26 @@ static void fmtfp (char *buffer, size_t *currlen, size_t maxlen,
if ((flags & DP_F_ZERO) && (padlen > 0)) {
if (signvalue) {
- dopr_outch (buffer, currlen, maxlen, signvalue);
+ DOPR_OUTCH(buffer, *currlen, maxlen, signvalue);
--padlen;
signvalue = 0;
}
while (padlen > 0) {
- dopr_outch (buffer, currlen, maxlen, '0');
+ DOPR_OUTCH(buffer, *currlen, maxlen, '0');
--padlen;
}
}
while (padlen > 0) {
- dopr_outch (buffer, currlen, maxlen, ' ');
+ DOPR_OUTCH(buffer, *currlen, maxlen, ' ');
--padlen;
}
if (signvalue)
- dopr_outch (buffer, currlen, maxlen, signvalue);
+ DOPR_OUTCH(buffer, *currlen, maxlen, signvalue);
- while (iplace > 0)
- dopr_outch (buffer, currlen, maxlen, iconvert[--iplace]);
+ while (iplace > 0) {
+ --iplace;
+ DOPR_OUTCH(buffer, *currlen, maxlen, iconvert[iplace]);
+ }
#ifdef DEBUG_SNPRINTF
printf("fmtfp: fplace=%d zpadlen=%d\n", fplace, zpadlen);
@@ -757,41 +806,38 @@ static void fmtfp (char *buffer, size_t *currlen, size_t maxlen,
* char to print out.
*/
if (max > 0) {
- dopr_outch (buffer, currlen, maxlen, '.');
+ DOPR_OUTCH(buffer, *currlen, maxlen, '.');
while (zpadlen > 0) {
- dopr_outch (buffer, currlen, maxlen, '0');
+ DOPR_OUTCH(buffer, *currlen, maxlen, '0');
--zpadlen;
}
- while (fplace > 0)
- dopr_outch (buffer, currlen, maxlen, fconvert[--fplace]);
+ while (fplace > 0) {
+ --fplace;
+ DOPR_OUTCH(buffer, *currlen, maxlen, fconvert[fplace]);
+ }
}
while (padlen < 0) {
- dopr_outch (buffer, currlen, maxlen, ' ');
+ DOPR_OUTCH(buffer, *currlen, maxlen, ' ');
++padlen;
}
-}
-
-static void dopr_outch(char *buffer, size_t *currlen, size_t maxlen, char c)
-{
- if (*currlen < maxlen) {
- buffer[(*currlen)] = c;
- }
- (*currlen)++;
+ return 0;
}
#endif /* !defined(HAVE_SNPRINTF) || !defined(HAVE_VSNPRINTF) */
#if !defined(HAVE_VSNPRINTF)
-int vsnprintf (char *str, size_t count, const char *fmt, va_list args)
+int
+vsnprintf (char *str, size_t count, const char *fmt, va_list args)
{
return dopr(str, count, fmt, args);
}
#endif
#if !defined(HAVE_SNPRINTF)
-int snprintf(char *str, size_t count, SNPRINTF_CONST char *fmt, ...)
+int
+snprintf(char *str, size_t count, SNPRINTF_CONST char *fmt, ...)
{
size_t ret;
va_list ap;
@@ -802,4 +848,3 @@ int snprintf(char *str, size_t count, SNPRINTF_CONST char *fmt, ...)
return ret;
}
#endif
-
diff --git a/Build/source/libs/obsdcompat/config.guess b/Build/source/libs/obsdcompat/config.guess
index 6cc26cd3df1..6d71f752f91 100755
--- a/Build/source/libs/obsdcompat/config.guess
+++ b/Build/source/libs/obsdcompat/config.guess
@@ -1,10 +1,9 @@
#! /bin/sh
# Attempt to guess a canonical system name.
# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
-# 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation,
-# Inc.
+# 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
-timestamp='2007-01-15'
+timestamp='2005-05-27'
# 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
@@ -107,7 +106,7 @@ set_cc_for_build='
trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ;
trap "rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null; exit 1" 1 2 13 15 ;
: ${TMPDIR=/tmp} ;
- { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } ||
+ { tmp=`(umask 077 && mktemp -d -q "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } ||
{ test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir $tmp) ; } ||
{ tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir $tmp) && echo "Warning: creating insecure temp directory" >&2 ; } ||
{ echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } ;
@@ -126,7 +125,7 @@ case $CC_FOR_BUILD,$HOST_CC,$CC in
;;
,,*) CC_FOR_BUILD=$CC ;;
,*,*) CC_FOR_BUILD=$HOST_CC ;;
-esac ; set_cc_for_build= ;'
+esac ;'
# This is needed to find uname on a Pyramid OSx when run in the BSD universe.
# (ghazi@noc.rutgers.edu 1994-08-24)
@@ -161,7 +160,6 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
arm*) machine=arm-unknown ;;
sh3el) machine=shl-unknown ;;
sh3eb) machine=sh-unknown ;;
- sh5el) machine=sh5le-unknown ;;
*) machine=${UNAME_MACHINE_ARCH}-unknown ;;
esac
# The Operating System including object format, if it has switched
@@ -201,18 +199,50 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used.
echo "${machine}-${os}${release}"
exit ;;
+ amd64:OpenBSD:*:*)
+ echo x86_64-unknown-openbsd${UNAME_RELEASE}
+ exit ;;
+ amiga:OpenBSD:*:*)
+ echo m68k-unknown-openbsd${UNAME_RELEASE}
+ exit ;;
+ cats:OpenBSD:*:*)
+ echo arm-unknown-openbsd${UNAME_RELEASE}
+ exit ;;
+ hp300:OpenBSD:*:*)
+ echo m68k-unknown-openbsd${UNAME_RELEASE}
+ exit ;;
+ luna88k:OpenBSD:*:*)
+ echo m88k-unknown-openbsd${UNAME_RELEASE}
+ exit ;;
+ mac68k:OpenBSD:*:*)
+ echo m68k-unknown-openbsd${UNAME_RELEASE}
+ exit ;;
+ macppc:OpenBSD:*:*)
+ echo powerpc-unknown-openbsd${UNAME_RELEASE}
+ exit ;;
+ mvme68k:OpenBSD:*:*)
+ echo m68k-unknown-openbsd${UNAME_RELEASE}
+ exit ;;
+ mvme88k:OpenBSD:*:*)
+ echo m88k-unknown-openbsd${UNAME_RELEASE}
+ exit ;;
+ mvmeppc:OpenBSD:*:*)
+ echo powerpc-unknown-openbsd${UNAME_RELEASE}
+ exit ;;
+ sgi:OpenBSD:*:*)
+ echo mips64-unknown-openbsd${UNAME_RELEASE}
+ exit ;;
+ sun3:OpenBSD:*:*)
+ echo m68k-unknown-openbsd${UNAME_RELEASE}
+ exit ;;
*:OpenBSD:*:*)
- UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'`
- echo ${UNAME_MACHINE_ARCH}-unknown-openbsd${UNAME_RELEASE}
+ echo ${UNAME_MACHINE}-unknown-openbsd${UNAME_RELEASE}
exit ;;
*:ekkoBSD:*:*)
echo ${UNAME_MACHINE}-unknown-ekkobsd${UNAME_RELEASE}
exit ;;
- *:SolidBSD:*:*)
- echo ${UNAME_MACHINE}-unknown-solidbsd${UNAME_RELEASE}
- exit ;;
macppc:MirBSD:*:*)
- echo powerpc-unknown-mirbsd${UNAME_RELEASE}
+ echo powerppc-unknown-mirbsd${UNAME_RELEASE}
exit ;;
*:MirBSD:*:*)
echo ${UNAME_MACHINE}-unknown-mirbsd${UNAME_RELEASE}
@@ -628,7 +658,8 @@ EOF
esac
if [ ${HP_ARCH} = "hppa2.0w" ]
then
- eval $set_cc_for_build
+ # avoid double evaluation of $set_cc_for_build
+ test -n "$CC_FOR_BUILD" || eval $set_cc_for_build
# hppa2.0w-hp-hpux* has a 64-bit kernel and a compiler generating
# 32-bit code. hppa64-hp-hpux* has the same kernel and a compiler
@@ -769,19 +800,12 @@ EOF
echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE}
exit ;;
*:FreeBSD:*:*)
- case ${UNAME_MACHINE} in
- pc98)
- echo i386-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
- amd64)
- echo x86_64-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
- *)
- echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
- esac
+ echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`
exit ;;
i*:CYGWIN*:*)
echo ${UNAME_MACHINE}-pc-cygwin
exit ;;
- *:MINGW*:*)
+ i*:MINGW*:*)
echo ${UNAME_MACHINE}-pc-mingw32
exit ;;
i*:windows32*:*)
@@ -791,11 +815,8 @@ EOF
i*:PW*:*)
echo ${UNAME_MACHINE}-pc-pw32
exit ;;
- x86:Interix*:[3456]*)
- echo i586-pc-interix${UNAME_RELEASE}
- exit ;;
- EM64T:Interix*:[3456]* | authenticamd:Interix*:[3456]*)
- echo x86_64-unknown-interix${UNAME_RELEASE}
+ x86:Interix*:[34]*)
+ echo i586-pc-interix${UNAME_RELEASE}|sed -e 's/\..*//'
exit ;;
[345]86:Windows_95:* | [345]86:Windows_98:* | [345]86:Windows_NT:*)
echo i${UNAME_MACHINE}-pc-mks
@@ -809,7 +830,7 @@ EOF
i*:UWIN*:*)
echo ${UNAME_MACHINE}-pc-uwin
exit ;;
- amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*)
+ amd64:CYGWIN*:*:*)
echo x86_64-unknown-cygwin
exit ;;
p*:CYGWIN*:*)
@@ -832,9 +853,6 @@ EOF
arm*:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-gnu
exit ;;
- avr32*:Linux:*:*)
- echo ${UNAME_MACHINE}-unknown-linux-gnu
- exit ;;
cris:Linux:*:*)
echo cris-axis-linux-gnu
exit ;;
@@ -869,11 +887,7 @@ EOF
#endif
#endif
EOF
- eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n '
- /^CPU/{
- s: ::g
- p
- }'`"
+ eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^CPU=`
test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; }
;;
mips64:Linux:*:*)
@@ -892,16 +906,9 @@ EOF
#endif
#endif
EOF
- eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n '
- /^CPU/{
- s: ::g
- p
- }'`"
+ eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^CPU=`
test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; }
;;
- or32:Linux:*:*)
- echo or32-unknown-linux-gnu
- exit ;;
ppc:Linux:*:*)
echo powerpc-unknown-linux-gnu
exit ;;
@@ -945,15 +952,9 @@ EOF
sparc:Linux:*:* | sparc64:Linux:*:*)
echo ${UNAME_MACHINE}-unknown-linux-gnu
exit ;;
- vax:Linux:*:*)
- echo ${UNAME_MACHINE}-dec-linux-gnu
- exit ;;
x86_64:Linux:*:*)
echo x86_64-unknown-linux-gnu
exit ;;
- xtensa:Linux:*:*)
- echo xtensa-unknown-linux-gnu
- exit ;;
i*86:Linux:*:*)
# The BFD linker knows what the default object file format is, so
# first see if it will tell us. cd to the root directory to prevent
@@ -996,7 +997,7 @@ EOF
LIBC=gnulibc1
# endif
#else
- #if defined(__INTEL_COMPILER) || defined(__PGI) || defined(__SUNPRO_C) || defined(__SUNPRO_CC)
+ #ifdef __INTEL_COMPILER
LIBC=gnu
#else
LIBC=gnuaout
@@ -1006,11 +1007,7 @@ EOF
LIBC=dietlibc
#endif
EOF
- eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n '
- /^LIBC/{
- s: ::g
- p
- }'`"
+ eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^LIBC=`
test x"${LIBC}" != x && {
echo "${UNAME_MACHINE}-pc-linux-${LIBC}"
exit
@@ -1212,15 +1209,6 @@ EOF
SX-6:SUPER-UX:*:*)
echo sx6-nec-superux${UNAME_RELEASE}
exit ;;
- SX-7:SUPER-UX:*:*)
- echo sx7-nec-superux${UNAME_RELEASE}
- exit ;;
- SX-8:SUPER-UX:*:*)
- echo sx8-nec-superux${UNAME_RELEASE}
- exit ;;
- SX-8R:SUPER-UX:*:*)
- echo sx8r-nec-superux${UNAME_RELEASE}
- exit ;;
Power*:Rhapsody:*:*)
echo powerpc-apple-rhapsody${UNAME_RELEASE}
exit ;;
@@ -1230,6 +1218,7 @@ EOF
*:Darwin:*:*)
UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown
case $UNAME_PROCESSOR in
+ *86) UNAME_PROCESSOR=i686 ;;
unknown) UNAME_PROCESSOR=powerpc ;;
esac
echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE}
@@ -1308,9 +1297,6 @@ EOF
i*86:skyos:*:*)
echo ${UNAME_MACHINE}-pc-skyos`echo ${UNAME_RELEASE}` | sed -e 's/ .*$//'
exit ;;
- i*86:rdos:*:*)
- echo ${UNAME_MACHINE}-pc-rdos
- exit ;;
esac
#echo '(No uname command or uname output not recognized.)' 1>&2
diff --git a/Build/source/libs/obsdcompat/config.sub b/Build/source/libs/obsdcompat/config.sub
index 5defff65a6e..1d9fecf3395 100755
--- a/Build/source/libs/obsdcompat/config.sub
+++ b/Build/source/libs/obsdcompat/config.sub
@@ -4,7 +4,7 @@
# 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation,
# Inc.
-timestamp='2007-01-18'
+timestamp='2007-01-04'
# This file is (in principle) common to ALL GNU software.
# The presence of a machine in this file suggests that SOME GNU software
@@ -250,7 +250,7 @@ case $basic_machine in
| i370 | i860 | i960 | ia64 \
| ip2k | iq2000 \
| m32c | m32r | m32rle | m68000 | m68k | m88k \
- | maxq | mb | microblaze | mcore | mep \
+ | maxq | mb | microblaze | mcore \
| mips | mipsbe | mipseb | mipsel | mipsle \
| mips16 \
| mips64 | mips64el \
@@ -1417,9 +1417,6 @@ case $basic_machine in
m68*-cisco)
os=-aout
;;
- mep-*)
- os=-elf
- ;;
mips*-cisco)
os=-elf
;;
diff --git a/Build/source/libs/xpdf/ANNOUNCE b/Build/source/libs/xpdf/ANNOUNCE
index 3f12a2602f8..1184040894f 100644
--- a/Build/source/libs/xpdf/ANNOUNCE
+++ b/Build/source/libs/xpdf/ANNOUNCE
@@ -1,4 +1,4 @@
-Subject: ANNOUNCE: Xpdf 3.01 - a PDF viewer for X
+Subject: ANNOUNCE: Xpdf 3.02 - a PDF viewer for X
Glyph & Cog, LLC is pleased to announce a new version of Xpdf, the
@@ -11,12 +11,11 @@ components (pdftops, pdftotext, etc.) also run on Win32 systems and
should run on pretty much any system with a decent C++ compiler.
Major changes:
-* Added the continuous view mode, including the '-cont' switch and the
- 'continuousView' config file option.
-* At high zoom levels, don't rasterize the entire page - this avoids
- problems running out of memory.
-* Added "search backward" and "match case" options to the find dialog.
-* Support explicitly masked images and soft masked images.
+* Anti-aliased vector graphics, including stroke adjustment.
+* Support for PDF 1.6 and PDF 1.7, including AES decryption and
+ OpenType fonts.
+* User-configurable key/mouse bindings.
+* Improved full-screen mode, with the ability to toggle on the fly.
See the `CHANGES' file for a complete list of changes.
diff --git a/Build/source/libs/xpdf/CHANGES b/Build/source/libs/xpdf/CHANGES
index 360dd25a105..0378f0da537 100644
--- a/Build/source/libs/xpdf/CHANGES
+++ b/Build/source/libs/xpdf/CHANGES
@@ -1577,7 +1577,8 @@ Minor changes to GlobalParams.h and JPXStream.h because some compilers
Xpdf now complains about a negative page number.
Changed GString::cmp and GString::cmpN to correctly handle '\0' chars
in the middle of strings.
-Corrected the handling of the 'extend' parameters in radial shadings.
+Fixed the radial shading code; corrected the handling of the 'extend'
+ parameters.
Added the gmallocn and greallocn functions.
Fixed a bug in the TIFF image component predictor which shows up with
components that are not 1 or 8 bits wide.
@@ -1626,3 +1627,136 @@ When converting a Type 1C glyph to a Type 1 glyph, insert closepath
Check for a sane 'loca' table in TrueType fonts (FoFiTrueType::parse).
Fix PSOutputDev to correctly handle the case of an empty name in a
font encoding.
+
+3.02 (2007-feb-27)
+------------------
+Added anti-aliasing for vector graphics; added the vectorAntialias
+ xpdfrc option; added the "-aaVector" switch to xpdf and pdftoppm.
+Implemented stroke adjustment (always enabled by default, ignoring the
+ SA parameter, to match Adobe's behavior), and added the strokeAdjust
+ xpdfrc command.
+Support PDF 1.6 and PDF 1.7.
+Added support for AES decryption.
+Added support for OpenType fonts (only tested with 8-bit CFF data so
+ far).
+Added user-configurable key/mouse bindings - the bind/unbind xpdfrc
+ commands.
+Cleaned up the full-screen mode code and added the ability to toggle
+ it on the fly (the default key binding is alt-f).
+Pdfimages with the -j option now writes JPEG files for 1-component
+ (grayscale) DCT images, in addition to 3-component (RGB) images.
+Fixed bugs in handling sampled (type 0) functions with 32-bit
+ samples.
+Fixed some things to support DeviceN color spaces with up to 32
+ colorants.
+Pdftops now constructs the %%Creator and %%Title DSC comments from the
+ relevant information in the PDF Info dictionary.
+Tweak the TrueType font encoding deciphering algorithm.
+Added the "mapUnkownCharNames" xpdfrc option.
+Fix a bug (that only showed up with certain window managers) in the
+ intermediate resize event optimization. [Thanks to Michael Rogers.]
+Check for a broken/missing embedded font (this was causing xpdf to
+ crash).
+Added support for transfer functions in PostScript output.
+Be a bit more tolerant of Link destinations that contain null values
+ for positioning parameters.
+Use ordered dot dithering instead of clustered dot dithering at
+ resolutions below 300 dpi (for monochrome output).
+Fixed security holes (bounds checking issues) in several places.
+Don't bother creating a SplashFont (allocating memory) for fonts that
+ are only used for hidden text - this avoids problems with fonts of
+ unreasonably large sizes.
+Clipping in TextOutputDev was off for characters on the left edge of
+ the page.
+The scn and SCN operators weren't correctly handling colors with more
+ than four components.
+FoFiType1::writeEncoded wasn't always correctly finding the end of the
+ encoding.
+Use the ColorTransform parameter in the DCTDecode stream dictionary.
+Type 3 fonts are allowed to have a bbox of [0 0 0 0], which means
+ "unspecified" -- don't issue error messages in that case.
+Perform the transform (to device space) in Splash instead of in
+ SplashOutputDev -- this is needed to correctly handle round joins
+ and caps on stroked paths.
+PSOutputDev now rasterizes any pages that use transparency.
+Limit the crop, bleed, trim, and art boxes to the edges of the media
+ box (per the PDF spec).
+Change GString to increase the allocation increment by powers of two.
+Handle whitespace in hex strings in CMap files/streams.
+Use strings instead of names for separation colorant names in
+ PSOutputDev.
+For explicitly masked images where the mask is higher resolution than
+ the image, use the soft mask code.
+Avoid problems with very large x-steps in the PostScript output for
+ tiling pattern fills.
+Avoid a divide-by-zero in stitching functions which have a subfunction
+ with empty bounds.
+Honor the "Hidden", "NoView", and "Print" flags on annotations.
+Rewrote the pixel rendering code in Splash to use a single set of
+ pixel pipeline functions.
+Added support for transparency groups and soft masks.
+Fixed the transparency blend functions to match the addendum published
+ by Adobe.
+Changed Splash/SplashBitmap to store alpha in a separate plane.
+Setting the color space now selects the correct default color for that
+ color space.
+Remove the mutex lock from GlobalParams::getErrQuiet() to avoid a
+ deadlock when parseCIDToUnicode() or parseUnicodeToUnicode() calls
+ it from inside a locked section.
+Added error checking (on the argument count) in the sc/SC/scn/SCN
+ operators.
+Skip over notdef glyphs in TrueType fonts (which sometimes get drawn
+ as little boxes), to match Adobe's behavior.
+Painting operations in a Separation color space with the "None"
+ colorant or a DeviceN color space with all colorants set to "None"
+ never mark the page.
+Fixed an obscure bug in the JPX decoder - it wasn't reading the extra
+ stuffing byte in the case where the last byte of a packet header was
+ 0xff.
+Change the TrueType font parser (FoFiTrueType) to change the glyph
+ count rather than report an error if the 'loca' table is too small.
+Fixed a couple of bugs in the JBIG2 decoder.
+Added stochastic clustered dot dithering.
+Added the screenType, screenSize, screenDotRadius, screenGamma,
+ screenBlackThreshold, and screenWhiteThreshold xpdfrc settings.
+PSOutputDev now correctly handles invalid Type 3 charprocs which don't
+ start with a d0 or d1 operator
+FreeType 2.2.x support - get rid of the FT_INTERNAL_OBJECTS_H include,
+ and add some 'const' declarations.
+Handle PDFDocEncoding in Info dictionary strings.
+Tweak the xref repair code - ignore whitespace at the start of lines
+ when looking for objects.
+Added the "-exec" switch to xpdf.
+Removed the xpdf.viKeys X resource.
+Changed the color key / explicit masked image code in PSOutputDev to
+ generate better PS code, including a Level 3 option.
+Tweaked the DEBUG_MEM code for performance.
+Move the JBIG2 global stream reading code into reset() instead of the
+ constructor - this way, pdftotext doesn't end up reading the global
+ stream.
+Added the "-preload" option to pdftops and the psPreload xpdfrc
+ command.
+Added the "zoom to selection" command (on the popup menu).
+Fix a bug (in xpdf/pdftoppm/pdftops) with tiling patterns whose bbox
+ size is different from their xStep/yStep.
+Implemented stroke with pattern color spaces.
+Following a link to a page whose CropBox was different from the
+ MediaBox was resulting in an incorrect scroll position.
+Parse truncated date strings from the Info dictionary correctly.
+Change FoFiType1 to handle Type 1 fonts with two /Encoding keys.
+Extend the PSOutputDev shaded fill code to handle DeviceCMYK shaded
+ fills in level2sep and level3sep modes.
+Detect infinite loops in the Page tree.
+Optimized the ASCII85Encoder code.
+Tweaked the text extractor to do a better job of lining up rows of
+ text.
+Leave images compressed (or re-compress them with RLE) in PostScript
+ output when setting up images for forms and Type 3 fonts (or with
+ -preload).
+Extend FoFiType1 to handle Type 1 fonts with octal character codes in
+ their encodings.
+Use a custom string formatter to avoid problems with locale-based decimal
+ formatting (commas instead of periods) in PS output.
+Allow comments in PostScript-type functions.
+Change the TrueType font parser (FoFiTrueType) to delete glyf table
+ entries that are too short.
diff --git a/Build/source/libs/xpdf/INSTALL b/Build/source/libs/xpdf/INSTALL
index 10036518c6f..6c6db871129 100644
--- a/Build/source/libs/xpdf/INSTALL
+++ b/Build/source/libs/xpdf/INSTALL
@@ -1,11 +1,11 @@
Xpdf
====
-version 3.01
-2005-aug-17
+version 3.02
+2007-feb-27
The Xpdf software and documentation are
-copyright 1996-2005 Glyph & Cog, LLC.
+copyright 1996-2007 Glyph & Cog, LLC.
Email: derekn@foolabs.com
WWW: http://www.foolabs.com/xpdf/
diff --git a/Build/source/libs/xpdf/README b/Build/source/libs/xpdf/README
index 5fb5b104c31..71fd62e319d 100644
--- a/Build/source/libs/xpdf/README
+++ b/Build/source/libs/xpdf/README
@@ -1,17 +1,17 @@
Xpdf
====
-version 3.01
-2005-aug-17
+version 3.02
+2007-feb-27
The Xpdf software and documentation are
-copyright 1996-2005 Glyph & Cog, LLC.
+copyright 1996-2007 Glyph & Cog, LLC.
Email: derekn@foolabs.com
WWW: http://www.foolabs.com/xpdf/
The PDF data structures, operators, and specification are
-copyright 1985-2004 Adobe Systems Inc.
+copyright 1985-2006 Adobe Systems Inc.
What is Xpdf?
@@ -204,10 +204,15 @@ pdftex project:
References
----------
-Adobe Systems Inc., _PDF Reference: Adobe Portable Document Format
-Version 1.6_.
-http://partners.adobe.com/public/developer/pdf/index_reference.html
-[The manual for PDF version 1.6.]
+Adobe Systems Inc., _PDF Reference, sixth edition: Adobe Portable
+Document Format version 1.7_.
+http://www.adobe.com/devnet/pdf/pdf_reference.html
+[The manual for PDF version 1.7.]
+
+Adobe Systems Inc., "Errata for the PDF Reference, sixth edition,
+version 1.7", October 16, 2006.
+http://www.adobe.com/devnet/pdf/pdf_reference.html
+[The errata for the PDF 1.7 spec.]
Adobe Systems Inc., _PostScript Language Reference_, 3rd ed.
Addison-Wesley, 1999, ISBN 0-201-37922-8.
@@ -262,6 +267,10 @@ http://partners.adobe.com/asn/developer/type/corporateuse.txt
http://partners.adobe.com/asn/developer/type/zapfdingbats.txt
[Mappings between character names to Unicode.]
+Adobe Systems Inc., OpenType Specification v. 1.4.
+http://partners.adobe.com/public/developer/opentype/index_spec.html
+[The OpenType font format spec.]
+
Aldus Corp., _OPI: Open Prepress Interface Specification 1.3_. 1993.
http://partners.adobe.com/asn/developer/PDFS/TN/OPI_13.pdf
@@ -271,7 +280,7 @@ ftp://idea.sec.dsi.unimi.it/pub/crypt/code/rc4.tar.gz
[This is the algorithm used to encrypt PDF files.]
T. Boutell, et al., "PNG (Portable Network Graphics) Specification,
-Version 1.0. RFC 2083.
+Version 1.0". RFC 2083.
[PDF uses the PNG filter algorithms.]
CCITT, "Information Technology - Digital Compression and Coding of
@@ -296,6 +305,15 @@ version 1.3". RFC 1951.
[The definition of the compression algorithm used in FlateDecode
streams.]
+Morris Dworkin, "Recommendation for Block Cipher Modes of Operation",
+National Institute of Standards, NIST Special Publication 800-38A,
+2001.
+[The cipher block chaining (CBC) mode used with AES in PDF files.]
+
+Federal Information Processing Standards Publication 197 (FIPS PUBS
+197), "Advanced Encryption Standard (AES)", November 26, 2001.
+[AES encryption, used in PDF 1.6.]
+
Jim Flowers, "X Logical Font Description Conventions", Version 1.5, X
Consortium Standard, X Version 11, Release 6.1.
ftp://ftp.x.org/pub/R6.1/xc/doc/hardcopy/XLFD/xlfd.PS.Z
@@ -333,6 +351,10 @@ http://www.itu.int/
[The official Group 3 and 4 fax standards - used by the CCITTFaxDecode
stream, as well as the JBIG2Decode stream.]
+B. Kaliski, "PKCS #5: Password-Based Cryptography Specification,
+Version 2.0". RFC 2898.
+[Defines the padding scheme used with AES encryption in PDF files.]
+
Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz, "Practical
Fast 1-D DCT Algorithms with 11 Multiplications". IEEE Intl. Conf. on
Acoustics, Speech & Signal Processing, 1989, 988-991.
@@ -342,10 +364,11 @@ Microsoft, _TrueType 1.0 Font Files_, rev. 1.66. 1995.
http://www.microsoft.com/typography/tt/tt.htm
[The TrueType font spec (in MS Word format, naturally).]
-Thai Industrial Standard, "Standard for Thai Character Codes for
-Computers", TIS-620-2533 (1990).
-http://www.nectec.or.th/it-standards/std620/std620.htm
-[The TIS-620 Thai encoding.]
+V. Ostromoukhov, R.D. Hersch, "Stochastic Clustered-Dot Dithering",
+Conf. Color Imaging: Device-Independent Color, Color Hardcopy, and
+Graphic Arts IV, 1999, SPIE Vol. 3648, 496-505.
+http://diwww.epfl.ch/w3lsp/publications/colour/scd.html
+[The stochastic dithering algorithm used in Xpdf.]
P. Peterlin, "ISO 8859-2 (Latin 2) Resources".
http://sizif.mf.uni-lj.si/linux/cee/iso8859-2.html
@@ -359,6 +382,11 @@ http://www.inforamp.net/~poynton/ColorFAQ.html
R. Rivest, "The MD5 Message-Digest Algorithm". RFC 1321.
[MD5 is used in PDF document encryption.]
+Thai Industrial Standard, "Standard for Thai Character Codes for
+Computers", TIS-620-2533 (1990).
+http://www.nectec.or.th/it-standards/std620/std620.htm
+[The TIS-620 Thai encoding.]
+
Unicode Consortium, "Unicode Home Page".
http://www.unicode.org/
[Online copy of the Unicode spec.]
diff --git a/Build/source/libs/xpdf/aconf-win32.h b/Build/source/libs/xpdf/aconf-win32.h
index 60509334391..0bdc7636623 100644
--- a/Build/source/libs/xpdf/aconf-win32.h
+++ b/Build/source/libs/xpdf/aconf-win32.h
@@ -7,6 +7,8 @@
#ifndef ACONF_H
#define ACONF_H
+#include <aconf2.h>
+
/*
* Use A4 paper size instead of Letter for PostScript output.
*/
@@ -28,6 +30,21 @@
#define MULTITHREADED 1
/*
+ * Enable C++ exceptions.
+ */
+#define USE_EXCEPTIONS 1
+
+/*
+ * Enable word list support.
+ */
+#undef TEXTOUT_WORD_LIST
+
+/*
+ * Use fixed point (instead of floating point) arithmetic.
+ */
+#undef USE_FIXEDPOINT
+
+/*
* Directory with the Xpdf app-defaults file.
*/
#undef APPDEFDIR
@@ -50,8 +67,14 @@
#undef HAVE_BSTRING_H
#undef HAVE_POPEN
#undef HAVE_MKSTEMP
+#undef HAVE_MKSTEMPS
#undef SELECT_TAKES_INT
+#undef HAVE_FSEEKO
#undef HAVE_FSEEK64
+#undef _FILE_OFFSET_BITS
+#undef _LARGE_FILES
+#undef _LARGEFILE_SOURCE
+#undef HAVE_XTAPPSETEXITFLAG
/*
* This is defined if using libXpm.
@@ -79,4 +102,19 @@
*/
#undef HAVE_PAPER_H
+/*
+ * Enable support for loading plugins.
+ */
+#undef ENABLE_PLUGINS
+
+/*
+ * Defined if the Splash library is avaiable.
+ */
+#undef HAVE_SPLASH
+
+/*
+ * Enable support for CMYK output.
+ */
+#undef SPLASH_CMYK
+
#endif
diff --git a/Build/source/libs/xpdf/aconf.h.in b/Build/source/libs/xpdf/aconf.h.in
index b7928fb3fc2..b6c63518f53 100644
--- a/Build/source/libs/xpdf/aconf.h.in
+++ b/Build/source/libs/xpdf/aconf.h.in
@@ -30,11 +30,21 @@
#undef MULTITHREADED
/*
+ * Enable C++ exceptions.
+ */
+#undef USE_EXCEPTIONS
+
+/*
* Enable word list support.
*/
#undef TEXTOUT_WORD_LIST
/*
+ * Use fixed point (instead of floating point) arithmetic.
+ */
+#undef USE_FIXEDPOINT
+
+/*
* Directory with the Xpdf app-defaults file.
*/
#undef APPDEFDIR
@@ -87,4 +97,19 @@
*/
#undef HAVE_PAPER_H
+/*
+ * Enable support for loading plugins.
+ */
+#undef ENABLE_PLUGINS
+
+/*
+ * Defined if the Splash library is avaiable.
+ */
+#undef HAVE_SPLASH
+
+/*
+ * Enable support for CMYK output.
+ */
+#undef SPLASH_CMYK
+
#endif
diff --git a/Build/source/libs/xpdf/dj_make.bat b/Build/source/libs/xpdf/dj_make.bat
index 37f360359df..d01b7928c63 100644
--- a/Build/source/libs/xpdf/dj_make.bat
+++ b/Build/source/libs/xpdf/dj_make.bat
@@ -1,5 +1,5 @@
set CC=gcc
-set CFLAGS=-g -O2 -I.. -I..\goo
+set CFLAGS=-g -O2 -I.. -I..\fofi -I..\goo
set CXX=gpp
set CXXFLAGS=%CFLAGS%
set LIBPROG=ar
@@ -10,9 +10,9 @@ cd goo
%CXX% %CXXFLAGS% -c GHash.cc
%CXX% %CXXFLAGS% -c GList.cc
%CXX% %CXXFLAGS% -c GString.cc
+%CXX% %CXXFLAGS% -c gmem.cc
%CXX% %CXXFLAGS% -c gmempp.cc
%CXX% %CXXFLAGS% -c gfile.cc
-%CC% %CFLAGS% -c gmem.c
%CC% %CFLAGS% -c parseargs.c
del libGoo.a
%LIBPROG% -rc libGoo.a GHash.o GList.o GString.o gmempp.o gfile.o gmem.o parseargs.o
@@ -59,6 +59,7 @@ del *.o
%CXX% %CXXFLAGS% -c PSTokenizer.cc
%CXX% %CXXFLAGS% -c Page.cc
%CXX% %CXXFLAGS% -c Parser.cc
+%CXX% %CXXFLAGS% -c SecurityHandler.cc
%CXX% %CXXFLAGS% -c Stream.cc
%CXX% %CXXFLAGS% -c TextOutputDev.cc
%CXX% %CXXFLAGS% -c UnicodeMap.cc
@@ -67,16 +68,14 @@ del *.o
del libxpdf.a
%LIBPROG% -rc libxpdf.a *.o
-%CXX% %CXXFLAGS% -o pdftops.exe pdftops.cc libxpdf.a ..\goo\libGoo.a
+%CXX% %CXXFLAGS% -o pdftops.exe pdftops.cc libxpdf.a ..\fofi\libfofi.a ..\goo\libGoo.a
-%CXX% %CXXFLAGS% -o pdftotext.exe pdftotext.cc libxpdf.a ..\goo\libGoo.a
+%CXX% %CXXFLAGS% -o pdftotext.exe pdftotext.cc libxpdf.a ..\fofi\libfofi.a ..\goo\libGoo.a
-%CXX% %CXXFLAGS% -o pdfinfo.exe pdfinfo.cc libxpdf.a ..\goo\libGoo.a
+%CXX% %CXXFLAGS% -o pdfinfo.exe pdfinfo.cc libxpdf.a ..\fofi\libfofi.a ..\goo\libGoo.a
-%CXX% %CXXFLAGS% -o pdffonts.exe pdffonts.cc libxpdf.a ..\goo\libGoo.a
+%CXX% %CXXFLAGS% -o pdffonts.exe pdffonts.cc libxpdf.a ..\fofi\libfofi.a ..\goo\libGoo.a
-%CXX% %CXXFLAGS% -o pdfimages.exe pdfimages.cc libxpdf.a ..\goo\libGoo.a
-
-%CXX% %CXXFLAGS% -o pdftoppm.exe pdftoppm.cc libxpdf.a ..\goo\libGoo.a
+%CXX% %CXXFLAGS% -o pdfimages.exe pdfimages.cc libxpdf.a ..\fofi\libfofi.a ..\goo\libGoo.a
cd ..
diff --git a/Build/source/libs/xpdf/fofi/FoFiTrueType.cc b/Build/source/libs/xpdf/fofi/FoFiTrueType.cc
index 46b61ec3979..f8a1aa3478e 100644
--- a/Build/source/libs/xpdf/fofi/FoFiTrueType.cc
+++ b/Build/source/libs/xpdf/fofi/FoFiTrueType.cc
@@ -18,6 +18,7 @@
#include "gmem.h"
#include "GString.h"
#include "GHash.h"
+#include "FoFiType1C.h"
#include "FoFiTrueType.h"
//
@@ -108,8 +109,11 @@ struct TrueTypeLoca {
#define cmapTag 0x636d6170
#define glyfTag 0x676c7966
#define headTag 0x68656164
+#define hheaTag 0x68686561
+#define hmtxTag 0x686d7478
#define locaTag 0x6c6f6361
#define nameTag 0x6e616d65
+#define os2Tag 0x4f532f32
#define postTag 0x706f7374
static int cmpTrueTypeLocaOffset(const void *p1, const void *p2) {
@@ -391,6 +395,28 @@ int FoFiTrueType::mapNameToGID(char *name) {
return nameToGID->lookupInt(name);
}
+Gushort *FoFiTrueType::getCIDToGIDMap(int *nCIDs) {
+ FoFiType1C *ff;
+ Gushort *map;
+ int i;
+
+ *nCIDs = 0;
+ if (!openTypeCFF) {
+ return NULL;
+ }
+ i = seekTable("CFF ");
+ if (!checkRegion(tables[i].offset, tables[i].len)) {
+ return NULL;
+ }
+ if (!(ff = FoFiType1C::make((char *)file + tables[i].offset,
+ tables[i].len))) {
+ return NULL;
+ }
+ map = ff->getCIDToGIDMap(nCIDs);
+ delete ff;
+ return map;
+}
+
int FoFiTrueType::getEmbeddingRights() {
int i, fsType;
GBool ok;
@@ -419,13 +445,19 @@ void FoFiTrueType::convertToType42(char *psName, char **encoding,
Gushort *codeToGID,
FoFiOutputFunc outputFunc,
void *outputStream) {
- char buf[512];
+ GString *buf;
GBool ok;
+ if (openTypeCFF) {
+ return;
+ }
+
// write the header
ok = gTrue;
- sprintf(buf, "%%!PS-TrueTypeFont-%g\n", (double)getS32BE(0, &ok) / 65536.0);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ buf = GString::format("%!PS-TrueTypeFont-{0:2g}\n",
+ (double)getS32BE(0, &ok) / 65536.0);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
// begin the font dictionary
(*outputFunc)(outputStream, "10 dict begin\n", 14);
@@ -434,9 +466,10 @@ void FoFiTrueType::convertToType42(char *psName, char **encoding,
(*outputFunc)(outputStream, " def\n", 5);
(*outputFunc)(outputStream, "/FontType 42 def\n", 17);
(*outputFunc)(outputStream, "/FontMatrix [1 0 0 1 0 0] def\n", 30);
- sprintf(buf, "/FontBBox [%d %d %d %d] def\n",
- bbox[0], bbox[1], bbox[2], bbox[3]);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ buf = GString::format("/FontBBox [{0:d} {1:d} {2:d} {3:d}] def\n",
+ bbox[0], bbox[1], bbox[2], bbox[3]);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
(*outputFunc)(outputStream, "/PaintType 0 def\n", 17);
// write the guts of the dictionary
@@ -448,20 +481,47 @@ void FoFiTrueType::convertToType42(char *psName, char **encoding,
(*outputFunc)(outputStream, "FontName currentdict end definefont pop\n", 40);
}
+void FoFiTrueType::convertToType1(char *psName, char **newEncoding,
+ GBool ascii, FoFiOutputFunc outputFunc,
+ void *outputStream) {
+ FoFiType1C *ff;
+ int i;
+
+ if (!openTypeCFF) {
+ return;
+ }
+ i = seekTable("CFF ");
+ if (!checkRegion(tables[i].offset, tables[i].len)) {
+ return;
+ }
+ if (!(ff = FoFiType1C::make((char *)file + tables[i].offset,
+ tables[i].len))) {
+ return;
+ }
+ ff->convertToType1(psName, newEncoding, ascii, outputFunc, outputStream);
+ delete ff;
+}
+
void FoFiTrueType::convertToCIDType2(char *psName,
Gushort *cidMap, int nCIDs,
GBool needVerticalMetrics,
FoFiOutputFunc outputFunc,
void *outputStream) {
- char buf[512];
+ GString *buf;
Gushort cid;
GBool ok;
int i, j, k;
+ if (openTypeCFF) {
+ return;
+ }
+
// write the header
ok = gTrue;
- sprintf(buf, "%%!PS-TrueTypeFont-%g\n", (double)getS32BE(0, &ok) / 65536.0);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ buf = GString::format("%!PS-TrueTypeFont-{0:2g}\n",
+ (double)getS32BE(0, &ok) / 65536.0);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
// begin the font dictionary
(*outputFunc)(outputStream, "20 dict begin\n", 14);
@@ -477,8 +537,9 @@ void FoFiTrueType::convertToCIDType2(char *psName,
(*outputFunc)(outputStream, " end def\n", 10);
(*outputFunc)(outputStream, "/GDBytes 2 def\n", 15);
if (cidMap) {
- sprintf(buf, "/CIDCount %d def\n", nCIDs);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ buf = GString::format("/CIDCount {0:d} def\n", nCIDs);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
if (nCIDs > 32767) {
(*outputFunc)(outputStream, "/CIDMap [", 9);
for (i = 0; i < nCIDs; i += 32768 - 16) {
@@ -487,8 +548,10 @@ void FoFiTrueType::convertToCIDType2(char *psName,
(*outputFunc)(outputStream, " ", 2);
for (k = 0; k < 16 && i+j+k < nCIDs; ++k) {
cid = cidMap[i+j+k];
- sprintf(buf, "%02x%02x", (cid >> 8) & 0xff, cid & 0xff);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ buf = GString::format("{0:02x}{1:02x}",
+ (cid >> 8) & 0xff, cid & 0xff);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
}
(*outputFunc)(outputStream, "\n", 1);
}
@@ -502,8 +565,10 @@ void FoFiTrueType::convertToCIDType2(char *psName,
(*outputFunc)(outputStream, " ", 2);
for (j = 0; j < 16 && i+j < nCIDs; ++j) {
cid = cidMap[i+j];
- sprintf(buf, "%02x%02x", (cid >> 8) & 0xff, cid & 0xff);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ buf = GString::format("{0:02x}{1:02x}",
+ (cid >> 8) & 0xff, cid & 0xff);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
}
(*outputFunc)(outputStream, "\n", 1);
}
@@ -511,27 +576,34 @@ void FoFiTrueType::convertToCIDType2(char *psName,
}
} else {
// direct mapping - just fill the string(s) with s[i]=i
- sprintf(buf, "/CIDCount %d def\n", nGlyphs);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ buf = GString::format("/CIDCount {0:d} def\n", nGlyphs);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
if (nGlyphs > 32767) {
(*outputFunc)(outputStream, "/CIDMap [\n", 10);
for (i = 0; i < nGlyphs; i += 32767) {
j = nGlyphs - i < 32767 ? nGlyphs - i : 32767;
- sprintf(buf, " %d string 0 1 %d {\n", 2 * j, j - 1);
- (*outputFunc)(outputStream, buf, strlen(buf));
- sprintf(buf, " 2 copy dup 2 mul exch %d add -8 bitshift put\n", i);
- (*outputFunc)(outputStream, buf, strlen(buf));
- sprintf(buf, " 1 index exch dup 2 mul 1 add exch %d add"
- " 255 and put\n", i);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ buf = GString::format(" {0:d} string 0 1 {1:d} {{\n", 2 * j, j - 1);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
+ buf = GString::format(" 2 copy dup 2 mul exch {0:d} add -8 bitshift put\n",
+ i);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
+ buf = GString::format(" 1 index exch dup 2 mul 1 add exch {0:d} add"
+ " 255 and put\n", i);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
(*outputFunc)(outputStream, " } for\n", 8);
}
(*outputFunc)(outputStream, "] def\n", 6);
} else {
- sprintf(buf, "/CIDMap %d string\n", 2 * nGlyphs);
- (*outputFunc)(outputStream, buf, strlen(buf));
- sprintf(buf, " 0 1 %d {\n", nGlyphs - 1);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ buf = GString::format("/CIDMap {0:d} string\n", 2 * nGlyphs);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
+ buf = GString::format(" 0 1 {0:d} {{\n", nGlyphs - 1);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
(*outputFunc)(outputStream,
" 2 copy dup 2 mul exch -8 bitshift put\n", 42);
(*outputFunc)(outputStream,
@@ -541,9 +613,10 @@ void FoFiTrueType::convertToCIDType2(char *psName,
}
}
(*outputFunc)(outputStream, "/FontMatrix [1 0 0 1 0 0] def\n", 30);
- sprintf(buf, "/FontBBox [%d %d %d %d] def\n",
- bbox[0], bbox[1], bbox[2], bbox[3]);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ buf = GString::format("/FontBBox [{0:d} {1:d} {2:d} {3:d}] def\n",
+ bbox[0], bbox[1], bbox[2], bbox[3]);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
(*outputFunc)(outputStream, "/PaintType 0 def\n", 17);
(*outputFunc)(outputStream, "/Encoding [] readonly def\n", 26);
(*outputFunc)(outputStream, "/CharStrings 1 dict dup begin\n", 30);
@@ -559,14 +632,39 @@ void FoFiTrueType::convertToCIDType2(char *psName,
56);
}
+void FoFiTrueType::convertToCIDType0(char *psName,
+ FoFiOutputFunc outputFunc,
+ void *outputStream) {
+ FoFiType1C *ff;
+ int i;
+
+ if (!openTypeCFF) {
+ return;
+ }
+ i = seekTable("CFF ");
+ if (!checkRegion(tables[i].offset, tables[i].len)) {
+ return;
+ }
+ if (!(ff = FoFiType1C::make((char *)file + tables[i].offset,
+ tables[i].len))) {
+ return;
+ }
+ ff->convertToCIDType0(psName, outputFunc, outputStream);
+ delete ff;
+}
+
void FoFiTrueType::convertToType0(char *psName, Gushort *cidMap, int nCIDs,
GBool needVerticalMetrics,
FoFiOutputFunc outputFunc,
void *outputStream) {
- char buf[512];
+ GString *buf;
GString *sfntsName;
int n, i, j;
+ if (openTypeCFF) {
+ return;
+ }
+
// write the Type 42 sfnts array
sfntsName = (new GString(psName))->append("_sfnts");
cvtSfnts(outputFunc, outputStream, sfntsName, needVerticalMetrics);
@@ -578,28 +676,33 @@ void FoFiTrueType::convertToType0(char *psName, Gushort *cidMap, int nCIDs,
(*outputFunc)(outputStream, "10 dict begin\n", 14);
(*outputFunc)(outputStream, "/FontName /", 11);
(*outputFunc)(outputStream, psName, strlen(psName));
- sprintf(buf, "_%02x def\n", i >> 8);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ buf = GString::format("_{0:02x} def\n", i >> 8);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
(*outputFunc)(outputStream, "/FontType 42 def\n", 17);
(*outputFunc)(outputStream, "/FontMatrix [1 0 0 1 0 0] def\n", 30);
- sprintf(buf, "/FontBBox [%d %d %d %d] def\n",
- bbox[0], bbox[1], bbox[2], bbox[3]);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ buf = GString::format("/FontBBox [{0:d} {1:d} {2:d} {3:d}] def\n",
+ bbox[0], bbox[1], bbox[2], bbox[3]);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
(*outputFunc)(outputStream, "/PaintType 0 def\n", 17);
(*outputFunc)(outputStream, "/sfnts ", 7);
(*outputFunc)(outputStream, psName, strlen(psName));
(*outputFunc)(outputStream, "_sfnts def\n", 11);
(*outputFunc)(outputStream, "/Encoding 256 array\n", 20);
for (j = 0; j < 256 && i+j < n; ++j) {
- sprintf(buf, "dup %d /c%02x put\n", j, j);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ buf = GString::format("dup {0:d} /c{1:02x} put\n", j, j);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
}
(*outputFunc)(outputStream, "readonly def\n", 13);
(*outputFunc)(outputStream, "/CharStrings 257 dict dup begin\n", 32);
(*outputFunc)(outputStream, "/.notdef 0 def\n", 15);
for (j = 0; j < 256 && i+j < n; ++j) {
- sprintf(buf, "/c%02x %d def\n", j, cidMap ? cidMap[i+j] : i+j);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ buf = GString::format("/c{0:02x} {1:d} def\n",
+ j, cidMap ? cidMap[i+j] : i+j);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
}
(*outputFunc)(outputStream, "end readonly def\n", 17);
(*outputFunc)(outputStream,
@@ -616,21 +719,44 @@ void FoFiTrueType::convertToType0(char *psName, Gushort *cidMap, int nCIDs,
(*outputFunc)(outputStream, "/FMapType 2 def\n", 16);
(*outputFunc)(outputStream, "/Encoding [\n", 12);
for (i = 0; i < n; i += 256) {
- sprintf(buf, "%d\n", i >> 8);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ buf = GString::format("{0:d}\n", i >> 8);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
}
(*outputFunc)(outputStream, "] def\n", 6);
(*outputFunc)(outputStream, "/FDepVector [\n", 14);
for (i = 0; i < n; i += 256) {
(*outputFunc)(outputStream, "/", 1);
(*outputFunc)(outputStream, psName, strlen(psName));
- sprintf(buf, "_%02x findfont\n", i >> 8);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ buf = GString::format("_{0:02x} findfont\n", i >> 8);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
}
(*outputFunc)(outputStream, "] def\n", 6);
(*outputFunc)(outputStream, "FontName currentdict end definefont pop\n", 40);
}
+void FoFiTrueType::convertToType0(char *psName,
+ FoFiOutputFunc outputFunc,
+ void *outputStream) {
+ FoFiType1C *ff;
+ int i;
+
+ if (!openTypeCFF) {
+ return;
+ }
+ i = seekTable("CFF ");
+ if (!checkRegion(tables[i].offset, tables[i].len)) {
+ return;
+ }
+ if (!(ff = FoFiType1C::make((char *)file + tables[i].offset,
+ tables[i].len))) {
+ return;
+ }
+ ff->convertToType0(psName, outputFunc, outputStream);
+ delete ff;
+}
+
void FoFiTrueType::writeTTF(FoFiOutputFunc outputFunc,
void *outputStream, char *name,
Gushort *codeToGID) {
@@ -672,12 +798,50 @@ void FoFiTrueType::writeTTF(FoFiOutputFunc outputFunc,
0, 0, 0, 0, // min Type 1 memory
0, 0, 0, 0 // max Type 1 memory
};
- GBool missingCmap, missingName, missingPost, unsortedLoca, badCmapLen;
+ static char os2Tab[86] = {
+ 0, 1, // version
+ 0, 1, // xAvgCharWidth
+ 0, 0, // usWeightClass
+ 0, 0, // usWidthClass
+ 0, 0, // fsType
+ 0, 0, // ySubscriptXSize
+ 0, 0, // ySubscriptYSize
+ 0, 0, // ySubscriptXOffset
+ 0, 0, // ySubscriptYOffset
+ 0, 0, // ySuperscriptXSize
+ 0, 0, // ySuperscriptYSize
+ 0, 0, // ySuperscriptXOffset
+ 0, 0, // ySuperscriptYOffset
+ 0, 0, // yStrikeoutSize
+ 0, 0, // yStrikeoutPosition
+ 0, 0, // sFamilyClass
+ 0, 0, 0, 0, 0, // panose
+ 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, // ulUnicodeRange1
+ 0, 0, 0, 0, // ulUnicodeRange2
+ 0, 0, 0, 0, // ulUnicodeRange3
+ 0, 0, 0, 0, // ulUnicodeRange4
+ 0, 0, 0, 0, // achVendID
+ 0, 0, // fsSelection
+ 0, 0, // usFirstCharIndex
+ 0, 0, // usLastCharIndex
+ 0, 0, // sTypoAscender
+ 0, 0, // sTypoDescender
+ 0, 0, // sTypoLineGap
+ 0, 0, // usWinAscent
+ 0, 0, // usWinDescent
+ 0, 0, 0, 0, // ulCodePageRange1
+ 0, 0, 0, 0 // ulCodePageRange2
+ };
+ GBool missingCmap, missingName, missingPost, missingOS2;
+ GBool unsortedLoca, badCmapLen, abbrevHMTX;
int nZeroLengthTables;
+ int nHMetrics, advWidth, lsb;
TrueTypeLoca *locaTable;
TrueTypeTable *newTables;
- char *newNameTab, *newCmapTab;
+ char *newNameTab, *newCmapTab, *newHHEATab, *newHMTXTab;
int nNewTables, cmapIdx, cmapLen, glyfLen, newNameLen, newCmapLen, next;
+ int newHHEALen, newHMTXLen;
Guint locaChecksum, glyfChecksum, fileChecksum;
char *tableDir;
char locaBuf[4], checksumBuf[4];
@@ -685,10 +849,20 @@ void FoFiTrueType::writeTTF(FoFiOutputFunc outputFunc,
Guint t;
int pos, i, j, k, n;
+ if (openTypeCFF) {
+ return;
+ }
+
// check for missing tables
+ // (Note: if the OS/2 table is missing, the Microsoft PCL5 driver
+ // will embed a PCL TrueType font with the pitch field set to zero,
+ // which apparently causes divide-by-zero errors. As far as I can
+ // tell, the only important field in the OS/2 table is
+ // xAvgCharWidth.)
missingCmap = (cmapIdx = seekTable("cmap")) < 0;
missingName = seekTable("name") < 0;
missingPost = seekTable("post") < 0;
+ missingOS2 = seekTable("OS/2") < 0;
// read the loca table, check to see if it's sorted
locaTable = (TrueTypeLoca *)gmallocn(nGlyphs + 1, sizeof(TrueTypeLoca));
@@ -705,6 +879,19 @@ void FoFiTrueType::writeTTF(FoFiOutputFunc outputFunc,
if (i > 0 && locaTable[i].origOffset < locaTable[i-1].origOffset) {
unsortedLoca = gTrue;
}
+ // glyph descriptions must be at least 12 bytes long (nContours,
+ // xMin, yMin, xMax, yMax, instructionLength - two bytes each);
+ // invalid glyph descriptions (even if they're never used) make
+ // Windows choke, so we work around that problem here (ideally,
+ // this would parse the glyph descriptions in the glyf table and
+ // remove any that were invalid, but this quick test is a decent
+ // start)
+ if (i > 0 &&
+ locaTable[i].origOffset - locaTable[i-1].origOffset > 0 &&
+ locaTable[i].origOffset - locaTable[i-1].origOffset < 12) {
+ locaTable[i-1].origOffset = locaTable[i].origOffset;
+ unsortedLoca = gTrue;
+ }
locaTable[i].idx = i;
}
@@ -732,9 +919,17 @@ void FoFiTrueType::writeTTF(FoFiOutputFunc outputFunc,
}
}
+ // check for an abbreviated hmtx table (this is completely legal,
+ // but confuses the Microsoft PCL5 printer driver, which generates
+ // embedded fonts with the pitch field set to zero)
+ i = seekTable("hhea");
+ nHMetrics = getU16BE(tables[i].offset + 34, &ok);
+ abbrevHMTX = nHMetrics < nGlyphs;
+
// if nothing is broken, just write the TTF file as is
- if (!missingCmap && !missingName && !missingPost && !unsortedLoca &&
- !badCmapLen && nZeroLengthTables == 0 && !name && !codeToGID) {
+ if (!missingCmap && !missingName && !missingPost && !missingOS2 &&
+ !unsortedLoca && !badCmapLen && !abbrevHMTX && nZeroLengthTables == 0 &&
+ !name && !codeToGID) {
(*outputFunc)(outputStream, (char *)file, len);
goto done1;
}
@@ -892,6 +1087,44 @@ void FoFiTrueType::writeTTF(FoFiOutputFunc outputFunc,
newCmapTab = NULL;
}
+ // generate the new hmtx table and the updated hhea table
+ if (abbrevHMTX) {
+ i = seekTable("hhea");
+ pos = tables[i].offset;
+ newHHEALen = 36;
+ newHHEATab = (char *)gmalloc(newHHEALen);
+ for (i = 0; i < newHHEALen; ++i) {
+ newHHEATab[i] = getU8(pos++, &ok);
+ }
+ newHHEATab[34] = nGlyphs >> 8;
+ newHHEATab[35] = nGlyphs & 0xff;
+ i = seekTable("hmtx");
+ pos = tables[i].offset;
+ newHMTXLen = 4 * nGlyphs;
+ newHMTXTab = (char *)gmalloc(newHMTXLen);
+ advWidth = 0;
+ for (i = 0; i < nHMetrics; ++i) {
+ advWidth = getU16BE(pos, &ok);
+ lsb = getU16BE(pos + 2, &ok);
+ pos += 4;
+ newHMTXTab[4*i ] = advWidth >> 8;
+ newHMTXTab[4*i + 1] = advWidth & 0xff;
+ newHMTXTab[4*i + 2] = lsb >> 8;
+ newHMTXTab[4*i + 3] = lsb & 0xff;
+ }
+ for (; i < nGlyphs; ++i) {
+ lsb = getU16BE(pos, &ok);
+ pos += 2;
+ newHMTXTab[4*i ] = advWidth >> 8;
+ newHMTXTab[4*i + 1] = advWidth & 0xff;
+ newHMTXTab[4*i + 2] = lsb >> 8;
+ newHMTXTab[4*i + 3] = lsb & 0xff;
+ }
+ } else {
+ newHHEATab = newHMTXTab = NULL;
+ newHHEALen = newHMTXLen = 0; // make gcc happy
+ }
+
// construct the new table directory:
// - keep all original tables with non-zero length
// - fix the cmap table's length, if necessary
@@ -901,7 +1134,7 @@ void FoFiTrueType::writeTTF(FoFiOutputFunc outputFunc,
// - (re)compute table checksums
nNewTables = nTables - nZeroLengthTables +
(missingCmap ? 1 : 0) + (missingName ? 1 : 0) +
- (missingPost ? 1 : 0);
+ (missingPost ? 1 : 0) + (missingOS2 ? 1 : 0);
newTables = (TrueTypeTable *)gmallocn(nNewTables, sizeof(TrueTypeTable));
j = 0;
for (i = 0; i < nTables; ++i) {
@@ -932,6 +1165,14 @@ void FoFiTrueType::writeTTF(FoFiOutputFunc outputFunc,
newTables[j].len = newNameLen;
newTables[j].checksum = computeTableChecksum((Guchar *)newNameTab,
newNameLen);
+ } else if (newTables[j].tag == hheaTag && abbrevHMTX) {
+ newTables[j].len = newHHEALen;
+ newTables[j].checksum = computeTableChecksum((Guchar *)newHHEATab,
+ newHHEALen);
+ } else if (newTables[j].tag == hmtxTag && abbrevHMTX) {
+ newTables[j].len = newHMTXLen;
+ newTables[j].checksum = computeTableChecksum((Guchar *)newHMTXTab,
+ newHMTXLen);
}
++j;
}
@@ -969,6 +1210,13 @@ void FoFiTrueType::writeTTF(FoFiOutputFunc outputFunc,
newTables[j].len = sizeof(postTab);
++j;
}
+ if (missingOS2) {
+ newTables[j].tag = os2Tag;
+ newTables[j].checksum = computeTableChecksum((Guchar *)os2Tab,
+ sizeof(os2Tab));
+ newTables[j].len = sizeof(os2Tab);
+ ++j;
+ }
qsort(newTables, nNewTables, sizeof(TrueTypeTable),
&cmpTrueTypeTableTag);
pos = 12 + nNewTables * 16;
@@ -1055,6 +1303,12 @@ void FoFiTrueType::writeTTF(FoFiOutputFunc outputFunc,
(*outputFunc)(outputStream, nameTab, newTables[i].len);
} else if (newTables[i].tag == postTag && missingPost) {
(*outputFunc)(outputStream, postTab, newTables[i].len);
+ } else if (newTables[i].tag == os2Tag && missingOS2) {
+ (*outputFunc)(outputStream, os2Tab, newTables[i].len);
+ } else if (newTables[i].tag == hheaTag && abbrevHMTX) {
+ (*outputFunc)(outputStream, newHHEATab, newTables[i].len);
+ } else if (newTables[i].tag == hmtxTag && abbrevHMTX) {
+ (*outputFunc)(outputStream, newHMTXTab, newTables[i].len);
} else if (newTables[i].tag == locaTag && unsortedLoca) {
for (j = 0; j <= nGlyphs; ++j) {
if (locaFmt) {
@@ -1102,6 +1356,8 @@ void FoFiTrueType::writeTTF(FoFiOutputFunc outputFunc,
}
}
+ gfree(newHMTXTab);
+ gfree(newHHEATab);
gfree(newCmapTab);
gfree(newNameTab);
gfree(tableDir);
@@ -1114,7 +1370,7 @@ void FoFiTrueType::cvtEncoding(char **encoding,
FoFiOutputFunc outputFunc,
void *outputStream) {
char *name;
- char buf[64];
+ GString *buf;
int i;
(*outputFunc)(outputStream, "/Encoding 256 array\n", 20);
@@ -1123,15 +1379,17 @@ void FoFiTrueType::cvtEncoding(char **encoding,
if (!(name = encoding[i])) {
name = ".notdef";
}
- sprintf(buf, "dup %d /", i);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ buf = GString::format("dup {0:d} /", i);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
(*outputFunc)(outputStream, name, strlen(name));
(*outputFunc)(outputStream, " put\n", 5);
}
} else {
for (i = 0; i < 256; ++i) {
- sprintf(buf, "dup %d /c%02x put\n", i, i);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ buf = GString::format("dup {0:d} /c{1:02x} put\n", i, i);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
}
}
(*outputFunc)(outputStream, "readonly def\n", 13);
@@ -1142,7 +1400,8 @@ void FoFiTrueType::cvtCharStrings(char **encoding,
FoFiOutputFunc outputFunc,
void *outputStream) {
char *name;
- char buf[64], buf2[16];
+ GString *buf;
+ char buf2[16];
int i, k;
// always define '.notdef'
@@ -1177,8 +1436,9 @@ void FoFiTrueType::cvtCharStrings(char **encoding,
if (k > 0 && k < nGlyphs) {
(*outputFunc)(outputStream, "/", 1);
(*outputFunc)(outputStream, name, strlen(name));
- sprintf(buf, " %d def\n", k);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ buf = GString::format(" {0:d} def\n", k);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
}
}
}
@@ -1481,14 +1741,15 @@ void FoFiTrueType::cvtSfnts(FoFiOutputFunc outputFunc,
void FoFiTrueType::dumpString(Guchar *s, int length,
FoFiOutputFunc outputFunc,
void *outputStream) {
- char buf[64];
+ GString *buf;
int pad, i, j;
(*outputFunc)(outputStream, "<", 1);
for (i = 0; i < length; i += 32) {
for (j = 0; j < 32 && i+j < length; ++j) {
- sprintf(buf, "%02X", s[i+j] & 0xff);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ buf = GString::format("{0:02x}", s[i+j] & 0xff);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
}
if (i % (65536 - 32) == 65536 - 64) {
(*outputFunc)(outputStream, ">\n<", 3);
@@ -1537,7 +1798,7 @@ Guint FoFiTrueType::computeTableChecksum(Guchar *data, int length) {
void FoFiTrueType::parse() {
Guint topTag;
- int pos, i, j;
+ int pos, ver, i, j;
parsedOk = gTrue;
@@ -1555,6 +1816,13 @@ void FoFiTrueType::parse() {
pos = 0;
}
+ // check the sfnt version
+ ver = getU32BE(pos, &parsedOk);
+ if (!parsedOk) {
+ return;
+ }
+ openTypeCFF = ver == 0x4f54544f; // 'OTTO'
+
// read the table directory
nTables = getU16BE(pos + 4, &parsedOk);
if (!parsedOk) {
@@ -1581,10 +1849,11 @@ void FoFiTrueType::parse() {
// the Type 42 spec
if (seekTable("head") < 0 ||
seekTable("hhea") < 0 ||
- seekTable("loca") < 0 ||
seekTable("maxp") < 0 ||
- seekTable("glyf") < 0 ||
- seekTable("hmtx") < 0) {
+ seekTable("hmtx") < 0 ||
+ (!openTypeCFF && seekTable("loca") < 0) ||
+ (!openTypeCFF && seekTable("glyf") < 0) ||
+ (openTypeCFF && seekTable("CFF ") < 0)) {
parsedOk = gFalse;
return;
}
@@ -1633,23 +1902,28 @@ void FoFiTrueType::parse() {
// make sure the loca table is sane (correct length and entries are
// in bounds)
- i = seekTable("loca");
- if (tables[i].len < (nGlyphs + 1) * (locaFmt ? 4 : 2)) {
- parsedOk = gFalse;
- return;
- }
- for (j = 0; j <= nGlyphs; ++j) {
- if (locaFmt) {
- pos = (int)getU32BE(tables[i].offset + j*4, &parsedOk);
- } else {
- pos = getU16BE(tables[i].offset + j*2, &parsedOk);
- }
- if (pos < 0 || pos > len) {
+ if (!openTypeCFF) {
+ i = seekTable("loca");
+ if (tables[i].len < 0) {
parsedOk = gFalse;
+ return;
+ }
+ if (tables[i].len < (nGlyphs + 1) * (locaFmt ? 4 : 2)) {
+ nGlyphs = tables[i].len / (locaFmt ? 4 : 2) - 1;
+ }
+ for (j = 0; j <= nGlyphs; ++j) {
+ if (locaFmt) {
+ pos = (int)getU32BE(tables[i].offset + j*4, &parsedOk);
+ } else {
+ pos = getU16BE(tables[i].offset + j*2, &parsedOk);
+ }
+ if (pos < 0 || pos > len) {
+ parsedOk = gFalse;
+ }
+ }
+ if (!parsedOk) {
+ return;
}
- }
- if (!parsedOk) {
- return;
}
// read the post table
diff --git a/Build/source/libs/xpdf/fofi/FoFiTrueType.h b/Build/source/libs/xpdf/fofi/FoFiTrueType.h
index f7b09d6c0ab..cf06ae78a9e 100644
--- a/Build/source/libs/xpdf/fofi/FoFiTrueType.h
+++ b/Build/source/libs/xpdf/fofi/FoFiTrueType.h
@@ -38,6 +38,10 @@ public:
virtual ~FoFiTrueType();
+ // Returns true if this an OpenType font containing CFF data, false
+ // if it's a TrueType font (or OpenType font with TrueType data).
+ GBool isOpenTypeCFF() { return openTypeCFF; }
+
// Return the number of cmaps defined by this font.
int getNumCmaps();
@@ -59,6 +63,11 @@ public:
// font does not have a post table.
int mapNameToGID(char *name);
+ // Return the mapping from CIDs to GIDs, and return the number of
+ // CIDs in *<nCIDs>. This is only useful for CID fonts. (Only
+ // useful for OpenType CFF fonts.)
+ Gushort *getCIDToGIDMap(int *nCIDs);
+
// Returns the least restrictive embedding licensing right (as
// defined by the TrueType spec):
// * 4: OS/2 table is missing or invalid
@@ -74,33 +83,57 @@ public:
// <encoding> array specifies the mapping from char codes to names.
// If <encoding> is NULL, the encoding is unknown or undefined. The
// <codeToGID> array specifies the mapping from char codes to GIDs.
+ // (Not useful for OpenType CFF fonts.)
void convertToType42(char *psName, char **encoding,
Gushort *codeToGID,
FoFiOutputFunc outputFunc, void *outputStream);
+ // Convert to a Type 1 font, suitable for embedding in a PostScript
+ // file. This is only useful with 8-bit fonts. If <newEncoding> is
+ // not NULL, it will be used in place of the encoding in the Type 1C
+ // font. If <ascii> is true the eexec section will be hex-encoded,
+ // otherwise it will be left as binary data. If <psName> is
+ // non-NULL, it will be used as the PostScript font name. (Only
+ // useful for OpenType CFF fonts.)
+ void convertToType1(char *psName, char **newEncoding, GBool ascii,
+ FoFiOutputFunc outputFunc, void *outputStream);
+
// Convert to a Type 2 CIDFont, suitable for embedding in a
// PostScript file. <psName> will be used as the PostScript font
// name (so we don't need to depend on the 'name' table in the
// font). The <cidMap> array maps CIDs to GIDs; it has <nCIDs>
- // entries.
+ // entries. (Not useful for OpenType CFF fonts.)
void convertToCIDType2(char *psName, Gushort *cidMap, int nCIDs,
GBool needVerticalMetrics,
FoFiOutputFunc outputFunc, void *outputStream);
+ // Convert to a Type 0 CIDFont, suitable for embedding in a
+ // PostScript file. <psName> will be used as the PostScript font
+ // name. (Only useful for OpenType CFF fonts.)
+ void convertToCIDType0(char *psName,
+ FoFiOutputFunc outputFunc, void *outputStream);
+
// Convert to a Type 0 (but non-CID) composite font, suitable for
// embedding in a PostScript file. <psName> will be used as the
// PostScript font name (so we don't need to depend on the 'name'
// table in the font). The <cidMap> array maps CIDs to GIDs; it has
- // <nCIDs> entries.
+ // <nCIDs> entries. (Not useful for OpenType CFF fonts.)
void convertToType0(char *psName, Gushort *cidMap, int nCIDs,
GBool needVerticalMetrics,
FoFiOutputFunc outputFunc, void *outputStream);
+ // Convert to a Type 0 (but non-CID) composite font, suitable for
+ // embedding in a PostScript file. <psName> will be used as the
+ // PostScript font name. (Only useful for OpenType CFF fonts.)
+ void convertToType0(char *psName,
+ FoFiOutputFunc outputFunc, void *outputStream);
+
// Write a clean TTF file, filling in missing tables and correcting
// various other errors. If <name> is non-NULL, the font is renamed
// to <name>. If <codeToGID> is non-NULL, the font is re-encoded,
// using a Windows Unicode cmap. If <name> is NULL and the font is
- // complete and correct, it will be written unmodified.
+ // complete and correct, it will be written unmodified. (Not useful
+ // for OpenType CFF fonts.)
void writeTTF(FoFiOutputFunc outputFunc, void *outputStream,
char *name = NULL, Gushort *codeToGID = NULL);
@@ -133,6 +166,7 @@ private:
int locaFmt;
int bbox[4];
GHash *nameToGID;
+ GBool openTypeCFF;
GBool parsedOk;
};
diff --git a/Build/source/libs/xpdf/fofi/FoFiType1.cc b/Build/source/libs/xpdf/fofi/FoFiType1.cc
index 256639c1203..efad5ee4eb7 100644
--- a/Build/source/libs/xpdf/fofi/FoFiType1.cc
+++ b/Build/source/libs/xpdf/fofi/FoFiType1.cc
@@ -75,7 +75,7 @@ char **FoFiType1::getEncoding() {
void FoFiType1::writeEncoded(char **newEncoding,
FoFiOutputFunc outputFunc, void *outputStream) {
char buf[512];
- char *line;
+ char *line, *line2, *p;
int i;
// copy everything up to the encoding
@@ -101,19 +101,57 @@ void FoFiType1::writeEncoded(char **newEncoding,
}
(*outputFunc)(outputStream, "readonly def\n", 13);
- // copy everything after the encoding
+ // find the end of the encoding data
+ //~ this ought to parse PostScript tokens
if (!strncmp(line, "/Encoding StandardEncoding def", 30)) {
line = getNextLine(line);
} else {
- for (line = getNextLine(line);
- line && strncmp(line, "readonly def", 12);
- line = getNextLine(line)) ;
- if (line) {
- line = getNextLine(line);
+ // skip "/Encoding" + one whitespace char,
+ // then look for 'def' preceded by PostScript whitespace
+ p = line + 10;
+ line = NULL;
+ for (; p < (char *)file + len; ++p) {
+ if ((*p == ' ' || *p == '\t' || *p == '\x0a' ||
+ *p == '\x0d' || *p == '\x0c' || *p == '\0') &&
+ p + 4 <= (char *)file + len &&
+ !strncmp(p + 1, "def", 3)) {
+ line = p + 4;
+ break;
+ }
}
}
+
+ // some fonts have two /Encoding entries in their dictionary, so we
+ // check for a second one here
if (line) {
- (*outputFunc)(outputStream, line, ((char *)file + len) - line);
+ for (line2 = line, i = 0;
+ i < 20 && line2 && strncmp(line2, "/Encoding", 9);
+ line2 = getNextLine(line2), ++i) ;
+ if (i < 20 && line2) {
+ (*outputFunc)(outputStream, line, line2 - line);
+ if (!strncmp(line2, "/Encoding StandardEncoding def", 30)) {
+ line = getNextLine(line2);
+ } else {
+ // skip "/Encoding" + one whitespace char,
+ // then look for 'def' preceded by PostScript whitespace
+ p = line2 + 10;
+ line = NULL;
+ for (; p < (char *)file + len; ++p) {
+ if ((*p == ' ' || *p == '\t' || *p == '\x0a' ||
+ *p == '\x0d' || *p == '\x0c' || *p == '\0') &&
+ p + 4 <= (char *)file + len &&
+ !strncmp(p + 1, "def", 3)) {
+ line = p + 4;
+ break;
+ }
+ }
+ }
+ }
+
+ // copy everything after the encoding
+ if (line) {
+ (*outputFunc)(outputStream, line, ((char *)file + len) - line);
+ }
}
}
@@ -178,8 +216,15 @@ void FoFiType1::parse() {
if (*p2) {
c = *p2;
*p2 = '\0';
- if ((code = atoi(p)) < 256) {
- *p2 = c;
+ code = atoi(p);
+ *p2 = c;
+ if (code == 8 && *p2 == '#') {
+ code = 0;
+ for (++p2; *p2 >= '0' && *p2 <= '7'; ++p2) {
+ code = code * 8 + (*p2 - '0');
+ }
+ }
+ if (code < 256) {
for (p = p2; *p == ' ' || *p == '\t'; ++p) ;
if (*p == '/') {
++p;
diff --git a/Build/source/libs/xpdf/fofi/FoFiType1C.cc b/Build/source/libs/xpdf/fofi/FoFiType1C.cc
index 499414bea2a..3b28f3210c8 100644
--- a/Build/source/libs/xpdf/fofi/FoFiType1C.cc
+++ b/Build/source/libs/xpdf/fofi/FoFiType1C.cc
@@ -129,24 +129,33 @@ Gushort *FoFiType1C::getCIDToGIDMap(int *nCIDs) {
return map;
}
-void FoFiType1C::convertToType1(char **newEncoding, GBool ascii,
+void FoFiType1C::convertToType1(char *psName, char **newEncoding, GBool ascii,
FoFiOutputFunc outputFunc,
void *outputStream) {
+ int psNameLen;
Type1CEexecBuf eb;
Type1CIndex subrIdx;
Type1CIndexVal val;
- char buf[512];
+ GString *buf;
+ char buf2[256];
char **enc;
GBool ok;
int i;
+ if (psName) {
+ psNameLen = strlen(psName);
+ } else {
+ psName = name->getCString();
+ psNameLen = name->getLength();
+ }
+
// write header and font dictionary, up to encoding
ok = gTrue;
(*outputFunc)(outputStream, "%!FontType1-1.0: ", 17);
- (*outputFunc)(outputStream, name->getCString(), name->getLength());
+ (*outputFunc)(outputStream, psName, psNameLen);
if (topDict.versionSID != 0) {
- getString(topDict.versionSID, buf, &ok);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ getString(topDict.versionSID, buf2, &ok);
+ (*outputFunc)(outputStream, buf2, strlen(buf2));
}
(*outputFunc)(outputStream, "\n", 1);
// the dictionary needs room for 12 entries: the following 9, plus
@@ -156,37 +165,37 @@ void FoFiType1C::convertToType1(char **newEncoding, GBool ascii,
(*outputFunc)(outputStream, "/FontInfo 10 dict dup begin\n", 28);
if (topDict.versionSID != 0) {
(*outputFunc)(outputStream, "/version (", 10);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ (*outputFunc)(outputStream, buf2, strlen(buf2));
(*outputFunc)(outputStream, ") readonly def\n", 15);
}
if (topDict.noticeSID != 0) {
- getString(topDict.noticeSID, buf, &ok);
+ getString(topDict.noticeSID, buf2, &ok);
(*outputFunc)(outputStream, "/Notice (", 9);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ (*outputFunc)(outputStream, buf2, strlen(buf2));
(*outputFunc)(outputStream, ") readonly def\n", 15);
}
if (topDict.copyrightSID != 0) {
- getString(topDict.copyrightSID, buf, &ok);
+ getString(topDict.copyrightSID, buf2, &ok);
(*outputFunc)(outputStream, "/Copyright (", 12);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ (*outputFunc)(outputStream, buf2, strlen(buf2));
(*outputFunc)(outputStream, ") readonly def\n", 15);
}
if (topDict.fullNameSID != 0) {
- getString(topDict.fullNameSID, buf, &ok);
+ getString(topDict.fullNameSID, buf2, &ok);
(*outputFunc)(outputStream, "/FullName (", 11);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ (*outputFunc)(outputStream, buf2, strlen(buf2));
(*outputFunc)(outputStream, ") readonly def\n", 15);
}
if (topDict.familyNameSID != 0) {
- getString(topDict.familyNameSID, buf, &ok);
+ getString(topDict.familyNameSID, buf2, &ok);
(*outputFunc)(outputStream, "/FamilyName (", 13);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ (*outputFunc)(outputStream, buf2, strlen(buf2));
(*outputFunc)(outputStream, ") readonly def\n", 15);
}
if (topDict.weightSID != 0) {
- getString(topDict.weightSID, buf, &ok);
+ getString(topDict.weightSID, buf2, &ok);
(*outputFunc)(outputStream, "/Weight (", 9);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ (*outputFunc)(outputStream, buf2, strlen(buf2));
(*outputFunc)(outputStream, ") readonly def\n", 15);
}
if (topDict.isFixedPitch) {
@@ -194,32 +203,43 @@ void FoFiType1C::convertToType1(char **newEncoding, GBool ascii,
} else {
(*outputFunc)(outputStream, "/isFixedPitch false def\n", 24);
}
- sprintf(buf, "/ItalicAngle %g def\n", topDict.italicAngle);
- (*outputFunc)(outputStream, buf, strlen(buf));
- sprintf(buf, "/UnderlinePosition %g def\n", topDict.underlinePosition);
- (*outputFunc)(outputStream, buf, strlen(buf));
- sprintf(buf, "/UnderlineThickness %g def\n", topDict.underlineThickness);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ buf = GString::format("/ItalicAngle {0:.4g} def\n", topDict.italicAngle);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
+ buf = GString::format("/UnderlinePosition {0:.4g} def\n",
+ topDict.underlinePosition);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
+ buf = GString::format("/UnderlineThickness {0:.4g} def\n",
+ topDict.underlineThickness);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
(*outputFunc)(outputStream, "end readonly def\n", 17);
(*outputFunc)(outputStream, "/FontName /", 11);
- (*outputFunc)(outputStream, name->getCString(), name->getLength());
+ (*outputFunc)(outputStream, psName, psNameLen);
(*outputFunc)(outputStream, " def\n", 5);
- sprintf(buf, "/PaintType %d def\n", topDict.paintType);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ buf = GString::format("/PaintType {0:d} def\n", topDict.paintType);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
(*outputFunc)(outputStream, "/FontType 1 def\n", 16);
- sprintf(buf, "/FontMatrix [%g %g %g %g %g %g] readonly def\n",
- topDict.fontMatrix[0], topDict.fontMatrix[1], topDict.fontMatrix[2],
- topDict.fontMatrix[3], topDict.fontMatrix[4], topDict.fontMatrix[5]);
- (*outputFunc)(outputStream, buf, strlen(buf));
- sprintf(buf, "/FontBBox [%g %g %g %g] readonly def\n",
- topDict.fontBBox[0], topDict.fontBBox[1],
- topDict.fontBBox[2], topDict.fontBBox[3]);
- (*outputFunc)(outputStream, buf, strlen(buf));
- sprintf(buf, "/StrokeWidth %g def\n", topDict.strokeWidth);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ buf = GString::format("/FontMatrix [{0:.8g} {1:.8g} {2:.8g} {3:.8g} {4:.8g} {5:.8g}] readonly def\n",
+ topDict.fontMatrix[0], topDict.fontMatrix[1],
+ topDict.fontMatrix[2], topDict.fontMatrix[3],
+ topDict.fontMatrix[4], topDict.fontMatrix[5]);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
+ buf = GString::format("/FontBBox [{0:.4g} {1:.4g} {2:.4g} {3:.4g}] readonly def\n",
+ topDict.fontBBox[0], topDict.fontBBox[1],
+ topDict.fontBBox[2], topDict.fontBBox[3]);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
+ buf = GString::format("/StrokeWidth {0:.4g} def\n", topDict.strokeWidth);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
if (topDict.uniqueID != 0) {
- sprintf(buf, "/UniqueID %d def\n", topDict.uniqueID);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ buf = GString::format("/UniqueID {0:d} def\n", topDict.uniqueID);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
}
// write the encoding
@@ -233,8 +253,9 @@ void FoFiType1C::convertToType1(char **newEncoding, GBool ascii,
enc = newEncoding ? newEncoding : encoding;
for (i = 0; i < 256; ++i) {
if (enc[i]) {
- sprintf(buf, "dup %d /%s put\n", i, enc[i]);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ buf = GString::format("dup {0:d} /{1:s} put\n", i, enc[i]);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
}
}
(*outputFunc)(outputStream, "readonly def\n", 13);
@@ -261,89 +282,112 @@ void FoFiType1C::convertToType1(char **newEncoding, GBool ascii,
if (privateDicts[0].nBlueValues) {
eexecWrite(&eb, "/BlueValues [");
for (i = 0; i < privateDicts[0].nBlueValues; ++i) {
- sprintf(buf, "%s%d", i > 0 ? " " : "", privateDicts[0].blueValues[i]);
- eexecWrite(&eb, buf);
+ buf = GString::format("{0:s}{1:d}",
+ i > 0 ? " " : "", privateDicts[0].blueValues[i]);
+ eexecWrite(&eb, buf->getCString());
+ delete buf;
}
eexecWrite(&eb, "] def\n");
}
if (privateDicts[0].nOtherBlues) {
eexecWrite(&eb, "/OtherBlues [");
for (i = 0; i < privateDicts[0].nOtherBlues; ++i) {
- sprintf(buf, "%s%d", i > 0 ? " " : "", privateDicts[0].otherBlues[i]);
- eexecWrite(&eb, buf);
+ buf = GString::format("{0:s}{1:d}",
+ i > 0 ? " " : "", privateDicts[0].otherBlues[i]);
+ eexecWrite(&eb, buf->getCString());
+ delete buf;
}
eexecWrite(&eb, "] def\n");
}
if (privateDicts[0].nFamilyBlues) {
eexecWrite(&eb, "/FamilyBlues [");
for (i = 0; i < privateDicts[0].nFamilyBlues; ++i) {
- sprintf(buf, "%s%d", i > 0 ? " " : "", privateDicts[0].familyBlues[i]);
- eexecWrite(&eb, buf);
+ buf = GString::format("{0:s}{1:d}",
+ i > 0 ? " " : "", privateDicts[0].familyBlues[i]);
+ eexecWrite(&eb, buf->getCString());
+ delete buf;
}
eexecWrite(&eb, "] def\n");
}
if (privateDicts[0].nFamilyOtherBlues) {
eexecWrite(&eb, "/FamilyOtherBlues [");
for (i = 0; i < privateDicts[0].nFamilyOtherBlues; ++i) {
- sprintf(buf, "%s%d", i > 0 ? " " : "",
- privateDicts[0].familyOtherBlues[i]);
- eexecWrite(&eb, buf);
+ buf = GString::format("{0:s}{1:d}", i > 0 ? " " : "",
+ privateDicts[0].familyOtherBlues[i]);
+ eexecWrite(&eb, buf->getCString());
+ delete buf;
}
eexecWrite(&eb, "] def\n");
}
if (privateDicts[0].blueScale != 0.039625) {
- sprintf(buf, "/BlueScale %g def\n", privateDicts[0].blueScale);
- eexecWrite(&eb, buf);
+ buf = GString::format("/BlueScale {0:.4g} def\n",
+ privateDicts[0].blueScale);
+ eexecWrite(&eb, buf->getCString());
+ delete buf;
}
if (privateDicts[0].blueShift != 7) {
- sprintf(buf, "/BlueShift %d def\n", privateDicts[0].blueShift);
- eexecWrite(&eb, buf);
+ buf = GString::format("/BlueShift {0:d} def\n", privateDicts[0].blueShift);
+ eexecWrite(&eb, buf->getCString());
+ delete buf;
}
if (privateDicts[0].blueFuzz != 1) {
- sprintf(buf, "/BlueFuzz %d def\n", privateDicts[0].blueFuzz);
- eexecWrite(&eb, buf);
+ buf = GString::format("/BlueFuzz {0:d} def\n", privateDicts[0].blueFuzz);
+ eexecWrite(&eb, buf->getCString());
+ delete buf;
}
if (privateDicts[0].hasStdHW) {
- sprintf(buf, "/StdHW [%g] def\n", privateDicts[0].stdHW);
- eexecWrite(&eb, buf);
+ buf = GString::format("/StdHW [{0:.4g}] def\n", privateDicts[0].stdHW);
+ eexecWrite(&eb, buf->getCString());
+ delete buf;
}
if (privateDicts[0].hasStdVW) {
- sprintf(buf, "/StdVW [%g] def\n", privateDicts[0].stdVW);
- eexecWrite(&eb, buf);
+ buf = GString::format("/StdVW [{0:.4g}] def\n", privateDicts[0].stdVW);
+ eexecWrite(&eb, buf->getCString());
+ delete buf;
}
if (privateDicts[0].nStemSnapH) {
eexecWrite(&eb, "/StemSnapH [");
for (i = 0; i < privateDicts[0].nStemSnapH; ++i) {
- sprintf(buf, "%s%g", i > 0 ? " " : "", privateDicts[0].stemSnapH[i]);
- eexecWrite(&eb, buf);
+ buf = GString::format("{0:s}{1:.4g}",
+ i > 0 ? " " : "", privateDicts[0].stemSnapH[i]);
+ eexecWrite(&eb, buf->getCString());
+ delete buf;
}
eexecWrite(&eb, "] def\n");
}
if (privateDicts[0].nStemSnapV) {
eexecWrite(&eb, "/StemSnapV [");
for (i = 0; i < privateDicts[0].nStemSnapV; ++i) {
- sprintf(buf, "%s%g", i > 0 ? " " : "", privateDicts[0].stemSnapV[i]);
- eexecWrite(&eb, buf);
+ buf = GString::format("{0:s}{1:.4g}",
+ i > 0 ? " " : "", privateDicts[0].stemSnapV[i]);
+ eexecWrite(&eb, buf->getCString());
+ delete buf;
}
eexecWrite(&eb, "] def\n");
}
if (privateDicts[0].hasForceBold) {
- sprintf(buf, "/ForceBold %s def\n",
- privateDicts[0].forceBold ? "true" : "false");
- eexecWrite(&eb, buf);
+ buf = GString::format("/ForceBold {0:s} def\n",
+ privateDicts[0].forceBold ? "true" : "false");
+ eexecWrite(&eb, buf->getCString());
+ delete buf;
}
if (privateDicts[0].forceBoldThreshold != 0) {
- sprintf(buf, "/ForceBoldThreshold %g def\n",
- privateDicts[0].forceBoldThreshold);
- eexecWrite(&eb, buf);
+ buf = GString::format("/ForceBoldThreshold {0:.4g} def\n",
+ privateDicts[0].forceBoldThreshold);
+ eexecWrite(&eb, buf->getCString());
+ delete buf;
}
if (privateDicts[0].languageGroup != 0) {
- sprintf(buf, "/LanguageGroup %d def\n", privateDicts[0].languageGroup);
- eexecWrite(&eb, buf);
+ buf = GString::format("/LanguageGroup {0:d} def\n",
+ privateDicts[0].languageGroup);
+ eexecWrite(&eb, buf->getCString());
+ delete buf;
}
if (privateDicts[0].expansionFactor != 0.06) {
- sprintf(buf, "/ExpansionFactor %g def\n", privateDicts[0].expansionFactor);
- eexecWrite(&eb, buf);
+ buf = GString::format("/ExpansionFactor {0:.4g} def\n",
+ privateDicts[0].expansionFactor);
+ eexecWrite(&eb, buf->getCString());
+ delete buf;
}
// set up subroutines
@@ -354,15 +398,17 @@ void FoFiType1C::convertToType1(char **newEncoding, GBool ascii,
}
// write the CharStrings
- sprintf(buf, "2 index /CharStrings %d dict dup begin\n", nGlyphs);
- eexecWrite(&eb, buf);
+ buf = GString::format("2 index /CharStrings {0:d} dict dup begin\n",
+ nGlyphs);
+ eexecWrite(&eb, buf->getCString());
+ delete buf;
for (i = 0; i < nGlyphs; ++i) {
ok = gTrue;
getIndexVal(&charStringsIdx, i, &val, &ok);
if (ok) {
- getString(charset[i], buf, &ok);
+ getString(charset[i], buf2, &ok);
if (ok) {
- eexecCvtGlyph(&eb, buf, val.pos, val.len, &subrIdx, &privateDicts[0]);
+ eexecCvtGlyph(&eb, buf2, val.pos, val.len, &subrIdx, &privateDicts[0]);
}
}
}
@@ -392,7 +438,8 @@ void FoFiType1C::convertToCIDType0(char *psName,
Type1CIndex subrIdx;
Type1CIndexVal val;
int nCIDs, gdBytes;
- char buf[512], buf2[512];
+ GString *buf;
+ char buf2[256];
GBool ok;
int gid, offset, n, i, j, k;
@@ -456,169 +503,204 @@ void FoFiType1C::convertToCIDType0(char *psName,
(*outputFunc)(outputStream, "/CIDSystemInfo 3 dict dup begin\n", 32);
if (topDict.registrySID > 0 && topDict.orderingSID > 0) {
ok = gTrue;
- getString(topDict.registrySID, buf, &ok);
+ getString(topDict.registrySID, buf2, &ok);
if (ok) {
(*outputFunc)(outputStream, " /Registry (", 13);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ (*outputFunc)(outputStream, buf2, strlen(buf2));
(*outputFunc)(outputStream, ") def\n", 6);
}
ok = gTrue;
- getString(topDict.orderingSID, buf, &ok);
+ getString(topDict.orderingSID, buf2, &ok);
if (ok) {
(*outputFunc)(outputStream, " /Ordering (", 13);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ (*outputFunc)(outputStream, buf2, strlen(buf2));
(*outputFunc)(outputStream, ") def\n", 6);
}
} else {
(*outputFunc)(outputStream, " /Registry (Adobe) def\n", 24);
(*outputFunc)(outputStream, " /Ordering (Identity) def\n", 27);
}
- sprintf(buf, " /Supplement %d def\n", topDict.supplement);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ buf = GString::format(" /Supplement {0:d} def\n", topDict.supplement);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
(*outputFunc)(outputStream, "end def\n", 8);
if (topDict.hasFontMatrix) {
- sprintf(buf, "/FontMatrix [%g %g %g %g %g %g] def\n",
- topDict.fontMatrix[0], topDict.fontMatrix[1],
- topDict.fontMatrix[2], topDict.fontMatrix[3],
- topDict.fontMatrix[4], topDict.fontMatrix[5]);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ buf = GString::format("/FontMatrix [{0:.8g} {1:.8g} {2:.8g} {3:.8g} {4:.8g} {5:.8g}] def\n",
+ topDict.fontMatrix[0], topDict.fontMatrix[1],
+ topDict.fontMatrix[2], topDict.fontMatrix[3],
+ topDict.fontMatrix[4], topDict.fontMatrix[5]);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
} else if (privateDicts[0].hasFontMatrix) {
(*outputFunc)(outputStream, "/FontMatrix [1 0 0 1 0 0] def\n", 30);
} else {
(*outputFunc)(outputStream,
"/FontMatrix [0.001 0 0 0.001 0 0] def\n", 38);
}
- sprintf(buf, "/FontBBox [%g %g %g %g] def\n",
- topDict.fontBBox[0], topDict.fontBBox[1],
- topDict.fontBBox[2], topDict.fontBBox[3]);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ buf = GString::format("/FontBBox [{0:.4g} {1:.4g} {2:.4g} {3:.4g}] def\n",
+ topDict.fontBBox[0], topDict.fontBBox[1],
+ topDict.fontBBox[2], topDict.fontBBox[3]);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
(*outputFunc)(outputStream, "/FontInfo 1 dict dup begin\n", 27);
(*outputFunc)(outputStream, " /FSType 8 def\n", 16);
(*outputFunc)(outputStream, "end def\n", 8);
// CIDFont-specific entries
- sprintf(buf, "/CIDCount %d def\n", nCIDs);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ buf = GString::format("/CIDCount {0:d} def\n", nCIDs);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
(*outputFunc)(outputStream, "/FDBytes 1 def\n", 15);
- sprintf(buf, "/GDBytes %d def\n", gdBytes);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ buf = GString::format("/GDBytes {0:d} def\n", gdBytes);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
(*outputFunc)(outputStream, "/CIDMapOffset 0 def\n", 20);
if (topDict.paintType != 0) {
- sprintf(buf, "/PaintType %d def\n", topDict.paintType);
- (*outputFunc)(outputStream, buf, strlen(buf));
- sprintf(buf, "/StrokeWidth %g def\n", topDict.strokeWidth);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ buf = GString::format("/PaintType {0:d} def\n", topDict.paintType);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
+ buf = GString::format("/StrokeWidth {0:.4g} def\n", topDict.strokeWidth);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
}
// FDArray entry
- sprintf(buf, "/FDArray %d array\n", nFDs);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ buf = GString::format("/FDArray {0:d} array\n", nFDs);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
for (i = 0; i < nFDs; ++i) {
- sprintf(buf, "dup %d 10 dict begin\n", i);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ buf = GString::format("dup {0:d} 10 dict begin\n", i);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
(*outputFunc)(outputStream, "/FontType 1 def\n", 16);
if (privateDicts[i].hasFontMatrix) {
- sprintf(buf, "/FontMatrix [%g %g %g %g %g %g] def\n",
- privateDicts[i].fontMatrix[0],
- privateDicts[i].fontMatrix[1],
- privateDicts[i].fontMatrix[2],
- privateDicts[i].fontMatrix[3],
- privateDicts[i].fontMatrix[4],
- privateDicts[i].fontMatrix[5]);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ buf = GString::format("/FontMatrix [{0:.8g} {1:.8g} {2:.8g} {3:.8g} {4:.8g} {5:.8g}] def\n",
+ privateDicts[i].fontMatrix[0],
+ privateDicts[i].fontMatrix[1],
+ privateDicts[i].fontMatrix[2],
+ privateDicts[i].fontMatrix[3],
+ privateDicts[i].fontMatrix[4],
+ privateDicts[i].fontMatrix[5]);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
} else {
(*outputFunc)(outputStream, "/FontMatrix [1 0 0 1 0 0] def\n", 30);
}
- sprintf(buf, "/PaintType %d def\n", topDict.paintType);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ buf = GString::format("/PaintType {0:d} def\n", topDict.paintType);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
(*outputFunc)(outputStream, "/Private 32 dict begin\n", 23);
if (privateDicts[i].nBlueValues) {
(*outputFunc)(outputStream, "/BlueValues [", 13);
for (j = 0; j < privateDicts[i].nBlueValues; ++j) {
- sprintf(buf, "%s%d", j > 0 ? " " : "", privateDicts[i].blueValues[j]);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ buf = GString::format("{0:s}{1:d}",
+ j > 0 ? " " : "", privateDicts[i].blueValues[j]);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
}
(*outputFunc)(outputStream, "] def\n", 6);
}
if (privateDicts[i].nOtherBlues) {
(*outputFunc)(outputStream, "/OtherBlues [", 13);
for (j = 0; j < privateDicts[i].nOtherBlues; ++j) {
- sprintf(buf, "%s%d", j > 0 ? " " : "", privateDicts[i].otherBlues[j]);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ buf = GString::format("{0:s}{1:d}",
+ j > 0 ? " " : "", privateDicts[i].otherBlues[j]);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
}
(*outputFunc)(outputStream, "] def\n", 6);
}
if (privateDicts[i].nFamilyBlues) {
(*outputFunc)(outputStream, "/FamilyBlues [", 14);
for (j = 0; j < privateDicts[i].nFamilyBlues; ++j) {
- sprintf(buf, "%s%d", j > 0 ? " " : "", privateDicts[i].familyBlues[j]);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ buf = GString::format("{0:s}{1:d}",
+ j > 0 ? " " : "",
+ privateDicts[i].familyBlues[j]);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
}
(*outputFunc)(outputStream, "] def\n", 6);
}
if (privateDicts[i].nFamilyOtherBlues) {
(*outputFunc)(outputStream, "/FamilyOtherBlues [", 19);
for (j = 0; j < privateDicts[i].nFamilyOtherBlues; ++j) {
- sprintf(buf, "%s%d", j > 0 ? " " : "",
- privateDicts[i].familyOtherBlues[j]);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ buf = GString::format("{0:s}{1:d}", j > 0 ? " " : "",
+ privateDicts[i].familyOtherBlues[j]);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
}
(*outputFunc)(outputStream, "] def\n", 6);
}
if (privateDicts[i].blueScale != 0.039625) {
- sprintf(buf, "/BlueScale %g def\n", privateDicts[i].blueScale);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ buf = GString::format("/BlueScale {0:.4g} def\n",
+ privateDicts[i].blueScale);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
}
if (privateDicts[i].blueShift != 7) {
- sprintf(buf, "/BlueShift %d def\n", privateDicts[i].blueShift);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ buf = GString::format("/BlueShift {0:d} def\n",
+ privateDicts[i].blueShift);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
}
if (privateDicts[i].blueFuzz != 1) {
- sprintf(buf, "/BlueFuzz %d def\n", privateDicts[i].blueFuzz);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ buf = GString::format("/BlueFuzz {0:d} def\n", privateDicts[i].blueFuzz);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
}
if (privateDicts[i].hasStdHW) {
- sprintf(buf, "/StdHW [%g] def\n", privateDicts[i].stdHW);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ buf = GString::format("/StdHW [{0:.4g}] def\n", privateDicts[i].stdHW);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
}
if (privateDicts[i].hasStdVW) {
- sprintf(buf, "/StdVW [%g] def\n", privateDicts[i].stdVW);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ buf = GString::format("/StdVW [{0:.4g}] def\n", privateDicts[i].stdVW);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
}
if (privateDicts[i].nStemSnapH) {
(*outputFunc)(outputStream, "/StemSnapH [", 12);
for (j = 0; j < privateDicts[i].nStemSnapH; ++j) {
- sprintf(buf, "%s%g", j > 0 ? " " : "", privateDicts[i].stemSnapH[j]);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ buf = GString::format("{0:s}{1:.4g}",
+ j > 0 ? " " : "", privateDicts[i].stemSnapH[j]);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
}
(*outputFunc)(outputStream, "] def\n", 6);
}
if (privateDicts[i].nStemSnapV) {
(*outputFunc)(outputStream, "/StemSnapV [", 12);
for (j = 0; j < privateDicts[i].nStemSnapV; ++j) {
- sprintf(buf, "%s%g", j > 0 ? " " : "", privateDicts[i].stemSnapV[j]);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ buf = GString::format("{0:s}{1:.4g}",
+ j > 0 ? " " : "", privateDicts[i].stemSnapV[j]);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
}
(*outputFunc)(outputStream, "] def\n", 6);
}
if (privateDicts[i].hasForceBold) {
- sprintf(buf, "/ForceBold %s def\n",
- privateDicts[i].forceBold ? "true" : "false");
- (*outputFunc)(outputStream, buf, strlen(buf));
+ buf = GString::format("/ForceBold {0:s} def\n",
+ privateDicts[i].forceBold ? "true" : "false");
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
}
if (privateDicts[i].forceBoldThreshold != 0) {
- sprintf(buf, "/ForceBoldThreshold %g def\n",
- privateDicts[i].forceBoldThreshold);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ buf = GString::format("/ForceBoldThreshold {0:.4g} def\n",
+ privateDicts[i].forceBoldThreshold);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
}
if (privateDicts[i].languageGroup != 0) {
- sprintf(buf, "/LanguageGroup %d def\n", privateDicts[i].languageGroup);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ buf = GString::format("/LanguageGroup {0:d} def\n",
+ privateDicts[i].languageGroup);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
}
if (privateDicts[i].expansionFactor != 0.06) {
- sprintf(buf, "/ExpansionFactor %g def\n",
- privateDicts[i].expansionFactor);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ buf = GString::format("/ExpansionFactor {0:.4g} def\n",
+ privateDicts[i].expansionFactor);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
}
(*outputFunc)(outputStream, "currentdict end def\n", 20);
(*outputFunc)(outputStream, "currentdict end put\n", 20);
@@ -627,26 +709,28 @@ void FoFiType1C::convertToCIDType0(char *psName,
// start the binary section
offset = (nCIDs + 1) * (1 + gdBytes);
- sprintf(buf, "(Hex) %d StartData\n",
- offset + charStrings->getLength());
- (*outputFunc)(outputStream, buf, strlen(buf));
+ buf = GString::format("(Hex) {0:d} StartData\n",
+ offset + charStrings->getLength());
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
// write the charstring offset (CIDMap) table
for (i = 0; i <= nCIDs; i += 6) {
for (j = 0; j < 6 && i+j <= nCIDs; ++j) {
if (i+j < nCIDs && cidMap[i+j] >= 0) {
- buf[0] = (char)fdSelect[cidMap[i+j]];
+ buf2[0] = (char)fdSelect[cidMap[i+j]];
} else {
- buf[0] = (char)0;
+ buf2[0] = (char)0;
}
n = offset + charStringOffsets[i+j];
for (k = gdBytes; k >= 1; --k) {
- buf[k] = (char)(n & 0xff);
+ buf2[k] = (char)(n & 0xff);
n >>= 8;
}
for (k = 0; k <= gdBytes; ++k) {
- sprintf(buf2, "%02x", buf[k] & 0xff);
- (*outputFunc)(outputStream, buf2, 2);
+ buf = GString::format("{0:02x}", buf2[k] & 0xff);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
}
}
(*outputFunc)(outputStream, "\n", 1);
@@ -656,8 +740,9 @@ void FoFiType1C::convertToCIDType0(char *psName,
n = charStrings->getLength();
for (i = 0; i < n; i += 32) {
for (j = 0; j < 32 && i+j < n; ++j) {
- sprintf(buf, "%02x", charStrings->getChar(i+j) & 0xff);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ buf = GString::format("{0:02x}", charStrings->getChar(i+j) & 0xff);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
}
if (i + 32 >= n) {
(*outputFunc)(outputStream, ">", 1);
@@ -677,7 +762,7 @@ void FoFiType1C::convertToType0(char *psName,
Type1CIndex subrIdx;
Type1CIndexVal val;
int nCIDs;
- char buf[512];
+ GString *buf;
Type1CEexecBuf eb;
GBool ok;
int fd, i, j, k;
@@ -702,9 +787,9 @@ void FoFiType1C::convertToType0(char *psName,
//~ this assumes that all CIDs in this block have the same FD --
//~ to handle multiple FDs correctly, need to somehow divide the
- //~ font up by FD
+ //~ font up by FD; as a kludge we ignore CID 0, which is .notdef
fd = 0;
- for (j = 0; j < 256 && i+j < nCIDs; ++j) {
+ for (j = i==0 ? 1 : 0; j < 256 && i+j < nCIDs; ++j) {
if (cidMap[i+j] >= 0) {
fd = fdSelect[cidMap[i+j]];
break;
@@ -715,42 +800,50 @@ void FoFiType1C::convertToType0(char *psName,
(*outputFunc)(outputStream, "16 dict begin\n", 14);
(*outputFunc)(outputStream, "/FontName /", 11);
(*outputFunc)(outputStream, psName, strlen(psName));
- sprintf(buf, "_%02x def\n", i >> 8);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ buf = GString::format("_{0:02x} def\n", i >> 8);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
(*outputFunc)(outputStream, "/FontType 1 def\n", 16);
if (privateDicts[fd].hasFontMatrix) {
- sprintf(buf, "/FontMatrix [%g %g %g %g %g %g] def\n",
- privateDicts[fd].fontMatrix[0],
- privateDicts[fd].fontMatrix[1],
- privateDicts[fd].fontMatrix[2],
- privateDicts[fd].fontMatrix[3],
- privateDicts[fd].fontMatrix[4],
- privateDicts[fd].fontMatrix[5]);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ buf = GString::format("/FontMatrix [{0:.8g} {1:.8g} {2:.8g} {3:.8g} {4:.8g} {5:.8g}] def\n",
+ privateDicts[fd].fontMatrix[0],
+ privateDicts[fd].fontMatrix[1],
+ privateDicts[fd].fontMatrix[2],
+ privateDicts[fd].fontMatrix[3],
+ privateDicts[fd].fontMatrix[4],
+ privateDicts[fd].fontMatrix[5]);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
} else if (topDict.hasFontMatrix) {
(*outputFunc)(outputStream, "/FontMatrix [1 0 0 1 0 0] def\n", 30);
} else {
(*outputFunc)(outputStream,
"/FontMatrix [0.001 0 0 0.001 0 0] def\n", 38);
}
- sprintf(buf, "/FontBBox [%g %g %g %g] def\n",
- topDict.fontBBox[0], topDict.fontBBox[1],
- topDict.fontBBox[2], topDict.fontBBox[3]);
- (*outputFunc)(outputStream, buf, strlen(buf));
- sprintf(buf, "/PaintType %d def\n", topDict.paintType);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ buf = GString::format("/FontBBox [{0:.4g} {1:.4g} {2:.4g} {3:.4g}] def\n",
+ topDict.fontBBox[0], topDict.fontBBox[1],
+ topDict.fontBBox[2], topDict.fontBBox[3]);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
+ buf = GString::format("/PaintType {0:d} def\n", topDict.paintType);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
if (topDict.paintType != 0) {
- sprintf(buf, "/StrokeWidth %g def\n", topDict.strokeWidth);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ buf = GString::format("/StrokeWidth {0:.4g} def\n", topDict.strokeWidth);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
}
(*outputFunc)(outputStream, "/Encoding 256 array\n", 20);
for (j = 0; j < 256 && i+j < nCIDs; ++j) {
- sprintf(buf, "dup %d /c%02x put\n", j, j);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ buf = GString::format("dup {0:d} /c{1:02x} put\n", j, j);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
}
if (j < 256) {
- sprintf(buf, "%d 1 255 { 1 index exch /.notdef put } for\n", j);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ buf = GString::format("{0:d} 1 255 {{ 1 index exch /.notdef put }} for\n",
+ j);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
}
(*outputFunc)(outputStream, "readonly def\n", 13);
(*outputFunc)(outputStream, "currentdict end\n", 16);
@@ -775,91 +868,116 @@ void FoFiType1C::convertToType0(char *psName,
if (privateDicts[fd].nBlueValues) {
eexecWrite(&eb, "/BlueValues [");
for (k = 0; k < privateDicts[fd].nBlueValues; ++k) {
- sprintf(buf, "%s%d", k > 0 ? " " : "", privateDicts[fd].blueValues[k]);
- eexecWrite(&eb, buf);
+ buf = GString::format("{0:s}{1:d}",
+ k > 0 ? " " : "",
+ privateDicts[fd].blueValues[k]);
+ eexecWrite(&eb, buf->getCString());
+ delete buf;
}
eexecWrite(&eb, "] def\n");
}
if (privateDicts[fd].nOtherBlues) {
eexecWrite(&eb, "/OtherBlues [");
for (k = 0; k < privateDicts[fd].nOtherBlues; ++k) {
- sprintf(buf, "%s%d", k > 0 ? " " : "", privateDicts[fd].otherBlues[k]);
- eexecWrite(&eb, buf);
+ buf = GString::format("{0:s}{1:d}",
+ k > 0 ? " " : "",
+ privateDicts[fd].otherBlues[k]);
+ eexecWrite(&eb, buf->getCString());
+ delete buf;
}
eexecWrite(&eb, "] def\n");
}
if (privateDicts[fd].nFamilyBlues) {
eexecWrite(&eb, "/FamilyBlues [");
for (k = 0; k < privateDicts[fd].nFamilyBlues; ++k) {
- sprintf(buf, "%s%d", k > 0 ? " " : "",
- privateDicts[fd].familyBlues[k]);
- eexecWrite(&eb, buf);
+ buf = GString::format("{0:s}{1:d}", k > 0 ? " " : "",
+ privateDicts[fd].familyBlues[k]);
+ eexecWrite(&eb, buf->getCString());
+ delete buf;
}
eexecWrite(&eb, "] def\n");
}
if (privateDicts[fd].nFamilyOtherBlues) {
eexecWrite(&eb, "/FamilyOtherBlues [");
for (k = 0; k < privateDicts[fd].nFamilyOtherBlues; ++k) {
- sprintf(buf, "%s%d", k > 0 ? " " : "",
- privateDicts[fd].familyOtherBlues[k]);
- eexecWrite(&eb, buf);
+ buf = GString::format("{0:s}{1:d}", k > 0 ? " " : "",
+ privateDicts[fd].familyOtherBlues[k]);
+ eexecWrite(&eb, buf->getCString());
+ delete buf;
}
eexecWrite(&eb, "] def\n");
}
if (privateDicts[fd].blueScale != 0.039625) {
- sprintf(buf, "/BlueScale %g def\n", privateDicts[fd].blueScale);
- eexecWrite(&eb, buf);
+ buf = GString::format("/BlueScale {0:.4g} def\n",
+ privateDicts[fd].blueScale);
+ eexecWrite(&eb, buf->getCString());
+ delete buf;
}
if (privateDicts[fd].blueShift != 7) {
- sprintf(buf, "/BlueShift %d def\n", privateDicts[fd].blueShift);
- eexecWrite(&eb, buf);
+ buf = GString::format("/BlueShift {0:d} def\n",
+ privateDicts[fd].blueShift);
+ eexecWrite(&eb, buf->getCString());
+ delete buf;
}
if (privateDicts[fd].blueFuzz != 1) {
- sprintf(buf, "/BlueFuzz %d def\n", privateDicts[fd].blueFuzz);
- eexecWrite(&eb, buf);
+ buf = GString::format("/BlueFuzz {0:d} def\n",
+ privateDicts[fd].blueFuzz);
+ eexecWrite(&eb, buf->getCString());
+ delete buf;
}
if (privateDicts[fd].hasStdHW) {
- sprintf(buf, "/StdHW [%g] def\n", privateDicts[fd].stdHW);
- eexecWrite(&eb, buf);
+ buf = GString::format("/StdHW [{0:.4g}] def\n", privateDicts[fd].stdHW);
+ eexecWrite(&eb, buf->getCString());
+ delete buf;
}
if (privateDicts[fd].hasStdVW) {
- sprintf(buf, "/StdVW [%g] def\n", privateDicts[fd].stdVW);
- eexecWrite(&eb, buf);
+ buf = GString::format("/StdVW [{0:.4g}] def\n", privateDicts[fd].stdVW);
+ eexecWrite(&eb, buf->getCString());
+ delete buf;
}
if (privateDicts[fd].nStemSnapH) {
eexecWrite(&eb, "/StemSnapH [");
for (k = 0; k < privateDicts[fd].nStemSnapH; ++k) {
- sprintf(buf, "%s%g", k > 0 ? " " : "", privateDicts[fd].stemSnapH[k]);
- eexecWrite(&eb, buf);
+ buf = GString::format("{0:s}{1:.4g}",
+ k > 0 ? " " : "", privateDicts[fd].stemSnapH[k]);
+ eexecWrite(&eb, buf->getCString());
+ delete buf;
}
eexecWrite(&eb, "] def\n");
}
if (privateDicts[fd].nStemSnapV) {
eexecWrite(&eb, "/StemSnapV [");
for (k = 0; k < privateDicts[fd].nStemSnapV; ++k) {
- sprintf(buf, "%s%g", k > 0 ? " " : "", privateDicts[fd].stemSnapV[k]);
- eexecWrite(&eb, buf);
+ buf = GString::format("{0:s}{1:.4g}",
+ k > 0 ? " " : "", privateDicts[fd].stemSnapV[k]);
+ eexecWrite(&eb, buf->getCString());
+ delete buf;
}
eexecWrite(&eb, "] def\n");
}
if (privateDicts[fd].hasForceBold) {
- sprintf(buf, "/ForceBold %s def\n",
- privateDicts[fd].forceBold ? "true" : "false");
- eexecWrite(&eb, buf);
+ buf = GString::format("/ForceBold {0:s} def\n",
+ privateDicts[fd].forceBold ? "true" : "false");
+ eexecWrite(&eb, buf->getCString());
+ delete buf;
}
if (privateDicts[fd].forceBoldThreshold != 0) {
- sprintf(buf, "/ForceBoldThreshold %g def\n",
- privateDicts[fd].forceBoldThreshold);
- eexecWrite(&eb, buf);
+ buf = GString::format("/ForceBoldThreshold {0:.4g} def\n",
+ privateDicts[fd].forceBoldThreshold);
+ eexecWrite(&eb, buf->getCString());
+ delete buf;
}
if (privateDicts[fd].languageGroup != 0) {
- sprintf(buf, "/LanguageGroup %d def\n", privateDicts[fd].languageGroup);
- eexecWrite(&eb, buf);
+ buf = GString::format("/LanguageGroup {0:d} def\n",
+ privateDicts[fd].languageGroup);
+ eexecWrite(&eb, buf->getCString());
+ delete buf;
}
if (privateDicts[fd].expansionFactor != 0.06) {
- sprintf(buf, "/ExpansionFactor %g def\n",
- privateDicts[fd].expansionFactor);
- eexecWrite(&eb, buf);
+ buf = GString::format("/ExpansionFactor {0:.4g} def\n",
+ privateDicts[fd].expansionFactor);
+ eexecWrite(&eb, buf->getCString());
+ delete buf;
}
// set up the subroutines
@@ -870,8 +988,7 @@ void FoFiType1C::convertToType0(char *psName,
}
// start the CharStrings
- sprintf(buf, "2 index /CharStrings 256 dict dup begin\n");
- eexecWrite(&eb, buf);
+ eexecWrite(&eb, "2 index /CharStrings 256 dict dup begin\n");
// write the .notdef CharString
ok = gTrue;
@@ -887,9 +1004,10 @@ void FoFiType1C::convertToType0(char *psName,
ok = gTrue;
getIndexVal(&charStringsIdx, cidMap[i+j], &val, &ok);
if (ok) {
- sprintf(buf, "c%02x", j);
- eexecCvtGlyph(&eb, buf, val.pos, val.len,
+ buf = GString::format("c{0:02x}", j);
+ eexecCvtGlyph(&eb, buf->getCString(), val.pos, val.len,
&subrIdx, &privateDicts[fd]);
+ delete buf;
}
}
}
@@ -917,27 +1035,30 @@ void FoFiType1C::convertToType0(char *psName,
(*outputFunc)(outputStream, " def\n", 5);
(*outputFunc)(outputStream, "/FontType 0 def\n", 16);
if (topDict.hasFontMatrix) {
- sprintf(buf, "/FontMatrix [%g %g %g %g %g %g] def\n",
- topDict.fontMatrix[0], topDict.fontMatrix[1],
- topDict.fontMatrix[2], topDict.fontMatrix[3],
- topDict.fontMatrix[4], topDict.fontMatrix[5]);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ buf = GString::format("/FontMatrix [{0:.8g} {1:.8g} {2:.8g} {3:.8g} {4:.8g} {5:.8g}] def\n",
+ topDict.fontMatrix[0], topDict.fontMatrix[1],
+ topDict.fontMatrix[2], topDict.fontMatrix[3],
+ topDict.fontMatrix[4], topDict.fontMatrix[5]);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
} else {
(*outputFunc)(outputStream, "/FontMatrix [1 0 0 1 0 0] def\n", 30);
}
(*outputFunc)(outputStream, "/FMapType 2 def\n", 16);
(*outputFunc)(outputStream, "/Encoding [\n", 12);
for (i = 0; i < nCIDs; i += 256) {
- sprintf(buf, "%d\n", i >> 8);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ buf = GString::format("{0:d}\n", i >> 8);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
}
(*outputFunc)(outputStream, "] def\n", 6);
(*outputFunc)(outputStream, "/FDepVector [\n", 14);
for (i = 0; i < nCIDs; i += 256) {
(*outputFunc)(outputStream, "/", 1);
(*outputFunc)(outputStream, psName, strlen(psName));
- sprintf(buf, "_%02x findfont\n", i >> 8);
- (*outputFunc)(outputStream, buf, strlen(buf));
+ buf = GString::format("_{0:02x} findfont\n", i >> 8);
+ (*outputFunc)(outputStream, buf->getCString(), buf->getLength());
+ delete buf;
}
(*outputFunc)(outputStream, "] def\n", 6);
(*outputFunc)(outputStream, "FontName currentdict end definefont pop\n", 40);
@@ -949,15 +1070,16 @@ void FoFiType1C::eexecCvtGlyph(Type1CEexecBuf *eb, char *glyphName,
int offset, int nBytes,
Type1CIndex *subrIdx,
Type1CPrivateDict *pDict) {
- char buf[512];
+ GString *buf;
GString *charBuf;
// generate the charstring
charBuf = new GString();
cvtGlyph(offset, nBytes, charBuf, subrIdx, pDict, gTrue);
- sprintf(buf, "/%s %d RD ", glyphName, charBuf->getLength());
- eexecWrite(eb, buf);
+ buf = GString::format("/{0:s} {1:d} RD ", glyphName, charBuf->getLength());
+ eexecWrite(eb, buf->getCString());
+ delete buf;
eexecWriteCharstring(eb, (Guchar *)charBuf->getCString(),
charBuf->getLength());
eexecWrite(eb, " ND\n");
diff --git a/Build/source/libs/xpdf/fofi/FoFiType1C.h b/Build/source/libs/xpdf/fofi/FoFiType1C.h
index 62649ed949d..eec27555494 100644
--- a/Build/source/libs/xpdf/fofi/FoFiType1C.h
+++ b/Build/source/libs/xpdf/fofi/FoFiType1C.h
@@ -157,8 +157,9 @@ public:
// file. This is only useful with 8-bit fonts. If <newEncoding> is
// not NULL, it will be used in place of the encoding in the Type 1C
// font. If <ascii> is true the eexec section will be hex-encoded,
- // otherwise it will be left as binary data.
- void convertToType1(char **newEncoding, GBool ascii,
+ // otherwise it will be left as binary data. If <psName> is non-NULL,
+ // it will be used as the PostScript font name.
+ void convertToType1(char *psName, char **newEncoding, GBool ascii,
FoFiOutputFunc outputFunc, void *outputStream);
// Convert to a Type 0 CIDFont, suitable for embedding in a
diff --git a/Build/source/libs/xpdf/goo/FixedPoint.cc b/Build/source/libs/xpdf/goo/FixedPoint.cc
index f969959a66b..47c2834a34b 100644
--- a/Build/source/libs/xpdf/goo/FixedPoint.cc
+++ b/Build/source/libs/xpdf/goo/FixedPoint.cc
@@ -18,13 +18,15 @@
#include "FixedPoint.h"
+#define ln2 ((FixedPoint)0.69314718)
+
FixedPoint FixedPoint::sqrt(FixedPoint x) {
FixedPoint y0, y1, z;
if (x.val <= 0) {
y1.val = 0;
} else {
- y1.val = x.val >> 1;
+ y1.val = x.val == 1 ? 2 : x.val >> 1;
do {
y0.val = y1.val;
z = x / y0;
@@ -34,10 +36,9 @@ FixedPoint FixedPoint::sqrt(FixedPoint x) {
return y1;
}
-//~ this is not very accurate
FixedPoint FixedPoint::pow(FixedPoint x, FixedPoint y) {
FixedPoint t, t2, lnx0, lnx, z0, z;
- int d, i;
+ int d, n, i;
if (y.val <= 0) {
z.val = 0;
@@ -56,6 +57,8 @@ FixedPoint FixedPoint::pow(FixedPoint x, FixedPoint y) {
lnx.val <<= 1;
t = y * lnx;
// exp(y * ln(x))
+ n = floor(t / ln2);
+ t -= ln2 * n;
t2 = t;
d = 1;
i = 1;
@@ -67,6 +70,11 @@ FixedPoint FixedPoint::pow(FixedPoint x, FixedPoint y) {
++i;
d *= i;
} while (::abs(z.val - z0.val) > 2 && d < (1 << fixptShift));
+ if (n >= 0) {
+ z.val <<= n;
+ } else if (n < 0) {
+ z.val >>= -n;
+ }
}
return z;
}
@@ -92,4 +100,19 @@ int FixedPoint::div(int x, int y) {
#endif
}
+GBool FixedPoint::divCheck(FixedPoint x, FixedPoint y, FixedPoint *result) {
+#if 1 //~tmp
+ FixPtInt64 z;
+
+ z = ((FixPtInt64)x.val << fixptShift) / y.val;
+ if ((z == 0 && x != 0) ||
+ z >= ((FixPtInt64)1 << 31) || z < -((FixPtInt64)1 << 31)) {
+ return gFalse;
+ }
+ result->val = z;
+ return gTrue;
+#else
+#endif
+}
+
#endif // USE_FIXEDPOINT
diff --git a/Build/source/libs/xpdf/goo/FixedPoint.h b/Build/source/libs/xpdf/goo/FixedPoint.h
index 7e89018edb9..abcb212101d 100644
--- a/Build/source/libs/xpdf/goo/FixedPoint.h
+++ b/Build/source/libs/xpdf/goo/FixedPoint.h
@@ -21,6 +21,7 @@
#include <stdio.h>
#include <stdlib.h>
+#include "gtypes.h"
#define fixptShift 16
#define fixptMaskL ((1 << fixptShift) - 1)
@@ -135,6 +136,10 @@ public:
static FixedPoint pow(FixedPoint x, FixedPoint y);
+ // Compute *result = x/y; return false if there is an underflow or
+ // overflow.
+ static GBool divCheck(FixedPoint x, FixedPoint y, FixedPoint *result);
+
private:
static FixedPoint make(int valA) { FixedPoint x; x.val = valA; return x; }
diff --git a/Build/source/libs/xpdf/goo/GString.cc b/Build/source/libs/xpdf/goo/GString.cc
index 049dcf38dc9..de280ad9842 100644
--- a/Build/source/libs/xpdf/goo/GString.cc
+++ b/Build/source/libs/xpdf/goo/GString.cc
@@ -18,14 +18,66 @@
#include <stddef.h>
#include <string.h>
#include <ctype.h>
-#include "gtypes.h"
+#include <math.h>
+#include "gmem.h"
#include "GString.h"
+//------------------------------------------------------------------------
+
+union GStringFormatArg {
+ int i;
+ Guint ui;
+ long l;
+ Gulong ul;
+ double f;
+ char c;
+ char *s;
+ GString *gs;
+};
+
+enum GStringFormatType {
+ fmtIntDecimal,
+ fmtIntHex,
+ fmtIntOctal,
+ fmtIntBinary,
+ fmtUIntDecimal,
+ fmtUIntHex,
+ fmtUIntOctal,
+ fmtUIntBinary,
+ fmtLongDecimal,
+ fmtLongHex,
+ fmtLongOctal,
+ fmtLongBinary,
+ fmtULongDecimal,
+ fmtULongHex,
+ fmtULongOctal,
+ fmtULongBinary,
+ fmtDouble,
+ fmtDoubleTrim,
+ fmtChar,
+ fmtString,
+ fmtGString,
+ fmtSpace
+};
+
+static char *formatStrings[] = {
+ "d", "x", "o", "b", "ud", "ux", "uo", "ub",
+ "ld", "lx", "lo", "lb", "uld", "ulx", "ulo", "ulb",
+ "f", "g",
+ "c",
+ "s",
+ "t",
+ "w",
+ NULL
+};
+
+//------------------------------------------------------------------------
+
static inline int size(int len) {
int delta;
-
- delta = len < 256 ? 7 : 255;
- return ((len + 1) + delta) & ~delta;
+ for (delta = 8; delta < len && delta < 0x100000; delta <<= 1) ;
+ // this is ((len + 1) + (delta - 1)) & ~(delta - 1)
+ return (len + delta) & ~(delta - 1);
}
inline void GString::resize(int length1) {
@@ -92,28 +144,30 @@ GString::GString(GString *str1, GString *str2) {
GString *GString::fromInt(int x) {
char buf[24]; // enough space for 64-bit ints plus a little extra
- GBool neg;
- Guint y;
- int i;
+ char *p;
+ int len;
- i = 24;
- if (x == 0) {
- buf[--i] = '0';
- } else {
- if ((neg = x < 0)) {
- y = (Guint)-x;
- } else {
- y = (Guint)x;
- }
- while (i > 0 && y > 0) {
- buf[--i] = '0' + y % 10;
- y /= 10;
- }
- if (neg && i > 0) {
- buf[--i] = '-';
- }
- }
- return new GString(buf + i, 24 - i);
+ formatInt(x, buf, sizeof(buf), gFalse, 0, 10, &p, &len);
+ return new GString(p, len);
+}
+
+GString *GString::format(char *fmt, ...) {
+ va_list argList;
+ GString *s;
+
+ s = new GString();
+ va_start(argList, fmt);
+ s->appendfv(fmt, argList);
+ va_end(argList);
+ return s;
+}
+
+GString *GString::formatv(char *fmt, va_list argList) {
+ GString *s;
+
+ s = new GString();
+ s->appendfv(fmt, argList);
+ return s;
}
GString::~GString() {
@@ -159,6 +213,351 @@ GString *GString::append(const char *str, int lengthA) {
return this;
}
+GString *GString::appendf(char *fmt, ...) {
+ va_list argList;
+
+ va_start(argList, fmt);
+ appendfv(fmt, argList);
+ va_end(argList);
+ return this;
+}
+
+GString *GString::appendfv(char *fmt, va_list argList) {
+ GStringFormatArg *args;
+ int argsLen, argsSize;
+ GStringFormatArg arg;
+ int idx, width, prec;
+ GBool reverseAlign, zeroFill;
+ GStringFormatType ft;
+ char buf[65];
+ int len, i;
+ char *p0, *p1, *str;
+
+ argsLen = 0;
+ argsSize = 8;
+ args = (GStringFormatArg *)gmallocn(argsSize, sizeof(GStringFormatArg));
+
+ p0 = fmt;
+ while (*p0) {
+ if (*p0 == '{') {
+ ++p0;
+ if (*p0 == '{') {
+ ++p0;
+ append('{');
+ } else {
+
+ // parse the format string
+ if (!(*p0 >= '0' && *p0 <= '9')) {
+ break;
+ }
+ idx = *p0 - '0';
+ for (++p0; *p0 >= '0' && *p0 <= '9'; ++p0) {
+ idx = 10 * idx + (*p0 - '0');
+ }
+ if (*p0 != ':') {
+ break;
+ }
+ ++p0;
+ if (*p0 == '-') {
+ reverseAlign = gTrue;
+ ++p0;
+ } else {
+ reverseAlign = gFalse;
+ }
+ width = 0;
+ zeroFill = *p0 == '0';
+ for (; *p0 >= '0' && *p0 <= '9'; ++p0) {
+ width = 10 * width + (*p0 - '0');
+ }
+ if (*p0 == '.') {
+ ++p0;
+ prec = 0;
+ for (; *p0 >= '0' && *p0 <= '9'; ++p0) {
+ prec = 10 * prec + (*p0 - '0');
+ }
+ } else {
+ prec = 0;
+ }
+ for (ft = (GStringFormatType)0;
+ formatStrings[ft];
+ ft = (GStringFormatType)(ft + 1)) {
+ if (!strncmp(p0, formatStrings[ft], strlen(formatStrings[ft]))) {
+ break;
+ }
+ }
+ if (!formatStrings[ft]) {
+ break;
+ }
+ p0 += strlen(formatStrings[ft]);
+ if (*p0 != '}') {
+ break;
+ }
+ ++p0;
+
+ // fetch the argument
+ if (idx > argsLen) {
+ break;
+ }
+ if (idx == argsLen) {
+ if (argsLen == argsSize) {
+ argsSize *= 2;
+ args = (GStringFormatArg *)greallocn(args, argsSize,
+ sizeof(GStringFormatArg));
+ }
+ switch (ft) {
+ case fmtIntDecimal:
+ case fmtIntHex:
+ case fmtIntOctal:
+ case fmtIntBinary:
+ case fmtSpace:
+ args[argsLen].i = va_arg(argList, int);
+ break;
+ case fmtUIntDecimal:
+ case fmtUIntHex:
+ case fmtUIntOctal:
+ case fmtUIntBinary:
+ args[argsLen].ui = va_arg(argList, Guint);
+ break;
+ case fmtLongDecimal:
+ case fmtLongHex:
+ case fmtLongOctal:
+ case fmtLongBinary:
+ args[argsLen].l = va_arg(argList, long);
+ break;
+ case fmtULongDecimal:
+ case fmtULongHex:
+ case fmtULongOctal:
+ case fmtULongBinary:
+ args[argsLen].ul = va_arg(argList, Gulong);
+ break;
+ case fmtDouble:
+ case fmtDoubleTrim:
+ args[argsLen].f = va_arg(argList, double);
+ break;
+ case fmtChar:
+ args[argsLen].c = (char)va_arg(argList, int);
+ break;
+ case fmtString:
+ args[argsLen].s = va_arg(argList, char *);
+ break;
+ case fmtGString:
+ args[argsLen].gs = va_arg(argList, GString *);
+ break;
+ }
+ ++argsLen;
+ }
+
+ // format the argument
+ arg = args[idx];
+ switch (ft) {
+ case fmtIntDecimal:
+ formatInt(arg.i, buf, sizeof(buf), zeroFill, width, 10, &str, &len);
+ break;
+ case fmtIntHex:
+ formatInt(arg.i, buf, sizeof(buf), zeroFill, width, 16, &str, &len);
+ break;
+ case fmtIntOctal:
+ formatInt(arg.i, buf, sizeof(buf), zeroFill, width, 8, &str, &len);
+ break;
+ case fmtIntBinary:
+ formatInt(arg.i, buf, sizeof(buf), zeroFill, width, 2, &str, &len);
+ break;
+ case fmtUIntDecimal:
+ formatUInt(arg.ui, buf, sizeof(buf), zeroFill, width, 10,
+ &str, &len);
+ break;
+ case fmtUIntHex:
+ formatUInt(arg.ui, buf, sizeof(buf), zeroFill, width, 16,
+ &str, &len);
+ break;
+ case fmtUIntOctal:
+ formatUInt(arg.ui, buf, sizeof(buf), zeroFill, width, 8, &str, &len);
+ break;
+ case fmtUIntBinary:
+ formatUInt(arg.ui, buf, sizeof(buf), zeroFill, width, 2, &str, &len);
+ break;
+ case fmtLongDecimal:
+ formatInt(arg.l, buf, sizeof(buf), zeroFill, width, 10, &str, &len);
+ break;
+ case fmtLongHex:
+ formatInt(arg.l, buf, sizeof(buf), zeroFill, width, 16, &str, &len);
+ break;
+ case fmtLongOctal:
+ formatInt(arg.l, buf, sizeof(buf), zeroFill, width, 8, &str, &len);
+ break;
+ case fmtLongBinary:
+ formatInt(arg.l, buf, sizeof(buf), zeroFill, width, 2, &str, &len);
+ break;
+ case fmtULongDecimal:
+ formatUInt(arg.ul, buf, sizeof(buf), zeroFill, width, 10,
+ &str, &len);
+ break;
+ case fmtULongHex:
+ formatUInt(arg.ul, buf, sizeof(buf), zeroFill, width, 16,
+ &str, &len);
+ break;
+ case fmtULongOctal:
+ formatUInt(arg.ul, buf, sizeof(buf), zeroFill, width, 8, &str, &len);
+ break;
+ case fmtULongBinary:
+ formatUInt(arg.ul, buf, sizeof(buf), zeroFill, width, 2, &str, &len);
+ break;
+ case fmtDouble:
+ formatDouble(arg.f, buf, sizeof(buf), prec, gFalse, &str, &len);
+ break;
+ case fmtDoubleTrim:
+ formatDouble(arg.f, buf, sizeof(buf), prec, gTrue, &str, &len);
+ break;
+ case fmtChar:
+ buf[0] = arg.c;
+ str = buf;
+ len = 1;
+ reverseAlign = !reverseAlign;
+ break;
+ case fmtString:
+ str = arg.s;
+ len = strlen(str);
+ reverseAlign = !reverseAlign;
+ break;
+ case fmtGString:
+ str = arg.gs->getCString();
+ len = arg.gs->getLength();
+ reverseAlign = !reverseAlign;
+ break;
+ case fmtSpace:
+ str = buf;
+ len = 0;
+ width = arg.i;
+ break;
+ }
+
+ // append the formatted arg, handling width and alignment
+ if (!reverseAlign && len < width) {
+ for (i = len; i < width; ++i) {
+ append(' ');
+ }
+ }
+ append(str, len);
+ if (reverseAlign && len < width) {
+ for (i = len; i < width; ++i) {
+ append(' ');
+ }
+ }
+ }
+
+ } else if (*p0 == '}') {
+ ++p0;
+ if (*p0 == '}') {
+ ++p0;
+ }
+ append('}');
+
+ } else {
+ for (p1 = p0 + 1; *p1 && *p1 != '{' && *p1 != '}'; ++p1) ;
+ append(p0, p1 - p0);
+ p0 = p1;
+ }
+ }
+
+ gfree(args);
+ return this;
+}
+
+void GString::formatInt(long x, char *buf, int bufSize,
+ GBool zeroFill, int width, int base,
+ char **p, int *len) {
+ static char vals[17] = "0123456789abcdef";
+ GBool neg;
+ int start, i, j;
+
+ i = bufSize;
+ if ((neg = x < 0)) {
+ x = -x;
+ }
+ start = neg ? 1 : 0;
+ if (x == 0) {
+ buf[--i] = '0';
+ } else {
+ while (i > start && x) {
+ buf[--i] = vals[x % base];
+ x /= base;
+ }
+ }
+ if (zeroFill) {
+ for (j = bufSize - i; i > start && j < width - start; ++j) {
+ buf[--i] = '0';
+ }
+ }
+ if (neg) {
+ buf[--i] = '-';
+ }
+ *p = buf + i;
+ *len = bufSize - i;
+}
+
+void GString::formatUInt(Gulong x, char *buf, int bufSize,
+ GBool zeroFill, int width, int base,
+ char **p, int *len) {
+ static char vals[17] = "0123456789abcdef";
+ int i, j;
+
+ i = bufSize;
+ if (x == 0) {
+ buf[--i] = '0';
+ } else {
+ while (i > 0 && x) {
+ buf[--i] = vals[x % base];
+ x /= base;
+ }
+ }
+ if (zeroFill) {
+ for (j = bufSize - i; i > 0 && j < width; ++j) {
+ buf[--i] = '0';
+ }
+ }
+ *p = buf + i;
+ *len = bufSize - i;
+}
+
+void GString::formatDouble(double x, char *buf, int bufSize, int prec,
+ GBool trim, char **p, int *len) {
+ GBool neg, started;
+ double x2;
+ int d, i, j;
+
+ if ((neg = x < 0)) {
+ x = -x;
+ }
+ x = floor(x * pow(10.0, prec) + 0.5);
+ i = bufSize;
+ started = !trim;
+ for (j = 0; j < prec && i > 1; ++j) {
+ x2 = floor(0.1 * (x + 0.5));
+ d = (int)floor(x - 10 * x2 + 0.5);
+ if (started || d != 0) {
+ buf[--i] = '0' + d;
+ started = gTrue;
+ }
+ x = x2;
+ }
+ if (i > 1 && started) {
+ buf[--i] = '.';
+ }
+ if (i > 1) {
+ do {
+ x2 = floor(0.1 * (x + 0.5));
+ d = (int)floor(x - 10 * x2 + 0.5);
+ buf[--i] = '0' + d;
+ x = x2;
+ } while (i > 1 && x);
+ }
+ if (neg) {
+ buf[--i] = '-';
+ }
+ *p = buf + i;
+ *len = bufSize - i;
+}
+
GString *GString::insert(int i, char c) {
int j;
diff --git a/Build/source/libs/xpdf/goo/GString.h b/Build/source/libs/xpdf/goo/GString.h
index f4ff7c6a9ee..dd22e2d8f6b 100644
--- a/Build/source/libs/xpdf/goo/GString.h
+++ b/Build/source/libs/xpdf/goo/GString.h
@@ -17,6 +17,9 @@
#pragma interface
#endif
+#include <stdarg.h>
+#include "gtypes.h"
+
class GString {
public:
@@ -43,6 +46,30 @@ public:
// Convert an integer to a string.
static GString *fromInt(int x);
+ // Create a formatted string. Similar to printf, but without the
+ // string overflow issues. Formatting elements consist of:
+ // {<arg>:[<width>][.<precision>]<type>}
+ // where:
+ // - <arg> is the argument number (arg 0 is the first argument
+ // following the format string) -- NB: args must be first used in
+ // order; they can be reused in any order
+ // - <width> is the field width -- negative to reverse the alignment;
+ // starting with a leading zero to zero-fill (for integers)
+ // - <precision> is the number of digits to the right of the decimal
+ // point (for floating point numbers)
+ // - <type> is one of:
+ // d, x, o, b -- int in decimal, hex, octal, binary
+ // ud, ux, uo, ub -- unsigned int
+ // ld, lx, lo, lb, uld, ulx, ulo, ulb -- long, unsigned long
+ // f, g -- double
+ // c -- char
+ // s -- string (char *)
+ // t -- GString *
+ // w -- blank space; arg determines width
+ // To get literal curly braces, use {{ or }}.
+ static GString *format(char *fmt, ...);
+ static GString *formatv(char *fmt, va_list argList);
+
// Destructor.
~GString();
@@ -67,6 +94,10 @@ public:
GString *append(const char *str);
GString *append(const char *str, int lengthA);
+ // Append a formatted string.
+ GString *appendf(char *fmt, ...);
+ GString *appendfv(char *fmt, va_list argList);
+
// Insert a character or string.
GString *insert(int i, char c);
GString *insert(int i, GString *str);
@@ -92,6 +123,14 @@ private:
char *s;
void resize(int length1);
+ static void formatInt(long x, char *buf, int bufSize,
+ GBool zeroFill, int width, int base,
+ char **p, int *len);
+ static void formatUInt(Gulong x, char *buf, int bufSize,
+ GBool zeroFill, int width, int base,
+ char **p, int *len);
+ static void formatDouble(double x, char *buf, int bufSize, int prec,
+ GBool trim, char **p, int *len);
};
#endif
diff --git a/Build/source/libs/xpdf/goo/Makefile.in b/Build/source/libs/xpdf/goo/Makefile.in
index fe992f46ac5..4cebea29e0b 100644
--- a/Build/source/libs/xpdf/goo/Makefile.in
+++ b/Build/source/libs/xpdf/goo/Makefile.in
@@ -5,6 +5,7 @@
# Copyright 1996 Derek B. Noonburg
#
# Modified for pdftex by Martin Schröder 2005
+# $Id$
#
#========================================================================
@@ -43,17 +44,17 @@ CXX_SRC = \
$(srcdir)/GHash.cc \
$(srcdir)/GList.cc \
$(srcdir)/GString.cc \
+ $(srcdir)/gmem.cc \
$(srcdir)/gmempp.cc \
$(srcdir)/gfile.cc
C_SRC = \
- $(srcdir)/gmem.c \
$(srcdir)/parseargs.c
#------------------------------------------------------------------------
-GOO_CXX_OBJS = FixedPoint.o GHash.o GList.o GString.o gmempp.o gfile.o
-GOO_C_OBJS = gmem.o parseargs.o
+GOO_CXX_OBJS = FixedPoint.o GHash.o GList.o GString.o gmem.o gmempp.o gfile.o
+GOO_C_OBJS = parseargs.o
GOO_OBJS = $(GOO_CXX_OBJS) $(GOO_C_OBJS)
libGoo.a: $(GOO_OBJS)
diff --git a/Build/source/libs/xpdf/goo/depend.mk b/Build/source/libs/xpdf/goo/depend.mk
index c0dfb37f7b5..8aa02de24cb 100644
--- a/Build/source/libs/xpdf/goo/depend.mk
+++ b/Build/source/libs/xpdf/goo/depend.mk
@@ -23,7 +23,7 @@ GString.o: $(srcdir)/GString.cc ../aconf.h \
$(srcdirparent)/aconf2.h \
$(srcdir)/gtypes.h \
$(srcdir)/GString.h
-gmem.o: $(srcdir)/gmem.c ../aconf.h \
+gmem.o: $(srcdir)/gmem.cc ../aconf.h \
$(srcdirparent)/aconf2.h \
$(srcdir)/gmem.h
parseargs.o: $(srcdir)/parseargs.c \
diff --git a/Build/source/libs/xpdf/goo/gfile.cc b/Build/source/libs/xpdf/goo/gfile.cc
index caa96e7459b..740b3ea1ff6 100644
--- a/Build/source/libs/xpdf/goo/gfile.cc
+++ b/Build/source/libs/xpdf/goo/gfile.cc
@@ -10,7 +10,9 @@
#include <aconf.h>
-#ifndef WIN32
+#ifdef WIN32
+# include <time.h>
+#else
# if defined(MACOS)
# include <sys/stat.h>
# elif !defined(ACORN)
@@ -441,21 +443,45 @@ time_t getModTime(char *fileName) {
GBool openTempFile(GString **name, FILE **f, char *mode, char *ext) {
#if defined(WIN32)
//---------- Win32 ----------
- char *s;
-
- if (!(s = _tempnam(getenv("TEMP"), NULL))) {
- return gFalse;
- }
- *name = new GString(s);
- free(s);
- if (ext) {
- (*name)->append(ext);
+ char *tempDir;
+ GString *s, *s2;
+ char buf[32];
+ FILE *f2;
+ int t, i;
+
+ // this has the standard race condition problem, but I haven't found
+ // a better way to generate temp file names with extensions on
+ // Windows
+ if ((tempDir = getenv("TEMP"))) {
+ s = new GString(tempDir);
+ s->append('\\');
+ } else {
+ s = new GString();
}
- if (!(*f = fopen((*name)->getCString(), mode))) {
- delete (*name);
- return gFalse;
+ s->append("x");
+ t = (int)time(NULL);
+ for (i = 0; i < 1000; ++i) {
+ sprintf(buf, "%d", t + i);
+ s2 = s->copy()->append(buf);
+ if (ext) {
+ s2->append(ext);
+ }
+ if (!(f2 = fopen(s2->getCString(), "r"))) {
+ if (!(f2 = fopen(s2->getCString(), mode))) {
+ delete s2;
+ delete s;
+ return gFalse;
+ }
+ *name = s2;
+ *f = f2;
+ delete s;
+ return gTrue;
+ }
+ fclose(f2);
+ delete s2;
}
- return gTrue;
+ delete s;
+ return gFalse;
#elif defined(VMS) || defined(__EMX__) || defined(ACORN) || defined(MACOS)
//---------- non-Unix ----------
char *s;
@@ -672,9 +698,9 @@ GDirEntry *GDir::getNextEntry() {
struct dirent *ent;
e = NULL;
if (dir) {
- ent = readdir(dir);
+ ent = (struct dirent *)readdir(dir);
if (ent && !strcmp(ent->d_name, ".")) {
- ent = readdir(dir);
+ ent = (struct dirent *)readdir(dir);
}
if (ent) {
e = new GDirEntry(path->getCString(), ent->d_name, doStat);
diff --git a/Build/source/libs/xpdf/goo/gfile.h b/Build/source/libs/xpdf/goo/gfile.h
index 8817e8b2381..82f1d7a98e3 100644
--- a/Build/source/libs/xpdf/goo/gfile.h
+++ b/Build/source/libs/xpdf/goo/gfile.h
@@ -46,9 +46,6 @@
# endif
# endif
#endif
-#if defined(__DJGPP__)
-typedef unsigned int time_t;
-#endif
#include "gtypes.h"
class GString;
@@ -86,9 +83,7 @@ extern time_t getModTime(char *fileName);
// should be done to the returned file pointer; the file may be
// reopened later for reading, but not for writing. The <mode> string
// should be "w" or "wb". Returns true on success.
-#ifndef PDF_PARSER_ONLY
extern GBool openTempFile(GString **name, FILE **f, char *mode, char *ext);
-#endif
// Execute <command>. Returns true on success.
extern GBool executeCommand(char *cmd);
diff --git a/Build/source/libs/xpdf/goo/gmem.c b/Build/source/libs/xpdf/goo/gmem.cc
index b97535adf04..6b13b38d0f0 100644
--- a/Build/source/libs/xpdf/goo/gmem.c
+++ b/Build/source/libs/xpdf/goo/gmem.cc
@@ -17,14 +17,17 @@
#ifdef DEBUG_MEM
typedef struct _GMemHdr {
+ unsigned int magic;
int size;
int index;
- struct _GMemHdr *next;
+ struct _GMemHdr *next, *prev;
} GMemHdr;
#define gMemHdrSize ((sizeof(GMemHdr) + 7) & ~7)
#define gMemTrlSize (sizeof(long))
+#define gMemMagic 0xabcd9999
+
#if gmemTrlSize==8
#define gMemDeadVal 0xdeadbeefdeadbeefUL
#else
@@ -35,19 +38,8 @@ typedef struct _GMemHdr {
#define gMemDataSize(size) \
((((size) + gMemTrlSize - 1) / gMemTrlSize) * gMemTrlSize)
-#define gMemNLists 64
-#define gMemListShift 4
-#define gMemListMask (gMemNLists - 1)
-static GMemHdr *gMemList[gMemNLists] = {
- NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
- NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
- NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
- NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
- NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
- NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
- NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
- NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
-};
+static GMemHdr *gMemHead = NULL;
+static GMemHdr *gMemTail = NULL;
static int gMemIndex = 0;
static int gMemAlloc = 0;
@@ -55,57 +47,75 @@ static int gMemInUse = 0;
#endif /* DEBUG_MEM */
-void *gmalloc(int size) {
+void *gmalloc(int size) GMEM_EXCEP {
#ifdef DEBUG_MEM
int size1;
char *mem;
GMemHdr *hdr;
void *data;
- int lst;
unsigned long *trl, *p;
- if (size <= 0)
+ if (size <= 0) {
return NULL;
+ }
size1 = gMemDataSize(size);
if (!(mem = (char *)malloc(size1 + gMemHdrSize + gMemTrlSize))) {
+#if USE_EXCEPTIONS
+ throw GMemException();
+#else
fprintf(stderr, "Out of memory\n");
exit(1);
+#endif
}
hdr = (GMemHdr *)mem;
data = (void *)(mem + gMemHdrSize);
trl = (unsigned long *)(mem + gMemHdrSize + size1);
+ hdr->magic = gMemMagic;
hdr->size = size;
hdr->index = gMemIndex++;
- lst = ((int)hdr >> gMemListShift) & gMemListMask;
- hdr->next = gMemList[lst];
- gMemList[lst] = hdr;
+ if (gMemTail) {
+ gMemTail->next = hdr;
+ hdr->prev = gMemTail;
+ gMemTail = hdr;
+ } else {
+ hdr->prev = NULL;
+ gMemHead = gMemTail = hdr;
+ }
+ hdr->next = NULL;
++gMemAlloc;
gMemInUse += size;
- for (p = (unsigned long *)data; p <= trl; ++p)
+ for (p = (unsigned long *)data; p <= trl; ++p) {
*p = gMemDeadVal;
+ }
return data;
#else
void *p;
- if (size <= 0)
+ if (size <= 0) {
return NULL;
+ }
if (!(p = malloc(size))) {
+#if USE_EXCEPTIONS
+ throw GMemException();
+#else
fprintf(stderr, "Out of memory\n");
exit(1);
+#endif
}
return p;
#endif
}
-void *grealloc(void *p, int size) {
+void *grealloc(void *p, int size) GMEM_EXCEP {
#ifdef DEBUG_MEM
GMemHdr *hdr;
void *q;
int oldSize;
if (size <= 0) {
- if (p)
+ if (p) {
gfree(p);
+ }
return NULL;
}
if (p) {
@@ -122,23 +132,29 @@ void *grealloc(void *p, int size) {
void *q;
if (size <= 0) {
- if (p)
+ if (p) {
free(p);
+ }
return NULL;
}
- if (p)
+ if (p) {
q = realloc(p, size);
- else
+ } else {
q = malloc(size);
+ }
if (!q) {
+#if USE_EXCEPTIONS
+ throw GMemException();
+#else
fprintf(stderr, "Out of memory\n");
exit(1);
+#endif
}
return q;
#endif
}
-void *gmallocn(int nObjs, int objSize) {
+void *gmallocn(int nObjs, int objSize) GMEM_EXCEP {
int n;
if (nObjs == 0) {
@@ -146,13 +162,17 @@ void *gmallocn(int nObjs, int objSize) {
}
n = nObjs * objSize;
if (objSize <= 0 || nObjs < 0 || nObjs >= INT_MAX / objSize) {
+#if USE_EXCEPTIONS
+ throw GMemException();
+#else
fprintf(stderr, "Bogus memory allocation size\n");
exit(1);
+#endif
}
return gmalloc(n);
}
-void *greallocn(void *p, int nObjs, int objSize) {
+void *greallocn(void *p, int nObjs, int objSize) GMEM_EXCEP {
int n;
if (nObjs == 0) {
@@ -163,8 +183,12 @@ void *greallocn(void *p, int nObjs, int objSize) {
}
n = nObjs * objSize;
if (objSize <= 0 || nObjs < 0 || nObjs >= INT_MAX / objSize) {
+#if USE_EXCEPTIONS
+ throw GMemException();
+#else
fprintf(stderr, "Bogus memory allocation size\n");
exit(1);
+#endif
}
return grealloc(p, n);
}
@@ -173,22 +197,23 @@ void gfree(void *p) {
#ifdef DEBUG_MEM
int size;
GMemHdr *hdr;
- GMemHdr *prevHdr, *q;
- int lst;
unsigned long *trl, *clr;
if (p) {
hdr = (GMemHdr *)((char *)p - gMemHdrSize);
- lst = ((int)hdr >> gMemListShift) & gMemListMask;
- for (prevHdr = NULL, q = gMemList[lst]; q; prevHdr = q, q = q->next) {
- if (q == hdr)
- break;
- }
- if (q) {
- if (prevHdr)
- prevHdr->next = hdr->next;
- else
- gMemList[lst] = hdr->next;
+ if (hdr->magic == gMemMagic &&
+ ((hdr->prev == NULL) == (hdr == gMemHead)) &&
+ ((hdr->next == NULL) == (hdr == gMemTail))) {
+ if (hdr->prev) {
+ hdr->prev->next = hdr->next;
+ } else {
+ gMemHead = hdr->next;
+ }
+ if (hdr->next) {
+ hdr->next->prev = hdr->prev;
+ } else {
+ gMemTail = hdr->prev;
+ }
--gMemAlloc;
gMemInUse -= hdr->size;
size = gMemDataSize(hdr->size);
@@ -197,32 +222,32 @@ void gfree(void *p) {
fprintf(stderr, "Overwrite past end of block %d at address %p\n",
hdr->index, p);
}
- for (clr = (unsigned long *)hdr; clr <= trl; ++clr)
+ for (clr = (unsigned long *)hdr; clr <= trl; ++clr) {
*clr = gMemDeadVal;
+ }
free(hdr);
} else {
fprintf(stderr, "Attempted to free bad address %p\n", p);
}
}
#else
- if (p)
+ if (p) {
free(p);
+ }
#endif
}
#ifdef DEBUG_MEM
void gMemReport(FILE *f) {
GMemHdr *p;
- int lst;
fprintf(f, "%d memory allocations in all\n", gMemIndex);
if (gMemAlloc > 0) {
fprintf(f, "%d memory blocks left allocated:\n", gMemAlloc);
fprintf(f, " index size\n");
fprintf(f, "-------- --------\n");
- for (lst = 0; lst < gMemNLists; ++lst) {
- for (p = gMemList[lst]; p; p = p->next)
- fprintf(f, "%8d %8d\n", p->index, p->size);
+ for (p = gMemHead; p; p = p->next) {
+ fprintf(f, "%8d %8d\n", p->index, p->size);
}
} else {
fprintf(f, "No memory blocks left allocated\n");
diff --git a/Build/source/libs/xpdf/goo/gmem.h b/Build/source/libs/xpdf/goo/gmem.h
index e74d1822318..da34736f216 100644
--- a/Build/source/libs/xpdf/goo/gmem.h
+++ b/Build/source/libs/xpdf/goo/gmem.h
@@ -10,6 +10,23 @@
#define GMEM_H
#include <stdio.h>
+#include <aconf.h>
+
+#if USE_EXCEPTIONS
+
+class GMemException {
+public:
+ GMemException() {}
+ ~GMemException() {}
+};
+
+#define GMEM_EXCEP throw(GMemException)
+
+#else // USE_EXCEPTIONS
+
+#define GMEM_EXCEP
+
+#endif // USE_EXCEPTIONS
#ifdef __cplusplus
extern "C" {
@@ -19,13 +36,13 @@ extern "C" {
* Same as malloc, but prints error message and exits if malloc()
* returns NULL.
*/
-extern void *gmalloc(int size);
+extern void *gmalloc(int size) GMEM_EXCEP;
/*
* Same as realloc, but prints error message and exits if realloc()
* returns NULL. If <p> is NULL, calls malloc instead of realloc().
*/
-extern void *grealloc(void *p, int size);
+extern void *grealloc(void *p, int size) GMEM_EXCEP;
/*
* These are similar to gmalloc and grealloc, but take an object count
@@ -33,8 +50,8 @@ extern void *grealloc(void *p, int size);
* bytes, but there is an additional error check that the total size
* doesn't overflow an int.
*/
-extern void *gmallocn(int nObjs, int objSize);
-extern void *greallocn(void *p, int nObjs, int objSize);
+extern void *gmallocn(int nObjs, int objSize) GMEM_EXCEP;
+extern void *greallocn(void *p, int nObjs, int objSize) GMEM_EXCEP;
/*
* Same as free, but checks for and ignores NULL pointers.
diff --git a/Build/source/libs/xpdf/xpdf/Catalog.cc b/Build/source/libs/xpdf/xpdf/Catalog.cc
index fd235d63c4b..de282c3feb6 100644
--- a/Build/source/libs/xpdf/xpdf/Catalog.cc
+++ b/Build/source/libs/xpdf/xpdf/Catalog.cc
@@ -2,7 +2,7 @@
//
// Catalog.cc
//
-// Copyright 1996-2003 Glyph & Cog, LLC
+// Copyright 1996-2007 Glyph & Cog, LLC
//
//========================================================================
@@ -28,8 +28,9 @@
//------------------------------------------------------------------------
Catalog::Catalog(XRef *xrefA) {
- Object catDict, pagesDict;
+ Object catDict, pagesDict, pagesDictRef;
Object obj, obj2;
+ char *alreadyRead;
int numPages0;
int i;
@@ -71,7 +72,16 @@ Catalog::Catalog(XRef *xrefA) {
pageRefs[i].num = -1;
pageRefs[i].gen = -1;
}
- numPages = readPageTree(pagesDict.getDict(), NULL, 0);
+ alreadyRead = (char *)gmalloc(xref->getNumObjects());
+ memset(alreadyRead, 0, xref->getNumObjects());
+ if (catDict.dictLookupNF("Pages", &pagesDictRef)->isRef() &&
+ pagesDictRef.getRefNum() >= 0 &&
+ pagesDictRef.getRefNum() < xref->getNumObjects()) {
+ alreadyRead[pagesDictRef.getRefNum()] = 1;
+ }
+ pagesDictRef.free();
+ numPages = readPageTree(pagesDict.getDict(), NULL, 0, alreadyRead);
+ gfree(alreadyRead);
if (numPages != numPages0) {
error(-1, "Page count in top-level pages object is incorrect");
}
@@ -169,7 +179,8 @@ GString *Catalog::readMetadata() {
return s;
}
-int Catalog::readPageTree(Dict *pagesDict, PageAttrs *attrs, int start) {
+int Catalog::readPageTree(Dict *pagesDict, PageAttrs *attrs, int start,
+ char *alreadyRead) {
Object kids;
Object kid;
Object kidRef;
@@ -185,6 +196,17 @@ int Catalog::readPageTree(Dict *pagesDict, PageAttrs *attrs, int start) {
goto err1;
}
for (i = 0; i < kids.arrayGetLength(); ++i) {
+ kids.arrayGetNF(i, &kidRef);
+ if (kidRef.isRef() &&
+ kidRef.getRefNum() >= 0 &&
+ kidRef.getRefNum() < xref->getNumObjects()) {
+ if (alreadyRead[kidRef.getRefNum()]) {
+ error(-1, "Loop in Pages tree");
+ kidRef.free();
+ continue;
+ }
+ alreadyRead[kidRef.getRefNum()] = 1;
+ }
kids.arrayGet(i, &kid);
if (kid.isDict("Page")) {
attrs2 = new PageAttrs(attrs1, kid.getDict());
@@ -204,17 +226,15 @@ int Catalog::readPageTree(Dict *pagesDict, PageAttrs *attrs, int start) {
}
}
pages[start] = page;
- kids.arrayGetNF(i, &kidRef);
if (kidRef.isRef()) {
pageRefs[start].num = kidRef.getRefNum();
pageRefs[start].gen = kidRef.getRefGen();
}
- kidRef.free();
++start;
// This should really be isDict("Pages"), but I've seen at least one
// PDF file where the /Type entry is missing.
} else if (kid.isDict()) {
- if ((start = readPageTree(kid.getDict(), attrs1, start))
+ if ((start = readPageTree(kid.getDict(), attrs1, start, alreadyRead))
< 0)
goto err2;
} else {
@@ -222,6 +242,7 @@ int Catalog::readPageTree(Dict *pagesDict, PageAttrs *attrs, int start) {
start+1, kid.getTypeName());
}
kid.free();
+ kidRef.free();
}
delete attrs1;
kids.free();
diff --git a/Build/source/libs/xpdf/xpdf/Catalog.h b/Build/source/libs/xpdf/xpdf/Catalog.h
index c38f1098500..6403194f974 100644
--- a/Build/source/libs/xpdf/xpdf/Catalog.h
+++ b/Build/source/libs/xpdf/xpdf/Catalog.h
@@ -2,7 +2,7 @@
//
// Catalog.h
//
-// Copyright 1996-2003 Glyph & Cog, LLC
+// Copyright 1996-2007 Glyph & Cog, LLC
//
//========================================================================
@@ -65,6 +65,10 @@ public:
// NULL if <name> is not a destination.
LinkDest *findDest(GString *name);
+ Object *getDests() { return &dests; }
+
+ Object *getNameTree() { return &nameTree; }
+
Object *getOutline() { return &outline; }
Object *getAcroForm() { return &acroForm; }
@@ -85,7 +89,8 @@ private:
Object acroForm; // AcroForm dictionary
GBool ok; // true if catalog is valid
- int readPageTree(Dict *pages, PageAttrs *attrs, int start);
+ int readPageTree(Dict *pages, PageAttrs *attrs, int start,
+ char *alreadyRead);
Object *findDestInTree(Object *tree, GString *name, Object *obj);
};
diff --git a/Build/source/libs/xpdf/xpdf/Decrypt.cc b/Build/source/libs/xpdf/xpdf/Decrypt.cc
index 91eb452a815..03205897cf4 100644
--- a/Build/source/libs/xpdf/xpdf/Decrypt.cc
+++ b/Build/source/libs/xpdf/xpdf/Decrypt.cc
@@ -18,6 +18,9 @@
static void rc4InitKey(Guchar *key, int keyLen, Guchar *state);
static Guchar rc4DecryptByte(Guchar *state, Guchar *x, Guchar *y, Guchar c);
+static void aesKeyExpansion(DecryptAESState *s,
+ Guchar *objKey, int objKeyLen);
+static void aesDecryptBlock(DecryptAESState *s, Guchar *in, GBool last);
static void md5(Guchar *msg, int msgLen, Guchar *digest);
static Guchar passwordPad[32] = {
@@ -31,37 +34,6 @@ static Guchar passwordPad[32] = {
// Decrypt
//------------------------------------------------------------------------
-Decrypt::Decrypt(Guchar *fileKey, int keyLength, int objNum, int objGen) {
- int i;
-
- // construct object key
- for (i = 0; i < keyLength; ++i) {
- objKey[i] = fileKey[i];
- }
- objKey[keyLength] = objNum & 0xff;
- objKey[keyLength + 1] = (objNum >> 8) & 0xff;
- objKey[keyLength + 2] = (objNum >> 16) & 0xff;
- objKey[keyLength + 3] = objGen & 0xff;
- objKey[keyLength + 4] = (objGen >> 8) & 0xff;
- md5(objKey, keyLength + 5, objKey);
-
- // set up for decryption
- x = y = 0;
- if ((objKeyLength = keyLength + 5) > 16) {
- objKeyLength = 16;
- }
- rc4InitKey(objKey, objKeyLength, state);
-}
-
-void Decrypt::reset() {
- x = y = 0;
- rc4InitKey(objKey, objKeyLength, state);
-}
-
-Guchar Decrypt::decryptByte(Guchar c) {
- return rc4DecryptByte(state, &x, &y, c);
-}
-
GBool Decrypt::makeFileKey(int encVersion, int encRevision, int keyLength,
GString *ownerKey, GString *userKey,
int permissions, GString *fileID,
@@ -206,6 +178,144 @@ GBool Decrypt::makeFileKey2(int encVersion, int encRevision, int keyLength,
}
//------------------------------------------------------------------------
+// DecryptStream
+//------------------------------------------------------------------------
+
+DecryptStream::DecryptStream(Stream *strA, Guchar *fileKey,
+ CryptAlgorithm algoA, int keyLength,
+ int objNum, int objGen):
+ FilterStream(strA)
+{
+ int n, i;
+
+ algo = algoA;
+
+ // construct object key
+ for (i = 0; i < keyLength; ++i) {
+ objKey[i] = fileKey[i];
+ }
+ objKey[keyLength] = objNum & 0xff;
+ objKey[keyLength + 1] = (objNum >> 8) & 0xff;
+ objKey[keyLength + 2] = (objNum >> 16) & 0xff;
+ objKey[keyLength + 3] = objGen & 0xff;
+ objKey[keyLength + 4] = (objGen >> 8) & 0xff;
+ if (algo == cryptAES) {
+ objKey[keyLength + 5] = 0x73; // 's'
+ objKey[keyLength + 6] = 0x41; // 'A'
+ objKey[keyLength + 7] = 0x6c; // 'l'
+ objKey[keyLength + 8] = 0x54; // 'T'
+ n = keyLength + 9;
+ } else {
+ n = keyLength + 5;
+ }
+ md5(objKey, n, objKey);
+ if ((objKeyLength = keyLength + 5) > 16) {
+ objKeyLength = 16;
+ }
+}
+
+DecryptStream::~DecryptStream() {
+ delete str;
+}
+
+void DecryptStream::reset() {
+ int i;
+
+ str->reset();
+ switch (algo) {
+ case cryptRC4:
+ state.rc4.x = state.rc4.y = 0;
+ rc4InitKey(objKey, objKeyLength, state.rc4.state);
+ state.rc4.buf = EOF;
+ break;
+ case cryptAES:
+ aesKeyExpansion(&state.aes, objKey, objKeyLength);
+ for (i = 0; i < 16; ++i) {
+ state.aes.cbc[i] = str->getChar();
+ }
+ state.aes.bufIdx = 16;
+ break;
+ }
+}
+
+int DecryptStream::getChar() {
+ Guchar in[16];
+ int c, i;
+
+ c = EOF; // make gcc happy
+ switch (algo) {
+ case cryptRC4:
+ if (state.rc4.buf == EOF) {
+ c = str->getChar();
+ if (c != EOF) {
+ state.rc4.buf = rc4DecryptByte(state.rc4.state, &state.rc4.x,
+ &state.rc4.y, (Guchar)c);
+ }
+ }
+ c = state.rc4.buf;
+ state.rc4.buf = EOF;
+ break;
+ case cryptAES:
+ if (state.aes.bufIdx == 16) {
+ for (i = 0; i < 16; ++i) {
+ if ((c = str->getChar()) == EOF) {
+ return EOF;
+ }
+ in[i] = (Guchar)c;
+ }
+ aesDecryptBlock(&state.aes, in, str->lookChar() == EOF);
+ }
+ if (state.aes.bufIdx == 16) {
+ c = EOF;
+ } else {
+ c = state.aes.buf[state.aes.bufIdx++];
+ }
+ break;
+ }
+ return c;
+}
+
+int DecryptStream::lookChar() {
+ Guchar in[16];
+ int c, i;
+
+ c = EOF; // make gcc happy
+ switch (algo) {
+ case cryptRC4:
+ if (state.rc4.buf == EOF) {
+ c = str->getChar();
+ if (c != EOF) {
+ state.rc4.buf = rc4DecryptByte(state.rc4.state, &state.rc4.x,
+ &state.rc4.y, (Guchar)c);
+ }
+ }
+ c = state.rc4.buf;
+ break;
+ case cryptAES:
+ if (state.aes.bufIdx == 16) {
+ for (i = 0; i < 16; ++i) {
+ if ((c = str->getChar()) == EOF) {
+ return EOF;
+ }
+ in[i] = c;
+ }
+ aesDecryptBlock(&state.aes, in, str->lookChar() == EOF);
+ }
+ if (state.aes.bufIdx == 16) {
+ c = EOF;
+ } else {
+ c = state.aes.buf[state.aes.bufIdx];
+ }
+ break;
+ }
+ return c;
+}
+
+GBool DecryptStream::isBinary(GBool last) {
+ return str->isBinary(last);
+}
+
+//------------------------------------------------------------------------
// RC4-compatible decryption
//------------------------------------------------------------------------
@@ -239,6 +349,261 @@ static Guchar rc4DecryptByte(Guchar *state, Guchar *x, Guchar *y, Guchar c) {
}
//------------------------------------------------------------------------
+// AES decryption
+//------------------------------------------------------------------------
+
+static Guchar sbox[256] = {
+ 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76,
+ 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0,
+ 0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
+ 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75,
+ 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84,
+ 0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
+ 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8,
+ 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2,
+ 0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
+ 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb,
+ 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79,
+ 0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
+ 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a,
+ 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e,
+ 0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
+ 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16
+};
+
+static Guchar invSbox[256] = {
+ 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb,
+ 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87, 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb,
+ 0x54, 0x7b, 0x94, 0x32, 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
+ 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49, 0x6d, 0x8b, 0xd1, 0x25,
+ 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16, 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92,
+ 0x6c, 0x70, 0x48, 0x50, 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
+ 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05, 0xb8, 0xb3, 0x45, 0x06,
+ 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02, 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b,
+ 0x3a, 0x91, 0x11, 0x41, 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
+ 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8, 0x1c, 0x75, 0xdf, 0x6e,
+ 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89, 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b,
+ 0xfc, 0x56, 0x3e, 0x4b, 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
+ 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xec, 0x5f,
+ 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d, 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef,
+ 0xa0, 0xe0, 0x3b, 0x4d, 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
+ 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d
+};
+
+static Guint rcon[11] = {
+ 0x00000000, // unused
+ 0x01000000,
+ 0x02000000,
+ 0x04000000,
+ 0x08000000,
+ 0x10000000,
+ 0x20000000,
+ 0x40000000,
+ 0x80000000,
+ 0x1b000000,
+ 0x36000000
+};
+
+static inline Guint subWord(Guint x) {
+ return (sbox[x >> 24] << 24)
+ | (sbox[(x >> 16) & 0xff] << 16)
+ | (sbox[(x >> 8) & 0xff] << 8)
+ | sbox[x & 0xff];
+}
+
+static inline Guint rotWord(Guint x) {
+ return ((x << 8) & 0xffffffff) | (x >> 24);
+}
+
+static inline void invSubBytes(Guchar *state) {
+ int i;
+
+ for (i = 0; i < 16; ++i) {
+ state[i] = invSbox[state[i]];
+ }
+}
+
+static inline void invShiftRows(Guchar *state) {
+ Guchar t;
+
+ t = state[7];
+ state[7] = state[6];
+ state[6] = state[5];
+ state[5] = state[4];
+ state[4] = t;
+
+ t = state[8];
+ state[8] = state[10];
+ state[10] = t;
+ t = state[9];
+ state[9] = state[11];
+ state[11] = t;
+
+ t = state[12];
+ state[12] = state[13];
+ state[13] = state[14];
+ state[14] = state[15];
+ state[15] = t;
+}
+
+// {09} \cdot s
+static inline Guchar mul09(Guchar s) {
+ Guchar s2, s4, s8;
+
+ s2 = (s & 0x80) ? ((s << 1) ^ 0x1b) : (s << 1);
+ s4 = (s2 & 0x80) ? ((s2 << 1) ^ 0x1b) : (s2 << 1);
+ s8 = (s4 & 0x80) ? ((s4 << 1) ^ 0x1b) : (s4 << 1);
+ return s ^ s8;
+}
+
+// {0b} \cdot s
+static inline Guchar mul0b(Guchar s) {
+ Guchar s2, s4, s8;
+
+ s2 = (s & 0x80) ? ((s << 1) ^ 0x1b) : (s << 1);
+ s4 = (s2 & 0x80) ? ((s2 << 1) ^ 0x1b) : (s2 << 1);
+ s8 = (s4 & 0x80) ? ((s4 << 1) ^ 0x1b) : (s4 << 1);
+ return s ^ s2 ^ s8;
+}
+
+// {0d} \cdot s
+static inline Guchar mul0d(Guchar s) {
+ Guchar s2, s4, s8;
+
+ s2 = (s & 0x80) ? ((s << 1) ^ 0x1b) : (s << 1);
+ s4 = (s2 & 0x80) ? ((s2 << 1) ^ 0x1b) : (s2 << 1);
+ s8 = (s4 & 0x80) ? ((s4 << 1) ^ 0x1b) : (s4 << 1);
+ return s ^ s4 ^ s8;
+}
+
+// {0e} \cdot s
+static inline Guchar mul0e(Guchar s) {
+ Guchar s2, s4, s8;
+
+ s2 = (s & 0x80) ? ((s << 1) ^ 0x1b) : (s << 1);
+ s4 = (s2 & 0x80) ? ((s2 << 1) ^ 0x1b) : (s2 << 1);
+ s8 = (s4 & 0x80) ? ((s4 << 1) ^ 0x1b) : (s4 << 1);
+ return s2 ^ s4 ^ s8;
+}
+
+static inline void invMixColumns(Guchar *state) {
+ int c;
+ Guchar s0, s1, s2, s3;
+
+ for (c = 0; c < 4; ++c) {
+ s0 = state[c];
+ s1 = state[4+c];
+ s2 = state[8+c];
+ s3 = state[12+c];
+ state[c] = mul0e(s0) ^ mul0b(s1) ^ mul0d(s2) ^ mul09(s3);
+ state[4+c] = mul09(s0) ^ mul0e(s1) ^ mul0b(s2) ^ mul0d(s3);
+ state[8+c] = mul0d(s0) ^ mul09(s1) ^ mul0e(s2) ^ mul0b(s3);
+ state[12+c] = mul0b(s0) ^ mul0d(s1) ^ mul09(s2) ^ mul0e(s3);
+ }
+}
+
+static inline void invMixColumnsW(Guint *w) {
+ int c;
+ Guchar s0, s1, s2, s3;
+
+ for (c = 0; c < 4; ++c) {
+ s0 = w[c] >> 24;
+ s1 = w[c] >> 16;
+ s2 = w[c] >> 8;
+ s3 = w[c];
+ w[c] = ((mul0e(s0) ^ mul0b(s1) ^ mul0d(s2) ^ mul09(s3)) << 24)
+ | ((mul09(s0) ^ mul0e(s1) ^ mul0b(s2) ^ mul0d(s3)) << 16)
+ | ((mul0d(s0) ^ mul09(s1) ^ mul0e(s2) ^ mul0b(s3)) << 8)
+ | (mul0b(s0) ^ mul0d(s1) ^ mul09(s2) ^ mul0e(s3));
+ }
+}
+
+static inline void addRoundKey(Guchar *state, Guint *w) {
+ int c;
+
+ for (c = 0; c < 4; ++c) {
+ state[c] ^= w[c] >> 24;
+ state[4+c] ^= w[c] >> 16;
+ state[8+c] ^= w[c] >> 8;
+ state[12+c] ^= w[c];
+ }
+}
+
+static void aesKeyExpansion(DecryptAESState *s,
+ Guchar *objKey, int objKeyLen) {
+ Guint temp;
+ int i, round;
+
+ //~ this assumes objKeyLen == 16
+
+ for (i = 0; i < 4; ++i) {
+ s->w[i] = (objKey[4*i] << 24) + (objKey[4*i+1] << 16) +
+ (objKey[4*i+2] << 8) + objKey[4*i+3];
+ }
+ for (i = 4; i < 44; ++i) {
+ temp = s->w[i-1];
+ if (!(i & 3)) {
+ temp = subWord(rotWord(temp)) ^ rcon[i/4];
+ }
+ s->w[i] = s->w[i-4] ^ temp;
+ }
+ for (round = 1; round <= 9; ++round) {
+ invMixColumnsW(&s->w[round * 4]);
+ }
+}
+
+static void aesDecryptBlock(DecryptAESState *s, Guchar *in, GBool last) {
+ int c, round, n, i;
+
+ // initial state
+ for (c = 0; c < 4; ++c) {
+ s->state[c] = in[4*c];
+ s->state[4+c] = in[4*c+1];
+ s->state[8+c] = in[4*c+2];
+ s->state[12+c] = in[4*c+3];
+ }
+
+ // round 0
+ addRoundKey(s->state, &s->w[10 * 4]);
+
+ // rounds 1-9
+ for (round = 9; round >= 1; --round) {
+ invSubBytes(s->state);
+ invShiftRows(s->state);
+ invMixColumns(s->state);
+ addRoundKey(s->state, &s->w[round * 4]);
+ }
+
+ // round 10
+ invSubBytes(s->state);
+ invShiftRows(s->state);
+ addRoundKey(s->state, &s->w[0]);
+
+ // CBC
+ for (c = 0; c < 4; ++c) {
+ s->buf[4*c] = s->state[c] ^ s->cbc[4*c];
+ s->buf[4*c+1] = s->state[4+c] ^ s->cbc[4*c+1];
+ s->buf[4*c+2] = s->state[8+c] ^ s->cbc[4*c+2];
+ s->buf[4*c+3] = s->state[12+c] ^ s->cbc[4*c+3];
+ }
+
+ // save the input block for the next CBC
+ for (i = 0; i < 16; ++i) {
+ s->cbc[i] = in[i];
+ }
+
+ // remove padding
+ s->bufIdx = 0;
+ if (last) {
+ n = s->buf[15];
+ for (i = 15; i >= n; --i) {
+ s->buf[i] = s->buf[i-n];
+ }
+ s->bufIdx = n;
+ }
+}
+
+//------------------------------------------------------------------------
// MD5 message digest
//------------------------------------------------------------------------
diff --git a/Build/source/libs/xpdf/xpdf/Decrypt.h b/Build/source/libs/xpdf/xpdf/Decrypt.h
index 2beba581583..56f34b77f26 100644
--- a/Build/source/libs/xpdf/xpdf/Decrypt.h
+++ b/Build/source/libs/xpdf/xpdf/Decrypt.h
@@ -17,6 +17,8 @@
#include "gtypes.h"
#include "GString.h"
+#include "Object.h"
+#include "Stream.h"
//------------------------------------------------------------------------
// Decrypt
@@ -25,15 +27,6 @@
class Decrypt {
public:
- // Initialize the decryptor object.
- Decrypt(Guchar *fileKey, int keyLength, int objNum, int objGen);
-
- // Reset decryption.
- void reset();
-
- // Decrypt one byte.
- Guchar decryptByte(Guchar c);
-
// Generate a file key. The <fileKey> buffer must have space for at
// least 16 bytes. Checks <ownerPassword> and then <userPassword>
// and returns true if either is correct. Sets <ownerPasswordOk> if
@@ -53,11 +46,50 @@ private:
int permissions, GString *fileID,
GString *userPassword, Guchar *fileKey,
GBool encryptMetadata);
+};
- int objKeyLength;
- Guchar objKey[21];
+//------------------------------------------------------------------------
+// DecryptStream
+//------------------------------------------------------------------------
+
+struct DecryptRC4State {
Guchar state[256];
Guchar x, y;
+ int buf;
+};
+
+struct DecryptAESState {
+ Guint w[44];
+ Guchar state[16];
+ Guchar cbc[16];
+ Guchar buf[16];
+ int bufIdx;
+};
+
+class DecryptStream: public FilterStream {
+public:
+
+ DecryptStream(Stream *strA, Guchar *fileKey,
+ CryptAlgorithm algoA, int keyLength,
+ int objNum, int objGen);
+ virtual ~DecryptStream();
+ virtual StreamKind getKind() { return strWeird; }
+ virtual void reset();
+ virtual int getChar();
+ virtual int lookChar();
+ virtual GBool isBinary(GBool last);
+ virtual Stream *getUndecodedStream() { return this; }
+
+private:
+
+ CryptAlgorithm algo;
+ int objKeyLength;
+ Guchar objKey[16 + 9];
+
+ union {
+ DecryptRC4State rc4;
+ DecryptAESState aes;
+ } state;
};
#endif
diff --git a/Build/source/libs/xpdf/xpdf/Function.cc b/Build/source/libs/xpdf/xpdf/Function.cc
index f6996412a8b..a4d51c73821 100644
--- a/Build/source/libs/xpdf/xpdf/Function.cc
+++ b/Build/source/libs/xpdf/xpdf/Function.cc
@@ -190,10 +190,11 @@ SampledFunction::SampledFunction(Object *funcObj, Dict *dict) {
Object obj1, obj2;
Guint buf, bitMask;
int bits;
- int s;
+ Guint s;
int i;
samples = NULL;
+ sBuf = NULL;
ok = gFalse;
//----- initialize the generic stuff
@@ -204,6 +205,14 @@ SampledFunction::SampledFunction(Object *funcObj, Dict *dict) {
error(-1, "Type 0 function is missing range");
goto err1;
}
+ if (m > sampledFuncMaxInputs) {
+ error(-1, "Sampled functions with more than %d inputs are unsupported",
+ sampledFuncMaxInputs);
+ goto err1;
+ }
+
+ //----- buffer
+ sBuf = (double *)gmallocn(1 << m, sizeof(double));
//----- get the stream
if (!funcObj->isStream()) {
@@ -239,7 +248,7 @@ SampledFunction::SampledFunction(Object *funcObj, Dict *dict) {
goto err2;
}
sampleBits = obj1.getInt();
- sampleMul = 1.0 / (double)((1 << sampleBits) - 1);
+ sampleMul = 1.0 / (pow(2.0, (double)sampleBits) - 1);
obj1.free();
//----- Encode
@@ -347,12 +356,16 @@ SampledFunction::~SampledFunction() {
if (samples) {
gfree(samples);
}
+ if (sBuf) {
+ gfree(sBuf);
+ }
}
SampledFunction::SampledFunction(SampledFunction *func) {
memcpy(this, func, sizeof(SampledFunction));
samples = (double *)gmallocn(nSamples, sizeof(double));
memcpy(samples, func->samples, nSamples * sizeof(double));
+ sBuf = (double *)gmallocn(1 << m, sizeof(double));
}
void SampledFunction::transform(double *in, double *out) {
@@ -360,7 +373,6 @@ void SampledFunction::transform(double *in, double *out) {
int e[funcMaxInputs][2];
double efrac0[funcMaxInputs];
double efrac1[funcMaxInputs];
- double s[1 << funcMaxInputs];
int i, j, k, idx, t;
// map input values into sample array
@@ -389,18 +401,18 @@ void SampledFunction::transform(double *in, double *out) {
for (k = 0, t = j; k < m; ++k, t >>= 1) {
idx += idxMul[k] * (e[k][t & 1]);
}
- s[j] = samples[idx];
+ sBuf[j] = samples[idx];
}
// do m sets of interpolations
for (j = 0, t = (1<<m); j < m; ++j, t >>= 1) {
for (k = 0; k < t; k += 2) {
- s[k >> 1] = efrac0[j] * s[k] + efrac1[j] * s[k+1];
+ sBuf[k >> 1] = efrac0[j] * sBuf[k] + efrac1[j] * sBuf[k+1];
}
}
// map output value to range
- out[i] = s[0] * (decode[i][1] - decode[i][0]) + decode[i][0];
+ out[i] = sBuf[0] * (decode[i][1] - decode[i][0]) + decode[i][0];
if (out[i] < range[i][0]) {
out[i] = range[i][0];
} else if (out[i] > range[i][1]) {
@@ -540,6 +552,7 @@ StitchingFunction::StitchingFunction(Object *funcObj, Dict *dict) {
funcs = NULL;
bounds = NULL;
encode = NULL;
+ scale = NULL;
//----- initialize the generic stuff
if (!init(dict)) {
@@ -559,6 +572,7 @@ StitchingFunction::StitchingFunction(Object *funcObj, Dict *dict) {
funcs = (Function **)gmallocn(k, sizeof(Function *));
bounds = (double *)gmallocn(k + 1, sizeof(double));
encode = (double *)gmallocn(2 * k, sizeof(double));
+ scale = (double *)gmallocn(k, sizeof(double));
for (i = 0; i < k; ++i) {
funcs[i] = NULL;
}
@@ -609,6 +623,17 @@ StitchingFunction::StitchingFunction(Object *funcObj, Dict *dict) {
}
obj1.free();
+ //----- pre-compute the scale factors
+ for (i = 0; i < k; ++i) {
+ if (bounds[i] == bounds[i+1]) {
+ // avoid a divide-by-zero -- in this situation, function i will
+ // never be used anyway
+ scale[i] = 0;
+ } else {
+ scale[i] = (encode[2*i+1] - encode[2*i]) / (bounds[i+1] - bounds[i]);
+ }
+ }
+
ok = gTrue;
return;
@@ -630,6 +655,8 @@ StitchingFunction::StitchingFunction(StitchingFunction *func) {
memcpy(bounds, func->bounds, (k + 1) * sizeof(double));
encode = (double *)gmallocn(2 * k, sizeof(double));
memcpy(encode, func->encode, 2 * k * sizeof(double));
+ scale = (double *)gmallocn(k, sizeof(double));
+ memcpy(scale, func->scale, k * sizeof(double));
ok = gTrue;
}
@@ -646,6 +673,7 @@ StitchingFunction::~StitchingFunction() {
gfree(funcs);
gfree(bounds);
gfree(encode);
+ gfree(scale);
}
void StitchingFunction::transform(double *in, double *out) {
@@ -664,8 +692,7 @@ void StitchingFunction::transform(double *in, double *out) {
break;
}
}
- x = encode[2*i] + ((x - bounds[i]) / (bounds[i+1] - bounds[i])) *
- (encode[2*i+1] - encode[2*i]);
+ x = encode[2*i] + (x - bounds[i]) * scale[i];
funcs[i]->transform(&x, out);
}
@@ -1180,14 +1207,25 @@ GBool PostScriptFunction::parseCode(Stream *str, int *codePtr) {
GString *PostScriptFunction::getToken(Stream *str) {
GString *s;
int c;
+ GBool comment;
s = new GString();
- do {
- c = str->getChar();
- if (c != EOF) {
- codeString->append(c);
+ comment = gFalse;
+ while (1) {
+ if ((c = str->getChar()) == EOF) {
+ break;
}
- } while (c != EOF && isspace(c));
+ codeString->append(c);
+ if (comment) {
+ if (c == '\x0a' || c == '\x0d') {
+ comment = gFalse;
+ }
+ } else if (c == '%') {
+ comment = gTrue;
+ } else if (!isspace(c)) {
+ break;
+ }
+ }
if (c == '{' || c == '}') {
s->append((char)c);
} else if (isdigit(c) || c == '.' || c == '-') {
diff --git a/Build/source/libs/xpdf/xpdf/Function.h b/Build/source/libs/xpdf/xpdf/Function.h
index bfaf83e300e..334a4390fa1 100644
--- a/Build/source/libs/xpdf/xpdf/Function.h
+++ b/Build/source/libs/xpdf/xpdf/Function.h
@@ -27,8 +27,9 @@ class PSStack;
// Function
//------------------------------------------------------------------------
-#define funcMaxInputs 8
-#define funcMaxOutputs 32
+#define funcMaxInputs 32
+#define funcMaxOutputs 32
+#define sampledFuncMaxInputs 16
class Function {
public:
@@ -131,6 +132,7 @@ private:
int idxMul[funcMaxInputs]; // sample array index multipliers
double *samples; // the samples
int nSamples; // size of the samples array
+ double *sBuf; // buffer for the transform function
GBool ok;
};
@@ -180,6 +182,7 @@ public:
Function *getFunc(int i) { return funcs[i]; }
double *getBounds() { return bounds; }
double *getEncode() { return encode; }
+ double *getScale() { return scale; }
private:
@@ -189,6 +192,7 @@ private:
Function **funcs;
double *bounds;
double *encode;
+ double *scale;
GBool ok;
};
diff --git a/Build/source/libs/xpdf/xpdf/GfxFont.cc b/Build/source/libs/xpdf/xpdf/GfxFont.cc
index a4581c0ff35..9af7efcf8c6 100644
--- a/Build/source/libs/xpdf/xpdf/GfxFont.cc
+++ b/Build/source/libs/xpdf/xpdf/GfxFont.cc
@@ -235,6 +235,19 @@ void GfxFont::readFontDescriptor(XRef *xref, Dict *fontDict) {
error(-1, "Mismatch between font type and embedded font file");
}
type = fontCIDType0C;
+ } else if (obj4.isName("OpenType")) {
+ embFontID = obj2.getRef();
+ if (type == fontTrueType) {
+ type = fontTrueTypeOT;
+ } else if (type == fontType1) {
+ type = fontType1COT;
+ } else if (type == fontCIDType0) {
+ type = fontCIDType0COT;
+ } else if (type == fontCIDType2) {
+ type = fontCIDType2OT;
+ } else {
+ error(-1, "Mismatch between font type and embedded font file");
+ }
} else {
error(-1, "Unknown embedded font type '%s'",
obj4.isName() ? obj4.getName() : "???");
@@ -751,6 +764,15 @@ Gfx8BitFont::Gfx8BitFont(XRef *xref, char *tagA, Ref idA, GString *nameA,
}
}
}
+
+ // if the 'mapUnknownCharNames' flag is set, do a simple pass-through
+ // mapping for unknown character names
+ } else if (missing && globalParams->getMapUnknownCharNames()) {
+ for (code = 0; code < 256; ++code) {
+ if (!toUnicode[code]) {
+ toUnicode[code] = code;
+ }
+ }
}
// construct the char code -> Unicode mapping object
@@ -973,10 +995,10 @@ Gushort *Gfx8BitFont::getCodeToGIDMap(FoFiTrueType *ff) {
useMacRoman = gTrue;
}
} else {
- if (macRomanCmap >= 0) {
- cmap = macRomanCmap;
- } else if (msSymbolCmap >= 0) {
+ if (msSymbolCmap >= 0) {
cmap = msSymbolCmap;
+ } else if (macRomanCmap >= 0) {
+ cmap = macRomanCmap;
}
}
diff --git a/Build/source/libs/xpdf/xpdf/GfxFont.h b/Build/source/libs/xpdf/xpdf/GfxFont.h
index 62dfd0881ad..d076692fc86 100644
--- a/Build/source/libs/xpdf/xpdf/GfxFont.h
+++ b/Build/source/libs/xpdf/xpdf/GfxFont.h
@@ -35,12 +35,16 @@ enum GfxFontType {
fontUnknownType,
fontType1,
fontType1C,
+ fontType1COT,
fontType3,
fontTrueType,
+ fontTrueTypeOT,
//----- GfxCIDFont
fontCIDType0,
fontCIDType0C,
- fontCIDType2
+ fontCIDType0COT,
+ fontCIDType2,
+ fontCIDType2OT
};
//------------------------------------------------------------------------
@@ -127,6 +131,7 @@ public:
GString *getExtFontFile() { return extFontFile; }
// Get font descriptor flags.
+ int getFlags() { return flags; }
GBool isFixedWidth() { return flags & fontFixedWidth; }
GBool isSerif() { return flags & fontSerif; }
GBool isSymbolic() { return flags & fontSymbolic; }
diff --git a/Build/source/libs/xpdf/xpdf/GfxState.cc b/Build/source/libs/xpdf/xpdf/GfxState.cc
index 051c7b645c8..67b4f6fd92d 100644
--- a/Build/source/libs/xpdf/xpdf/GfxState.cc
+++ b/Build/source/libs/xpdf/xpdf/GfxState.cc
@@ -34,10 +34,12 @@ static inline double clip01(double x) {
//------------------------------------------------------------------------
-static struct {
+struct GfxBlendModeInfo {
char *name;
GfxBlendMode mode;
-} gfxBlendModeNames[] = {
+};
+
+static GfxBlendModeInfo gfxBlendModeNames[] = {
{ "Normal", gfxBlendNormal },
{ "Compatible", gfxBlendNormal },
{ "Multiply", gfxBlendMultiply },
@@ -58,7 +60,7 @@ static struct {
};
#define nGfxBlendModeNames \
- ((int)((sizeof(gfxBlendModeNames) / sizeof(char *))))
+ ((int)((sizeof(gfxBlendModeNames) / sizeof(GfxBlendModeInfo))))
//------------------------------------------------------------------------
@@ -186,6 +188,10 @@ void GfxDeviceGrayColorSpace::getCMYK(GfxColor *color, GfxCMYK *cmyk) {
cmyk->k = clip01(gfxColorComp1 - color->c[0]);
}
+void GfxDeviceGrayColorSpace::getDefaultColor(GfxColor *color) {
+ color->c[0] = 0;
+}
+
//------------------------------------------------------------------------
// GfxCalGrayColorSpace
//------------------------------------------------------------------------
@@ -271,6 +277,10 @@ void GfxCalGrayColorSpace::getCMYK(GfxColor *color, GfxCMYK *cmyk) {
cmyk->k = clip01(gfxColorComp1 - color->c[0]);
}
+void GfxCalGrayColorSpace::getDefaultColor(GfxColor *color) {
+ color->c[0] = 0;
+}
+
//------------------------------------------------------------------------
// GfxDeviceRGBColorSpace
//------------------------------------------------------------------------
@@ -316,6 +326,12 @@ void GfxDeviceRGBColorSpace::getCMYK(GfxColor *color, GfxCMYK *cmyk) {
cmyk->k = k;
}
+void GfxDeviceRGBColorSpace::getDefaultColor(GfxColor *color) {
+ color->c[0] = 0;
+ color->c[1] = 0;
+ color->c[2] = 0;
+}
+
//------------------------------------------------------------------------
// GfxCalRGBColorSpace
//------------------------------------------------------------------------
@@ -447,6 +463,12 @@ void GfxCalRGBColorSpace::getCMYK(GfxColor *color, GfxCMYK *cmyk) {
cmyk->k = k;
}
+void GfxCalRGBColorSpace::getDefaultColor(GfxColor *color) {
+ color->c[0] = 0;
+ color->c[1] = 0;
+ color->c[2] = 0;
+}
+
//------------------------------------------------------------------------
// GfxDeviceCMYKColorSpace
//------------------------------------------------------------------------
@@ -537,6 +559,13 @@ void GfxDeviceCMYKColorSpace::getCMYK(GfxColor *color, GfxCMYK *cmyk) {
cmyk->k = clip01(color->c[3]);
}
+void GfxDeviceCMYKColorSpace::getDefaultColor(GfxColor *color) {
+ color->c[0] = 0;
+ color->c[1] = 0;
+ color->c[2] = 0;
+ color->c[3] = gfxColorComp1;
+}
+
//------------------------------------------------------------------------
// GfxLabColorSpace
//------------------------------------------------------------------------
@@ -714,6 +743,24 @@ void GfxLabColorSpace::getCMYK(GfxColor *color, GfxCMYK *cmyk) {
cmyk->k = k;
}
+void GfxLabColorSpace::getDefaultColor(GfxColor *color) {
+ color->c[0] = 0;
+ if (aMin > 0) {
+ color->c[1] = dblToCol(aMin);
+ } else if (aMax < 0) {
+ color->c[1] = dblToCol(aMax);
+ } else {
+ color->c[1] = 0;
+ }
+ if (bMin > 0) {
+ color->c[2] = dblToCol(bMin);
+ } else if (bMax < 0) {
+ color->c[2] = dblToCol(bMax);
+ } else {
+ color->c[2] = 0;
+ }
+}
+
void GfxLabColorSpace::getDefaultRanges(double *decodeLow, double *decodeRange,
int maxImgPixel) {
decodeLow[0] = 0;
@@ -839,6 +886,20 @@ void GfxICCBasedColorSpace::getCMYK(GfxColor *color, GfxCMYK *cmyk) {
alt->getCMYK(color, cmyk);
}
+void GfxICCBasedColorSpace::getDefaultColor(GfxColor *color) {
+ int i;
+
+ for (i = 0; i < nComps; ++i) {
+ if (rangeMin[i] > 0) {
+ color->c[i] = dblToCol(rangeMin[i]);
+ } else if (rangeMax[i] < 0) {
+ color->c[i] = dblToCol(rangeMax[i]);
+ } else {
+ color->c[i] = 0;
+ }
+ }
+}
+
void GfxICCBasedColorSpace::getDefaultRanges(double *decodeLow,
double *decodeRange,
int maxImgPixel) {
@@ -991,6 +1052,10 @@ void GfxIndexedColorSpace::getCMYK(GfxColor *color, GfxCMYK *cmyk) {
base->getCMYK(mapColorToBase(color, &color2), cmyk);
}
+void GfxIndexedColorSpace::getDefaultColor(GfxColor *color) {
+ color->c[0] = 0;
+}
+
void GfxIndexedColorSpace::getDefaultRanges(double *decodeLow,
double *decodeRange,
int maxImgPixel) {
@@ -1008,6 +1073,7 @@ GfxSeparationColorSpace::GfxSeparationColorSpace(GString *nameA,
name = nameA;
alt = altA;
func = funcA;
+ nonMarking = !name->cmp("None");
}
GfxSeparationColorSpace::~GfxSeparationColorSpace() {
@@ -1104,6 +1170,10 @@ void GfxSeparationColorSpace::getCMYK(GfxColor *color, GfxCMYK *cmyk) {
alt->getCMYK(&color2, cmyk);
}
+void GfxSeparationColorSpace::getDefaultColor(GfxColor *color) {
+ color->c[0] = gfxColorComp1;
+}
+
//------------------------------------------------------------------------
// GfxDeviceNColorSpace
//------------------------------------------------------------------------
@@ -1114,6 +1184,7 @@ GfxDeviceNColorSpace::GfxDeviceNColorSpace(int nCompsA,
nComps = nCompsA;
alt = altA;
func = funcA;
+ nonMarking = gFalse;
}
GfxDeviceNColorSpace::~GfxDeviceNColorSpace() {
@@ -1134,6 +1205,7 @@ GfxColorSpace *GfxDeviceNColorSpace::copy() {
for (i = 0; i < nComps; ++i) {
cs->names[i] = names[i]->copy();
}
+ cs->nonMarking = nonMarking;
return cs;
}
@@ -1183,8 +1255,12 @@ GfxColorSpace *GfxDeviceNColorSpace::parse(Array *arr) {
}
obj1.free();
cs = new GfxDeviceNColorSpace(nCompsA, altA, funcA);
+ cs->nonMarking = gTrue;
for (i = 0; i < nCompsA; ++i) {
cs->names[i] = namesA[i];
+ if (namesA[i]->cmp("None")) {
+ cs->nonMarking = gFalse;
+ }
}
return cs;
@@ -1245,6 +1321,14 @@ void GfxDeviceNColorSpace::getCMYK(GfxColor *color, GfxCMYK *cmyk) {
alt->getCMYK(&color2, cmyk);
}
+void GfxDeviceNColorSpace::getDefaultColor(GfxColor *color) {
+ int i;
+
+ for (i = 0; i < nComps; ++i) {
+ color->c[i] = gfxColorComp1;
+ }
+}
+
//------------------------------------------------------------------------
// GfxPatternColorSpace
//------------------------------------------------------------------------
@@ -1300,6 +1384,10 @@ void GfxPatternColorSpace::getCMYK(GfxColor *color, GfxCMYK *cmyk) {
cmyk->k = 1;
}
+void GfxPatternColorSpace::getDefaultColor(GfxColor *color) {
+ // not used
+}
+
//------------------------------------------------------------------------
// Pattern
//------------------------------------------------------------------------
@@ -3113,6 +3201,11 @@ GfxImageColorMap::GfxImageColorMap(int bitsA, Object *decode,
maxPixel = (1 << bits) - 1;
colorSpace = colorSpaceA;
+ // initialize
+ for (k = 0; k < gfxColorMaxComps; ++k) {
+ lookup[k] = NULL;
+ }
+
// get decode map
if (decode->isNull()) {
nComps = colorSpace->getNComps();
@@ -3147,9 +3240,6 @@ GfxImageColorMap::GfxImageColorMap(int bitsA, Object *decode,
// Optimization: for Indexed and Separation color spaces (which have
// only one component), we store color values in the lookup table
// rather than component values.
- for (k = 0; k < gfxColorMaxComps; ++k) {
- lookup[k] = NULL;
- }
colorSpace2 = NULL;
nComps2 = 0;
if (colorSpace->getMode() == csIndexed) {
@@ -3506,10 +3596,12 @@ void GfxPath::offset(double dx, double dy) {
// GfxState
//------------------------------------------------------------------------
-GfxState::GfxState(double hDPI, double vDPI, PDFRectangle *pageBox,
+GfxState::GfxState(double hDPIA, double vDPIA, PDFRectangle *pageBox,
int rotateA, GBool upsideDown) {
double kx, ky;
+ hDPI = hDPIA;
+ vDPI = vDPIA;
rotate = rotateA;
px1 = pageBox->x1;
py1 = pageBox->y1;
@@ -3566,6 +3658,7 @@ GfxState::GfxState(double hDPI, double vDPI, PDFRectangle *pageBox,
strokeOpacity = 1;
fillOverprint = gFalse;
strokeOverprint = gFalse;
+ transfer[0] = transfer[1] = transfer[2] = transfer[3] = NULL;
lineWidth = 1;
lineDash = NULL;
@@ -3575,6 +3668,7 @@ GfxState::GfxState(double hDPI, double vDPI, PDFRectangle *pageBox,
lineJoin = 0;
lineCap = 0;
miterLimit = 10;
+ strokeAdjust = gFalse;
font = NULL;
fontSize = 0;
@@ -3601,6 +3695,8 @@ GfxState::GfxState(double hDPI, double vDPI, PDFRectangle *pageBox,
}
GfxState::~GfxState() {
+ int i;
+
if (fillColorSpace) {
delete fillColorSpace;
}
@@ -3613,6 +3709,11 @@ GfxState::~GfxState() {
if (strokePattern) {
delete strokePattern;
}
+ for (i = 0; i < 4; ++i) {
+ if (transfer[i]) {
+ delete transfer[i];
+ }
+ }
gfree(lineDash);
if (path) {
// this gets set to NULL by restore()
@@ -3625,6 +3726,8 @@ GfxState::~GfxState() {
// Used for copy();
GfxState::GfxState(GfxState *state) {
+ int i;
+
memcpy(this, state, sizeof(GfxState));
if (fillColorSpace) {
fillColorSpace = state->fillColorSpace->copy();
@@ -3638,6 +3741,11 @@ GfxState::GfxState(GfxState *state) {
if (strokePattern) {
strokePattern = state->strokePattern->copy();
}
+ for (i = 0; i < 4; ++i) {
+ if (transfer[i]) {
+ transfer[i] = state->transfer[i]->copy();
+ }
+ }
if (lineDashLength > 0) {
lineDash = (double *)gmallocn(lineDashLength, sizeof(double));
memcpy(lineDash, state->lineDash, lineDashLength * sizeof(double));
@@ -3783,6 +3891,15 @@ void GfxState::concatCTM(double a, double b, double c,
}
}
+void GfxState::shiftCTM(double tx, double ty) {
+ ctm[4] += tx;
+ ctm[5] += ty;
+ clipXMin += tx;
+ clipYMin += ty;
+ clipXMax += tx;
+ clipYMax += ty;
+}
+
void GfxState::setFillColorSpace(GfxColorSpace *colorSpace) {
if (fillColorSpace) {
delete fillColorSpace;
@@ -3811,6 +3928,17 @@ void GfxState::setStrokePattern(GfxPattern *pattern) {
strokePattern = pattern;
}
+void GfxState::setTransfer(Function **funcs) {
+ int i;
+
+ for (i = 0; i < 4; ++i) {
+ if (transfer[i]) {
+ delete transfer[i];
+ }
+ transfer[i] = funcs[i];
+ }
+}
+
void GfxState::setLineDash(double *dash, int length, double start) {
if (lineDash)
gfree(lineDash);
@@ -3865,6 +3993,69 @@ void GfxState::clip() {
}
}
+void GfxState::clipToStrokePath() {
+ double xMin, yMin, xMax, yMax, x, y, t0, t1;
+ GfxSubpath *subpath;
+ int i, j;
+
+ xMin = xMax = yMin = yMax = 0; // make gcc happy
+ for (i = 0; i < path->getNumSubpaths(); ++i) {
+ subpath = path->getSubpath(i);
+ for (j = 0; j < subpath->getNumPoints(); ++j) {
+ transform(subpath->getX(j), subpath->getY(j), &x, &y);
+ if (i == 0 && j == 0) {
+ xMin = xMax = x;
+ yMin = yMax = y;
+ } else {
+ if (x < xMin) {
+ xMin = x;
+ } else if (x > xMax) {
+ xMax = x;
+ }
+ if (y < yMin) {
+ yMin = y;
+ } else if (y > yMax) {
+ yMax = y;
+ }
+ }
+ }
+ }
+
+ // allow for the line width
+ //~ miter joins can extend farther than this
+ t0 = fabs(ctm[0]);
+ t1 = fabs(ctm[2]);
+ if (t0 > t1) {
+ xMin -= 0.5 * lineWidth * t0;
+ xMax += 0.5 * lineWidth * t0;
+ } else {
+ xMin -= 0.5 * lineWidth * t1;
+ xMax += 0.5 * lineWidth * t1;
+ }
+ t0 = fabs(ctm[0]);
+ t1 = fabs(ctm[3]);
+ if (t0 > t1) {
+ yMin -= 0.5 * lineWidth * t0;
+ yMax += 0.5 * lineWidth * t0;
+ } else {
+ yMin -= 0.5 * lineWidth * t1;
+ yMax += 0.5 * lineWidth * t1;
+ }
+
+ if (xMin > clipXMin) {
+ clipXMin = xMin;
+ }
+ if (yMin > clipYMin) {
+ clipYMin = yMin;
+ }
+ if (xMax < clipXMax) {
+ clipXMax = xMax;
+ }
+ if (yMax < clipYMax) {
+ clipYMax = yMax;
+ }
+}
+
void GfxState::textShift(double tx, double ty) {
double dx, dy;
diff --git a/Build/source/libs/xpdf/xpdf/GfxState.h b/Build/source/libs/xpdf/xpdf/GfxState.h
index e1d68013dfc..f85643dcc63 100644
--- a/Build/source/libs/xpdf/xpdf/GfxState.h
+++ b/Build/source/libs/xpdf/xpdf/GfxState.h
@@ -148,11 +148,18 @@ public:
// Return the number of color components.
virtual int getNComps() = 0;
+ // Get this color space's default color.
+ virtual void getDefaultColor(GfxColor *color) = 0;
+
// Return the default ranges for each component, assuming an image
// with a max pixel value of <maxImgPixel>.
virtual void getDefaultRanges(double *decodeLow, double *decodeRange,
int maxImgPixel);
+ // Returns true if painting operations in this color space never
+ // mark the page (e.g., the "None" colorant).
+ virtual GBool isNonMarking() { return gFalse; }
+
// Return the number of color space modes
static int getNumColorSpaceModes();
@@ -179,6 +186,7 @@ public:
virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
virtual int getNComps() { return 1; }
+ virtual void getDefaultColor(GfxColor *color);
private:
};
@@ -203,6 +211,7 @@ public:
virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
virtual int getNComps() { return 1; }
+ virtual void getDefaultColor(GfxColor *color);
// CalGray-specific access.
double getWhiteX() { return whiteX; }
@@ -237,6 +246,7 @@ public:
virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
virtual int getNComps() { return 3; }
+ virtual void getDefaultColor(GfxColor *color);
private:
};
@@ -261,6 +271,7 @@ public:
virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
virtual int getNComps() { return 3; }
+ virtual void getDefaultColor(GfxColor *color);
// CalRGB-specific access.
double getWhiteX() { return whiteX; }
@@ -299,6 +310,7 @@ public:
virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
virtual int getNComps() { return 4; }
+ virtual void getDefaultColor(GfxColor *color);
private:
};
@@ -323,6 +335,7 @@ public:
virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
virtual int getNComps() { return 3; }
+ virtual void getDefaultColor(GfxColor *color);
virtual void getDefaultRanges(double *decodeLow, double *decodeRange,
int maxImgPixel);
@@ -368,6 +381,7 @@ public:
virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
virtual int getNComps() { return nComps; }
+ virtual void getDefaultColor(GfxColor *color);
virtual void getDefaultRanges(double *decodeLow, double *decodeRange,
int maxImgPixel);
@@ -404,6 +418,7 @@ public:
virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
virtual int getNComps() { return 1; }
+ virtual void getDefaultColor(GfxColor *color);
virtual void getDefaultRanges(double *decodeLow, double *decodeRange,
int maxImgPixel);
@@ -442,6 +457,9 @@ public:
virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
virtual int getNComps() { return 1; }
+ virtual void getDefaultColor(GfxColor *color);
+
+ virtual GBool isNonMarking() { return nonMarking; }
// Separation-specific access.
GString *getName() { return name; }
@@ -453,6 +471,7 @@ private:
GString *name; // colorant name
GfxColorSpace *alt; // alternate color space
Function *func; // tint transform (into alternate color space)
+ GBool nonMarking;
};
//------------------------------------------------------------------------
@@ -475,6 +494,9 @@ public:
virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
virtual int getNComps() { return nComps; }
+ virtual void getDefaultColor(GfxColor *color);
+
+ virtual GBool isNonMarking() { return nonMarking; }
// DeviceN-specific access.
GString *getColorantName(int i) { return names[i]; }
@@ -488,6 +510,7 @@ private:
*names[gfxColorMaxComps];
GfxColorSpace *alt; // alternate color space
Function *func; // tint transform (into alternate color space)
+ GBool nonMarking;
};
//------------------------------------------------------------------------
@@ -510,6 +533,7 @@ public:
virtual void getCMYK(GfxColor *color, GfxCMYK *cmyk);
virtual int getNComps() { return 0; }
+ virtual void getDefaultColor(GfxColor *color);
// Pattern-specific access.
GfxColorSpace *getUnder() { return under; }
@@ -992,7 +1016,7 @@ public:
// Construct a default GfxState, for a device with resolution <hDPI>
// x <vDPI>, page box <pageBox>, page rotation <rotateA>, and
// coordinate system specified by <upsideDown>.
- GfxState(double hDPI, double vDPI, PDFRectangle *pageBox,
+ GfxState(double hDPIA, double vDPIA, PDFRectangle *pageBox,
int rotateA, GBool upsideDown);
// Destructor.
@@ -1002,6 +1026,8 @@ public:
GfxState *copy() { return new GfxState(this); }
// Accessors.
+ double getHDPI() { return hDPI; }
+ double getVDPI() { return vDPI; }
double *getCTM() { return ctm; }
double getX1() { return px1; }
double getY1() { return py1; }
@@ -1033,6 +1059,7 @@ public:
double getStrokeOpacity() { return strokeOpacity; }
GBool getFillOverprint() { return fillOverprint; }
GBool getStrokeOverprint() { return strokeOverprint; }
+ Function **getTransfer() { return transfer; }
double getLineWidth() { return lineWidth; }
void getLineDash(double **dash, int *length, double *start)
{ *dash = lineDash; *length = lineDashLength; *start = lineDashStart; }
@@ -1040,6 +1067,7 @@ public:
int getLineJoin() { return lineJoin; }
int getLineCap() { return lineCap; }
double getMiterLimit() { return miterLimit; }
+ GBool getStrokeAdjust() { return strokeAdjust; }
GfxFont *getFont() { return font; }
double getFontSize() { return fontSize; }
double *getTextMat() { return textMat; }
@@ -1087,6 +1115,7 @@ public:
double d, double e, double f);
void concatCTM(double a, double b, double c,
double d, double e, double f);
+ void shiftCTM(double tx, double ty);
void setFillColorSpace(GfxColorSpace *colorSpace);
void setStrokeColorSpace(GfxColorSpace *colorSpace);
void setFillColor(GfxColor *color) { fillColor = *color; }
@@ -1098,12 +1127,14 @@ public:
void setStrokeOpacity(double opac) { strokeOpacity = opac; }
void setFillOverprint(GBool op) { fillOverprint = op; }
void setStrokeOverprint(GBool op) { strokeOverprint = op; }
+ void setTransfer(Function **funcs);
void setLineWidth(double width) { lineWidth = width; }
void setLineDash(double *dash, int length, double start);
void setFlatness(int flatness1) { flatness = flatness1; }
void setLineJoin(int lineJoin1) { lineJoin = lineJoin1; }
void setLineCap(int lineCap1) { lineCap = lineCap1; }
void setMiterLimit(double limit) { miterLimit = limit; }
+ void setStrokeAdjust(GBool sa) { strokeAdjust = sa; }
void setFont(GfxFont *fontA, double fontSizeA)
{ font = fontA; fontSize = fontSizeA; }
void setTextMat(double a, double b, double c,
@@ -1137,6 +1168,7 @@ public:
// Update clip region.
void clip();
+ void clipToStrokePath();
// Text position.
void textSetPos(double tx, double ty) { lineX = tx; lineY = ty; }
@@ -1155,6 +1187,7 @@ public:
private:
+ double hDPI, vDPI; // resolution
double ctm[6]; // coord transform matrix
double px1, py1, px2, py2; // page corners (user coords)
double pageWidth, pageHeight; // page size (pixels)
@@ -1171,6 +1204,10 @@ private:
double strokeOpacity; // stroke opacity
GBool fillOverprint; // fill overprint
GBool strokeOverprint; // stroke overprint
+ Function *transfer[4]; // transfer function (entries may be: all
+ // NULL = identity; last three NULL =
+ // single function; all four non-NULL =
+ // R,G,B,gray functions)
double lineWidth; // line width
double *lineDash; // line dash
@@ -1180,6 +1217,7 @@ private:
int lineJoin; // line join style
int lineCap; // line cap style
double miterLimit; // line miter limit
+ GBool strokeAdjust; // stroke adjustment
GfxFont *font; // font
double fontSize; // font size
diff --git a/Build/source/libs/xpdf/xpdf/GlobalParams.cc b/Build/source/libs/xpdf/xpdf/GlobalParams.cc
index 7d4013818e4..2b07a1964fd 100644
--- a/Build/source/libs/xpdf/xpdf/GlobalParams.cc
+++ b/Build/source/libs/xpdf/xpdf/GlobalParams.cc
@@ -43,6 +43,10 @@
#endif
#include "GlobalParams.h"
+#ifdef WIN32
+# define strcasecmp stricmp
+#endif
+
#if MULTITHREADED
# define lockGlobalParams gLockMutex(&mutex)
# define lockUnicodeMapCache gLockMutex(&unicodeMapCacheMutex)
@@ -153,6 +157,251 @@ DisplayFontParam::~DisplayFontParam() {
}
}
+#ifdef WIN32
+
+//------------------------------------------------------------------------
+// WinFontInfo
+//------------------------------------------------------------------------
+
+class WinFontInfo: public DisplayFontParam {
+public:
+
+ GBool bold, italic;
+
+ static WinFontInfo *make(GString *nameA, GBool boldA, GBool italicA,
+ HKEY regKey, char *winFontDir);
+ WinFontInfo(GString *nameA, GBool boldA, GBool italicA,
+ GString *fileNameA);
+ virtual ~WinFontInfo();
+ GBool equals(WinFontInfo *fi);
+};
+
+WinFontInfo *WinFontInfo::make(GString *nameA, GBool boldA, GBool italicA,
+ HKEY regKey, char *winFontDir) {
+ GString *regName;
+ GString *fileNameA;
+ char buf[MAX_PATH];
+ DWORD n;
+ char c;
+ int i;
+
+ //----- find the font file
+ fileNameA = NULL;
+ regName = nameA->copy();
+ if (boldA) {
+ regName->append(" Bold");
+ }
+ if (italicA) {
+ regName->append(" Italic");
+ }
+ regName->append(" (TrueType)");
+ n = sizeof(buf);
+ if (RegQueryValueEx(regKey, regName->getCString(), NULL, NULL,
+ (LPBYTE)buf, &n) == ERROR_SUCCESS) {
+ fileNameA = new GString(winFontDir);
+ fileNameA->append('\\')->append(buf);
+ }
+ delete regName;
+ if (!fileNameA) {
+ delete nameA;
+ return NULL;
+ }
+
+ //----- normalize the font name
+ i = 0;
+ while (i < nameA->getLength()) {
+ c = nameA->getChar(i);
+ if (c == ' ' || c == ',' || c == '-') {
+ nameA->del(i);
+ } else {
+ ++i;
+ }
+ }
+
+ return new WinFontInfo(nameA, boldA, italicA, fileNameA);
+}
+
+WinFontInfo::WinFontInfo(GString *nameA, GBool boldA, GBool italicA,
+ GString *fileNameA):
+ DisplayFontParam(nameA, displayFontTT)
+{
+ bold = boldA;
+ italic = italicA;
+ tt.fileName = fileNameA;
+}
+
+WinFontInfo::~WinFontInfo() {
+}
+
+GBool WinFontInfo::equals(WinFontInfo *fi) {
+ return !name->cmp(fi->name) && bold == fi->bold && italic == fi->italic;
+}
+
+//------------------------------------------------------------------------
+// WinFontList
+//------------------------------------------------------------------------
+
+class WinFontList {
+public:
+
+ WinFontList(char *winFontDirA);
+ ~WinFontList();
+ WinFontInfo *find(GString *font);
+
+private:
+
+ void add(WinFontInfo *fi);
+ static int CALLBACK enumFunc1(CONST LOGFONT *font,
+ CONST TEXTMETRIC *metrics,
+ DWORD type, LPARAM data);
+ static int CALLBACK enumFunc2(CONST LOGFONT *font,
+ CONST TEXTMETRIC *metrics,
+ DWORD type, LPARAM data);
+
+ GList *fonts; // [WinFontInfo]
+ HDC dc; // (only used during enumeration)
+ HKEY regKey; // (only used during enumeration)
+ char *winFontDir; // (only used during enumeration)
+};
+
+WinFontList::WinFontList(char *winFontDirA) {
+ OSVERSIONINFO version;
+ char *path;
+
+ fonts = new GList();
+ dc = GetDC(NULL);
+ winFontDir = winFontDirA;
+ version.dwOSVersionInfoSize = sizeof(version);
+ GetVersionEx(&version);
+ if (version.dwPlatformId == VER_PLATFORM_WIN32_NT) {
+ path = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts\\";
+ } else {
+ path = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Fonts\\";
+ }
+ if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, path, 0,
+ KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS,
+ &regKey) == ERROR_SUCCESS) {
+ EnumFonts(dc, NULL, &WinFontList::enumFunc1, (LPARAM)this);
+ RegCloseKey(regKey);
+ }
+ ReleaseDC(NULL, dc);
+}
+
+WinFontList::~WinFontList() {
+ deleteGList(fonts, WinFontInfo);
+}
+
+void WinFontList::add(WinFontInfo *fi) {
+ int i;
+
+ for (i = 0; i < fonts->getLength(); ++i) {
+ if (((WinFontInfo *)fonts->get(i))->equals(fi)) {
+ delete fi;
+ return;
+ }
+ }
+ fonts->append(fi);
+}
+
+WinFontInfo *WinFontList::find(GString *font) {
+ GString *name;
+ GBool bold, italic;
+ WinFontInfo *fi;
+ char c;
+ int n, i;
+
+ name = font->copy();
+
+ // remove space, comma, dash chars
+ i = 0;
+ while (i < name->getLength()) {
+ c = name->getChar(i);
+ if (c == ' ' || c == ',' || c == '-') {
+ name->del(i);
+ } else {
+ ++i;
+ }
+ }
+ n = name->getLength();
+
+ // remove trailing "MT" (Foo-MT, Foo-BoldMT, etc.)
+ if (!strcmp(name->getCString() + n - 2, "MT")) {
+ name->del(n - 2, 2);
+ n -= 2;
+ }
+
+ // look for "Italic"
+ if (!strcmp(name->getCString() + n - 6, "Italic")) {
+ name->del(n - 6, 6);
+ italic = gTrue;
+ n -= 6;
+ } else {
+ italic = gFalse;
+ }
+
+ // look for "Bold"
+ if (!strcmp(name->getCString() + n - 4, "Bold")) {
+ name->del(n - 4, 4);
+ bold = gTrue;
+ n -= 4;
+ } else {
+ bold = gFalse;
+ }
+
+ // remove trailing "MT" (FooMT-Bold, etc.)
+ if (!strcmp(name->getCString() + n - 2, "MT")) {
+ name->del(n - 2, 2);
+ n -= 2;
+ }
+
+ // remove trailing "PS"
+ if (!strcmp(name->getCString() + n - 2, "PS")) {
+ name->del(n - 2, 2);
+ n -= 2;
+ }
+
+ // search for the font
+ fi = NULL;
+ for (i = 0; i < fonts->getLength(); ++i) {
+ fi = (WinFontInfo *)fonts->get(i);
+ if (!fi->name->cmp(name) && fi->bold == bold && fi->italic == italic) {
+ break;
+ }
+ fi = NULL;
+ }
+
+ delete name;
+ return fi;
+}
+
+int CALLBACK WinFontList::enumFunc1(CONST LOGFONT *font,
+ CONST TEXTMETRIC *metrics,
+ DWORD type, LPARAM data) {
+ WinFontList *fl = (WinFontList *)data;
+
+ EnumFonts(fl->dc, font->lfFaceName, &WinFontList::enumFunc2, (LPARAM)fl);
+ return 1;
+}
+
+int CALLBACK WinFontList::enumFunc2(CONST LOGFONT *font,
+ CONST TEXTMETRIC *metrics,
+ DWORD type, LPARAM data) {
+ WinFontList *fl = (WinFontList *)data;
+ WinFontInfo *fi;
+
+ if (type & TRUETYPE_FONTTYPE) {
+ if ((fi = WinFontInfo::make(new GString(font->lfFaceName),
+ font->lfWeight >= 600,
+ font->lfItalic ? gTrue : gFalse,
+ fl->regKey, fl->winFontDir))) {
+ fl->add(fi);
+ }
+ }
+ return 1;
+}
+
+#endif // WIN32
+
//------------------------------------------------------------------------
// PSFontParam
//------------------------------------------------------------------------
@@ -173,6 +422,41 @@ PSFontParam::~PSFontParam() {
}
}
+#ifndef PDF_PARSER_ONLY
+//------------------------------------------------------------------------
+// KeyBinding
+//------------------------------------------------------------------------
+
+KeyBinding::KeyBinding(int codeA, int modsA, int contextA, char *cmd0) {
+ code = codeA;
+ mods = modsA;
+ context = contextA;
+ cmds = new GList();
+ cmds->append(new GString(cmd0));
+}
+
+KeyBinding::KeyBinding(int codeA, int modsA, int contextA,
+ char *cmd0, char *cmd1) {
+ code = codeA;
+ mods = modsA;
+ context = contextA;
+ cmds = new GList();
+ cmds->append(new GString(cmd0));
+ cmds->append(new GString(cmd1));
+}
+
+KeyBinding::KeyBinding(int codeA, int modsA, int contextA, GList *cmdsA) {
+ code = codeA;
+ mods = modsA;
+ context = contextA;
+ cmds = cmdsA;
+}
+
+KeyBinding::~KeyBinding() {
+ deleteGList(cmds, GString);
+}
+#endif
+
#ifdef ENABLE_PLUGINS
//------------------------------------------------------------------------
// Plugin
@@ -525,6 +809,7 @@ GlobalParams::GlobalParams(char *cfgFileName) {
psEmbedTrueType = gTrue;
psEmbedCIDPostScript = gTrue;
psEmbedCIDTrueType = gTrue;
+ psPreload = gFalse;
psOPI = gFalse;
psASCIIHex = gFalse;
textEncoding = new GString("Latin1");
@@ -543,9 +828,21 @@ GlobalParams::GlobalParams(char *cfgFileName) {
enableT1lib = gTrue;
enableFreeType = gTrue;
antialias = gTrue;
+ vectorAntialias = gTrue;
+ strokeAdjust = gTrue;
+ screenType = screenUnset;
+ screenSize = -1;
+ screenDotRadius = -1;
+ screenGamma = 1.0;
+ screenBlackThreshold = 0.0;
+ screenWhiteThreshold = 1.0;
urlCommand = NULL;
movieCommand = NULL;
mapNumericCharNames = gTrue;
+ mapUnknownCharNames = gFalse;
+#ifndef PDF_PARSER_ONLY
+ createDefaultKeyBindings();
+#endif
printCommands = gFalse;
errQuiet = gFalse;
@@ -555,6 +852,10 @@ GlobalParams::GlobalParams(char *cfgFileName) {
unicodeMapCache = new UnicodeMapCache();
cMapCache = new CMapCache();
+#ifdef WIN32
+ winFontList = NULL;
+#endif
+
#ifdef ENABLE_PLUGINS
plugins = new GList();
securityHandlers = new GList();
@@ -616,180 +917,342 @@ GlobalParams::GlobalParams(char *cfgFileName) {
}
}
if (f) {
+#ifndef PDF_PARSER_ONLY
parseFile(fileName, f);
+#endif
delete fileName;
fclose(f);
}
}
+#ifndef PDF_PARSER_ONLY
+void GlobalParams::createDefaultKeyBindings() {
+ keyBindings = new GList();
+
+ //----- mouse buttons
+ keyBindings->append(new KeyBinding(xpdfKeyCodeMousePress1, xpdfKeyModNone,
+ xpdfKeyContextAny, "startSelection"));
+ keyBindings->append(new KeyBinding(xpdfKeyCodeMouseRelease1, xpdfKeyModNone,
+ xpdfKeyContextAny, "endSelection",
+ "followLinkNoSel"));
+ keyBindings->append(new KeyBinding(xpdfKeyCodeMousePress2, xpdfKeyModNone,
+ xpdfKeyContextAny, "startPan"));
+ keyBindings->append(new KeyBinding(xpdfKeyCodeMouseRelease2, xpdfKeyModNone,
+ xpdfKeyContextAny, "endPan"));
+ keyBindings->append(new KeyBinding(xpdfKeyCodeMousePress3, xpdfKeyModNone,
+ xpdfKeyContextAny, "postPopupMenu"));
+ keyBindings->append(new KeyBinding(xpdfKeyCodeMousePress4, xpdfKeyModNone,
+ xpdfKeyContextAny,
+ "scrollUpPrevPage(16)"));
+ keyBindings->append(new KeyBinding(xpdfKeyCodeMousePress5, xpdfKeyModNone,
+ xpdfKeyContextAny,
+ "scrollDownNextPage(16)"));
+ keyBindings->append(new KeyBinding(xpdfKeyCodeMousePress6, xpdfKeyModNone,
+ xpdfKeyContextAny, "scrollLeft(16)"));
+ keyBindings->append(new KeyBinding(xpdfKeyCodeMousePress7, xpdfKeyModNone,
+ xpdfKeyContextAny, "scrollRight(16)"));
+
+ //----- keys
+ keyBindings->append(new KeyBinding(xpdfKeyCodeHome, xpdfKeyModCtrl,
+ xpdfKeyContextAny, "gotoPage(1)"));
+ keyBindings->append(new KeyBinding(xpdfKeyCodeHome, xpdfKeyModNone,
+ xpdfKeyContextAny, "scrollToTopLeft"));
+ keyBindings->append(new KeyBinding(xpdfKeyCodeEnd, xpdfKeyModCtrl,
+ xpdfKeyContextAny, "gotoLastPage"));
+ keyBindings->append(new KeyBinding(xpdfKeyCodeEnd, xpdfKeyModNone,
+ xpdfKeyContextAny,
+ "scrollToBottomRight"));
+ keyBindings->append(new KeyBinding(xpdfKeyCodePgUp, xpdfKeyModNone,
+ xpdfKeyContextAny, "pageUp"));
+ keyBindings->append(new KeyBinding(xpdfKeyCodeBackspace, xpdfKeyModNone,
+ xpdfKeyContextAny, "pageUp"));
+ keyBindings->append(new KeyBinding(xpdfKeyCodeDelete, xpdfKeyModNone,
+ xpdfKeyContextAny, "pageUp"));
+ keyBindings->append(new KeyBinding(xpdfKeyCodePgDn, xpdfKeyModNone,
+ xpdfKeyContextAny, "pageDown"));
+ keyBindings->append(new KeyBinding(' ', xpdfKeyModNone,
+ xpdfKeyContextAny, "pageDown"));
+ keyBindings->append(new KeyBinding(xpdfKeyCodeLeft, xpdfKeyModNone,
+ xpdfKeyContextAny, "scrollLeft(16)"));
+ keyBindings->append(new KeyBinding(xpdfKeyCodeRight, xpdfKeyModNone,
+ xpdfKeyContextAny, "scrollRight(16)"));
+ keyBindings->append(new KeyBinding(xpdfKeyCodeUp, xpdfKeyModNone,
+ xpdfKeyContextAny, "scrollUp(16)"));
+ keyBindings->append(new KeyBinding(xpdfKeyCodeDown, xpdfKeyModNone,
+ xpdfKeyContextAny, "scrollDown(16)"));
+ keyBindings->append(new KeyBinding('o', xpdfKeyModNone,
+ xpdfKeyContextAny, "open"));
+ keyBindings->append(new KeyBinding('O', xpdfKeyModNone,
+ xpdfKeyContextAny, "open"));
+ keyBindings->append(new KeyBinding('r', xpdfKeyModNone,
+ xpdfKeyContextAny, "reload"));
+ keyBindings->append(new KeyBinding('R', xpdfKeyModNone,
+ xpdfKeyContextAny, "reload"));
+ keyBindings->append(new KeyBinding('f', xpdfKeyModNone,
+ xpdfKeyContextAny, "find"));
+ keyBindings->append(new KeyBinding('F', xpdfKeyModNone,
+ xpdfKeyContextAny, "find"));
+ keyBindings->append(new KeyBinding('f', xpdfKeyModCtrl,
+ xpdfKeyContextAny, "find"));
+ keyBindings->append(new KeyBinding('g', xpdfKeyModCtrl,
+ xpdfKeyContextAny, "findNext"));
+ keyBindings->append(new KeyBinding('p', xpdfKeyModCtrl,
+ xpdfKeyContextAny, "print"));
+ keyBindings->append(new KeyBinding('n', xpdfKeyModNone,
+ xpdfKeyContextScrLockOff, "nextPage"));
+ keyBindings->append(new KeyBinding('N', xpdfKeyModNone,
+ xpdfKeyContextScrLockOff, "nextPage"));
+ keyBindings->append(new KeyBinding('n', xpdfKeyModNone,
+ xpdfKeyContextScrLockOn,
+ "nextPageNoScroll"));
+ keyBindings->append(new KeyBinding('N', xpdfKeyModNone,
+ xpdfKeyContextScrLockOn,
+ "nextPageNoScroll"));
+ keyBindings->append(new KeyBinding('p', xpdfKeyModNone,
+ xpdfKeyContextScrLockOff, "prevPage"));
+ keyBindings->append(new KeyBinding('P', xpdfKeyModNone,
+ xpdfKeyContextScrLockOff, "prevPage"));
+ keyBindings->append(new KeyBinding('p', xpdfKeyModNone,
+ xpdfKeyContextScrLockOn,
+ "prevPageNoScroll"));
+ keyBindings->append(new KeyBinding('P', xpdfKeyModNone,
+ xpdfKeyContextScrLockOn,
+ "prevPageNoScroll"));
+ keyBindings->append(new KeyBinding('v', xpdfKeyModNone,
+ xpdfKeyContextAny, "goForward"));
+ keyBindings->append(new KeyBinding('b', xpdfKeyModNone,
+ xpdfKeyContextAny, "goBackward"));
+ keyBindings->append(new KeyBinding('g', xpdfKeyModNone,
+ xpdfKeyContextAny, "focusToPageNum"));
+ keyBindings->append(new KeyBinding('0', xpdfKeyModNone,
+ xpdfKeyContextAny, "zoomPercent(125)"));
+ keyBindings->append(new KeyBinding('+', xpdfKeyModNone,
+ xpdfKeyContextAny, "zoomIn"));
+ keyBindings->append(new KeyBinding('-', xpdfKeyModNone,
+ xpdfKeyContextAny, "zoomOut"));
+ keyBindings->append(new KeyBinding('z', xpdfKeyModNone,
+ xpdfKeyContextAny, "zoomFitPage"));
+ keyBindings->append(new KeyBinding('w', xpdfKeyModNone,
+ xpdfKeyContextAny, "zoomFitWidth"));
+ keyBindings->append(new KeyBinding('f', xpdfKeyModAlt,
+ xpdfKeyContextAny,
+ "toggleFullScreenMode"));
+ keyBindings->append(new KeyBinding('l', xpdfKeyModCtrl,
+ xpdfKeyContextAny, "redraw"));
+ keyBindings->append(new KeyBinding('w', xpdfKeyModCtrl,
+ xpdfKeyContextAny, "closeWindow"));
+ keyBindings->append(new KeyBinding('?', xpdfKeyModNone,
+ xpdfKeyContextAny, "about"));
+ keyBindings->append(new KeyBinding('q', xpdfKeyModNone,
+ xpdfKeyContextAny, "quit"));
+ keyBindings->append(new KeyBinding('Q', xpdfKeyModNone,
+ xpdfKeyContextAny, "quit"));
+}
+
void GlobalParams::parseFile(GString *fileName, FILE *f) {
int line;
- GList *tokens;
- GString *cmd, *incFile;
- char *p1, *p2;
char buf[512];
- FILE *f2;
line = 1;
while (getLine(buf, sizeof(buf) - 1, f)) {
+ parseLine(buf, fileName, line);
+ ++line;
+ }
+}
- // break the line into tokens
- tokens = new GList();
- p1 = buf;
- while (*p1) {
- for (; *p1 && isspace(*p1); ++p1) ;
- if (!*p1) {
- break;
- }
- if (*p1 == '"' || *p1 == '\'') {
- for (p2 = p1 + 1; *p2 && *p2 != *p1; ++p2) ;
- ++p1;
- } else {
- for (p2 = p1 + 1; *p2 && !isspace(*p2); ++p2) ;
- }
- tokens->append(new GString(p1, p2 - p1));
- p1 = *p2 ? p2 + 1 : p2;
- }
+void GlobalParams::parseLine(char *buf, GString *fileName, int line) {
+ GList *tokens;
+ GString *cmd, *incFile;
+ char *p1, *p2;
+ FILE *f2;
- if (tokens->getLength() > 0 &&
- ((GString *)tokens->get(0))->getChar(0) != '#') {
- cmd = (GString *)tokens->get(0);
- if (!cmd->cmp("include")) {
- if (tokens->getLength() == 2) {
- incFile = (GString *)tokens->get(1);
- if ((f2 = fopen(incFile->getCString(), "r"))) {
- parseFile(incFile, f2);
- fclose(f2);
- } else {
- error(-1, "Couldn't find included config file: '%s' (%s:%d)",
- incFile->getCString(), fileName->getCString(), line);
- }
+ // break the line into tokens
+ tokens = new GList();
+ p1 = buf;
+ while (*p1) {
+ for (; *p1 && isspace(*p1); ++p1) ;
+ if (!*p1) {
+ break;
+ }
+ if (*p1 == '"' || *p1 == '\'') {
+ for (p2 = p1 + 1; *p2 && *p2 != *p1; ++p2) ;
+ ++p1;
+ } else {
+ for (p2 = p1 + 1; *p2 && !isspace(*p2); ++p2) ;
+ }
+ tokens->append(new GString(p1, p2 - p1));
+ p1 = *p2 ? p2 + 1 : p2;
+ }
+
+ // parse the line
+ if (tokens->getLength() > 0 &&
+ ((GString *)tokens->get(0))->getChar(0) != '#') {
+ cmd = (GString *)tokens->get(0);
+ if (!cmd->cmp("include")) {
+ if (tokens->getLength() == 2) {
+ incFile = (GString *)tokens->get(1);
+ if ((f2 = fopen(incFile->getCString(), "r"))) {
+ parseFile(incFile, f2);
+ fclose(f2);
} else {
- error(-1, "Bad 'include' config file command (%s:%d)",
- fileName->getCString(), line);
+ error(-1, "Couldn't find included config file: '%s' (%s:%d)",
+ incFile->getCString(), fileName->getCString(), line);
}
- } else if (!cmd->cmp("nameToUnicode")) {
- parseNameToUnicode(tokens, fileName, line);
- } else if (!cmd->cmp("cidToUnicode")) {
- parseCIDToUnicode(tokens, fileName, line);
- } else if (!cmd->cmp("unicodeToUnicode")) {
- parseUnicodeToUnicode(tokens, fileName, line);
- } else if (!cmd->cmp("unicodeMap")) {
- parseUnicodeMap(tokens, fileName, line);
- } else if (!cmd->cmp("cMapDir")) {
- parseCMapDir(tokens, fileName, line);
- } else if (!cmd->cmp("toUnicodeDir")) {
- parseToUnicodeDir(tokens, fileName, line);
- } else if (!cmd->cmp("displayFontT1")) {
- parseDisplayFont(tokens, displayFonts, displayFontT1, fileName, line);
- } else if (!cmd->cmp("displayFontTT")) {
- parseDisplayFont(tokens, displayFonts, displayFontTT, fileName, line);
- } else if (!cmd->cmp("displayNamedCIDFontT1")) {
- parseDisplayFont(tokens, displayNamedCIDFonts,
- displayFontT1, fileName, line);
- } else if (!cmd->cmp("displayCIDFontT1")) {
- parseDisplayFont(tokens, displayCIDFonts,
- displayFontT1, fileName, line);
- } else if (!cmd->cmp("displayNamedCIDFontTT")) {
- parseDisplayFont(tokens, displayNamedCIDFonts,
- displayFontTT, fileName, line);
- } else if (!cmd->cmp("displayCIDFontTT")) {
- parseDisplayFont(tokens, displayCIDFonts,
- displayFontTT, fileName, line);
- } else if (!cmd->cmp("psFile")) {
- parsePSFile(tokens, fileName, line);
- } else if (!cmd->cmp("psFont")) {
- parsePSFont(tokens, fileName, line);
- } else if (!cmd->cmp("psNamedFont16")) {
- parsePSFont16("psNamedFont16", psNamedFonts16,
- tokens, fileName, line);
- } else if (!cmd->cmp("psFont16")) {
- parsePSFont16("psFont16", psFonts16, tokens, fileName, line);
- } else if (!cmd->cmp("psPaperSize")) {
- parsePSPaperSize(tokens, fileName, line);
- } else if (!cmd->cmp("psImageableArea")) {
- parsePSImageableArea(tokens, fileName, line);
- } else if (!cmd->cmp("psCrop")) {
- parseYesNo("psCrop", &psCrop, tokens, fileName, line);
- } else if (!cmd->cmp("psExpandSmaller")) {
- parseYesNo("psExpandSmaller", &psExpandSmaller,
- tokens, fileName, line);
- } else if (!cmd->cmp("psShrinkLarger")) {
- parseYesNo("psShrinkLarger", &psShrinkLarger, tokens, fileName, line);
- } else if (!cmd->cmp("psCenter")) {
- parseYesNo("psCenter", &psCenter, tokens, fileName, line);
- } else if (!cmd->cmp("psDuplex")) {
- parseYesNo("psDuplex", &psDuplex, tokens, fileName, line);
- } else if (!cmd->cmp("psLevel")) {
- parsePSLevel(tokens, fileName, line);
- } else if (!cmd->cmp("psEmbedType1Fonts")) {
- parseYesNo("psEmbedType1", &psEmbedType1, tokens, fileName, line);
- } else if (!cmd->cmp("psEmbedTrueTypeFonts")) {
- parseYesNo("psEmbedTrueType", &psEmbedTrueType,
- tokens, fileName, line);
- } else if (!cmd->cmp("psEmbedCIDPostScriptFonts")) {
- parseYesNo("psEmbedCIDPostScript", &psEmbedCIDPostScript,
- tokens, fileName, line);
- } else if (!cmd->cmp("psEmbedCIDTrueTypeFonts")) {
- parseYesNo("psEmbedCIDTrueType", &psEmbedCIDTrueType,
- tokens, fileName, line);
- } else if (!cmd->cmp("psOPI")) {
- parseYesNo("psOPI", &psOPI, tokens, fileName, line);
- } else if (!cmd->cmp("psASCIIHex")) {
- parseYesNo("psASCIIHex", &psASCIIHex, tokens, fileName, line);
- } else if (!cmd->cmp("textEncoding")) {
- parseTextEncoding(tokens, fileName, line);
- } else if (!cmd->cmp("textEOL")) {
- parseTextEOL(tokens, fileName, line);
- } else if (!cmd->cmp("textPageBreaks")) {
- parseYesNo("textPageBreaks", &textPageBreaks,
- tokens, fileName, line);
- } else if (!cmd->cmp("textKeepTinyChars")) {
- parseYesNo("textKeepTinyChars", &textKeepTinyChars,
- tokens, fileName, line);
- } else if (!cmd->cmp("fontDir")) {
- parseFontDir(tokens, fileName, line);
- } else if (!cmd->cmp("initialZoom")) {
- parseInitialZoom(tokens, fileName, line);
- } else if (!cmd->cmp("continuousView")) {
- parseYesNo("continuousView", &continuousView, tokens, fileName, line);
- } else if (!cmd->cmp("enableT1lib")) {
- parseYesNo("enableT1lib", &enableT1lib, tokens, fileName, line);
- } else if (!cmd->cmp("enableFreeType")) {
- parseYesNo("enableFreeType", &enableFreeType, tokens, fileName, line);
- } else if (!cmd->cmp("antialias")) {
- parseYesNo("antialias", &antialias, tokens, fileName, line);
- } else if (!cmd->cmp("urlCommand")) {
- parseCommand("urlCommand", &urlCommand, tokens, fileName, line);
- } else if (!cmd->cmp("movieCommand")) {
- parseCommand("movieCommand", &movieCommand, tokens, fileName, line);
- } else if (!cmd->cmp("mapNumericCharNames")) {
- parseYesNo("mapNumericCharNames", &mapNumericCharNames,
- tokens, fileName, line);
- } else if (!cmd->cmp("printCommands")) {
- parseYesNo("printCommands", &printCommands, tokens, fileName, line);
- } else if (!cmd->cmp("errQuiet")) {
- parseYesNo("errQuiet", &errQuiet, tokens, fileName, line);
} else {
- error(-1, "Unknown config file command '%s' (%s:%d)",
- cmd->getCString(), fileName->getCString(), line);
- if (!cmd->cmp("displayFontX") ||
- !cmd->cmp("displayNamedCIDFontX") ||
- !cmd->cmp("displayCIDFontX")) {
- error(-1, "-- Xpdf no longer supports X fonts");
- } else if (!cmd->cmp("t1libControl") || !cmd->cmp("freetypeControl")) {
- error(-1, "-- The t1libControl and freetypeControl options have been replaced");
- error(-1, " by the enableT1lib, enableFreeType, and antialias options");
- } else if (!cmd->cmp("fontpath") || !cmd->cmp("fontmap")) {
- error(-1, "-- the config file format has changed since Xpdf 0.9x");
- }
+ error(-1, "Bad 'include' config file command (%s:%d)",
+ fileName->getCString(), line);
+ }
+ } else if (!cmd->cmp("nameToUnicode")) {
+ parseNameToUnicode(tokens, fileName, line);
+ } else if (!cmd->cmp("cidToUnicode")) {
+ parseCIDToUnicode(tokens, fileName, line);
+ } else if (!cmd->cmp("unicodeToUnicode")) {
+ parseUnicodeToUnicode(tokens, fileName, line);
+ } else if (!cmd->cmp("unicodeMap")) {
+ parseUnicodeMap(tokens, fileName, line);
+ } else if (!cmd->cmp("cMapDir")) {
+ parseCMapDir(tokens, fileName, line);
+ } else if (!cmd->cmp("toUnicodeDir")) {
+ parseToUnicodeDir(tokens, fileName, line);
+ } else if (!cmd->cmp("displayFontT1")) {
+ parseDisplayFont(tokens, displayFonts, displayFontT1, fileName, line);
+ } else if (!cmd->cmp("displayFontTT")) {
+ parseDisplayFont(tokens, displayFonts, displayFontTT, fileName, line);
+ } else if (!cmd->cmp("displayNamedCIDFontT1")) {
+ parseDisplayFont(tokens, displayNamedCIDFonts,
+ displayFontT1, fileName, line);
+ } else if (!cmd->cmp("displayCIDFontT1")) {
+ parseDisplayFont(tokens, displayCIDFonts,
+ displayFontT1, fileName, line);
+ } else if (!cmd->cmp("displayNamedCIDFontTT")) {
+ parseDisplayFont(tokens, displayNamedCIDFonts,
+ displayFontTT, fileName, line);
+ } else if (!cmd->cmp("displayCIDFontTT")) {
+ parseDisplayFont(tokens, displayCIDFonts,
+ displayFontTT, fileName, line);
+ } else if (!cmd->cmp("psFile")) {
+ parsePSFile(tokens, fileName, line);
+ } else if (!cmd->cmp("psFont")) {
+ parsePSFont(tokens, fileName, line);
+ } else if (!cmd->cmp("psNamedFont16")) {
+ parsePSFont16("psNamedFont16", psNamedFonts16,
+ tokens, fileName, line);
+ } else if (!cmd->cmp("psFont16")) {
+ parsePSFont16("psFont16", psFonts16, tokens, fileName, line);
+ } else if (!cmd->cmp("psPaperSize")) {
+ parsePSPaperSize(tokens, fileName, line);
+ } else if (!cmd->cmp("psImageableArea")) {
+ parsePSImageableArea(tokens, fileName, line);
+ } else if (!cmd->cmp("psCrop")) {
+ parseYesNo("psCrop", &psCrop, tokens, fileName, line);
+ } else if (!cmd->cmp("psExpandSmaller")) {
+ parseYesNo("psExpandSmaller", &psExpandSmaller,
+ tokens, fileName, line);
+ } else if (!cmd->cmp("psShrinkLarger")) {
+ parseYesNo("psShrinkLarger", &psShrinkLarger, tokens, fileName, line);
+ } else if (!cmd->cmp("psCenter")) {
+ parseYesNo("psCenter", &psCenter, tokens, fileName, line);
+ } else if (!cmd->cmp("psDuplex")) {
+ parseYesNo("psDuplex", &psDuplex, tokens, fileName, line);
+ } else if (!cmd->cmp("psLevel")) {
+ parsePSLevel(tokens, fileName, line);
+ } else if (!cmd->cmp("psEmbedType1Fonts")) {
+ parseYesNo("psEmbedType1", &psEmbedType1, tokens, fileName, line);
+ } else if (!cmd->cmp("psEmbedTrueTypeFonts")) {
+ parseYesNo("psEmbedTrueType", &psEmbedTrueType,
+ tokens, fileName, line);
+ } else if (!cmd->cmp("psEmbedCIDPostScriptFonts")) {
+ parseYesNo("psEmbedCIDPostScript", &psEmbedCIDPostScript,
+ tokens, fileName, line);
+ } else if (!cmd->cmp("psEmbedCIDTrueTypeFonts")) {
+ parseYesNo("psEmbedCIDTrueType", &psEmbedCIDTrueType,
+ tokens, fileName, line);
+ } else if (!cmd->cmp("psPreload")) {
+ parseYesNo("psPreload", &psPreload, tokens, fileName, line);
+ } else if (!cmd->cmp("psOPI")) {
+ parseYesNo("psOPI", &psOPI, tokens, fileName, line);
+ } else if (!cmd->cmp("psASCIIHex")) {
+ parseYesNo("psASCIIHex", &psASCIIHex, tokens, fileName, line);
+ } else if (!cmd->cmp("textEncoding")) {
+ parseTextEncoding(tokens, fileName, line);
+ } else if (!cmd->cmp("textEOL")) {
+ parseTextEOL(tokens, fileName, line);
+ } else if (!cmd->cmp("textPageBreaks")) {
+ parseYesNo("textPageBreaks", &textPageBreaks,
+ tokens, fileName, line);
+ } else if (!cmd->cmp("textKeepTinyChars")) {
+ parseYesNo("textKeepTinyChars", &textKeepTinyChars,
+ tokens, fileName, line);
+ } else if (!cmd->cmp("fontDir")) {
+ parseFontDir(tokens, fileName, line);
+ } else if (!cmd->cmp("initialZoom")) {
+ parseInitialZoom(tokens, fileName, line);
+ } else if (!cmd->cmp("continuousView")) {
+ parseYesNo("continuousView", &continuousView, tokens, fileName, line);
+ } else if (!cmd->cmp("enableT1lib")) {
+ parseYesNo("enableT1lib", &enableT1lib, tokens, fileName, line);
+ } else if (!cmd->cmp("enableFreeType")) {
+ parseYesNo("enableFreeType", &enableFreeType, tokens, fileName, line);
+ } else if (!cmd->cmp("antialias")) {
+ parseYesNo("antialias", &antialias, tokens, fileName, line);
+ } else if (!cmd->cmp("vectorAntialias")) {
+ parseYesNo("vectorAntialias", &vectorAntialias,
+ tokens, fileName, line);
+ } else if (!cmd->cmp("strokeAdjust")) {
+ parseYesNo("strokeAdjust", &strokeAdjust, tokens, fileName, line);
+ } else if (!cmd->cmp("screenType")) {
+ parseScreenType(tokens, fileName, line);
+ } else if (!cmd->cmp("screenSize")) {
+ parseInteger("screenSize", &screenSize, tokens, fileName, line);
+ } else if (!cmd->cmp("screenDotRadius")) {
+ parseInteger("screenDotRadius", &screenDotRadius,
+ tokens, fileName, line);
+ } else if (!cmd->cmp("screenGamma")) {
+ parseFloat("screenGamma", &screenGamma,
+ tokens, fileName, line);
+ } else if (!cmd->cmp("screenBlackThreshold")) {
+ parseFloat("screenBlackThreshold", &screenBlackThreshold,
+ tokens, fileName, line);
+ } else if (!cmd->cmp("screenWhiteThreshold")) {
+ parseFloat("screenWhiteThreshold", &screenWhiteThreshold,
+ tokens, fileName, line);
+ } else if (!cmd->cmp("urlCommand")) {
+ parseCommand("urlCommand", &urlCommand, tokens, fileName, line);
+ } else if (!cmd->cmp("movieCommand")) {
+ parseCommand("movieCommand", &movieCommand, tokens, fileName, line);
+ } else if (!cmd->cmp("mapNumericCharNames")) {
+ parseYesNo("mapNumericCharNames", &mapNumericCharNames,
+ tokens, fileName, line);
+ } else if (!cmd->cmp("mapUnknownCharNames")) {
+ parseYesNo("mapUnknownCharNames", &mapUnknownCharNames,
+ tokens, fileName, line);
+ } else if (!cmd->cmp("bind")) {
+ parseBind(tokens, fileName, line);
+ } else if (!cmd->cmp("unbind")) {
+ parseUnbind(tokens, fileName, line);
+ } else if (!cmd->cmp("printCommands")) {
+ parseYesNo("printCommands", &printCommands, tokens, fileName, line);
+ } else if (!cmd->cmp("errQuiet")) {
+ parseYesNo("errQuiet", &errQuiet, tokens, fileName, line);
+ } else {
+ error(-1, "Unknown config file command '%s' (%s:%d)",
+ cmd->getCString(), fileName->getCString(), line);
+ if (!cmd->cmp("displayFontX") ||
+ !cmd->cmp("displayNamedCIDFontX") ||
+ !cmd->cmp("displayCIDFontX")) {
+ error(-1, "-- Xpdf no longer supports X fonts");
+ } else if (!cmd->cmp("t1libControl") || !cmd->cmp("freetypeControl")) {
+ error(-1, "-- The t1libControl and freetypeControl options have been replaced");
+ error(-1, " by the enableT1lib, enableFreeType, and antialias options");
+ } else if (!cmd->cmp("fontpath") || !cmd->cmp("fontmap")) {
+ error(-1, "-- the config file format has changed since Xpdf 0.9x");
}
}
-
- deleteGList(tokens, GString);
- ++line;
}
+
+ deleteGList(tokens, GString);
}
+#endif
void GlobalParams::parseNameToUnicode(GList *tokens, GString *fileName,
int line) {
@@ -1112,6 +1575,216 @@ void GlobalParams::parseInitialZoom(GList *tokens,
initialZoom = ((GString *)tokens->get(1))->copy();
}
+void GlobalParams::parseScreenType(GList *tokens, GString *fileName,
+ int line) {
+ GString *tok;
+
+ if (tokens->getLength() != 2) {
+ error(-1, "Bad 'screenType' config file command (%s:%d)",
+ fileName->getCString(), line);
+ return;
+ }
+ tok = (GString *)tokens->get(1);
+ if (!tok->cmp("dispersed")) {
+ screenType = screenDispersed;
+ } else if (!tok->cmp("clustered")) {
+ screenType = screenClustered;
+ } else if (!tok->cmp("stochasticClustered")) {
+ screenType = screenStochasticClustered;
+ } else {
+ error(-1, "Bad 'screenType' config file command (%s:%d)",
+ fileName->getCString(), line);
+ }
+}
+
+#ifndef PDF_PARSER_ONLY
+void GlobalParams::parseBind(GList *tokens, GString *fileName, int line) {
+ KeyBinding *binding;
+ GList *cmds;
+ int code, mods, context, i;
+
+ if (tokens->getLength() < 4) {
+ error(-1, "Bad 'bind' config file command (%s:%d)",
+ fileName->getCString(), line);
+ return;
+ }
+ if (!parseKey((GString *)tokens->get(1), (GString *)tokens->get(2),
+ &code, &mods, &context,
+ "bind", tokens, fileName, line)) {
+ return;
+ }
+ for (i = 0; i < keyBindings->getLength(); ++i) {
+ binding = (KeyBinding *)keyBindings->get(i);
+ if (binding->code == code &&
+ binding->mods == mods &&
+ binding->context == context) {
+ delete (KeyBinding *)keyBindings->del(i);
+ break;
+ }
+ }
+ cmds = new GList();
+ for (i = 3; i < tokens->getLength(); ++i) {
+ cmds->append(((GString *)tokens->get(i))->copy());
+ }
+ keyBindings->append(new KeyBinding(code, mods, context, cmds));
+}
+
+void GlobalParams::parseUnbind(GList *tokens, GString *fileName, int line) {
+ KeyBinding *binding;
+ int code, mods, context, i;
+
+ if (tokens->getLength() != 3) {
+ error(-1, "Bad 'unbind' config file command (%s:%d)",
+ fileName->getCString(), line);
+ return;
+ }
+ if (!parseKey((GString *)tokens->get(1), (GString *)tokens->get(2),
+ &code, &mods, &context,
+ "unbind", tokens, fileName, line)) {
+ return;
+ }
+ for (i = 0; i < keyBindings->getLength(); ++i) {
+ binding = (KeyBinding *)keyBindings->get(i);
+ if (binding->code == code &&
+ binding->mods == mods &&
+ binding->context == context) {
+ delete (KeyBinding *)keyBindings->del(i);
+ break;
+ }
+ }
+}
+
+GBool GlobalParams::parseKey(GString *modKeyStr, GString *contextStr,
+ int *code, int *mods, int *context,
+ char *cmdName,
+ GList *tokens, GString *fileName, int line) {
+ char *p0;
+
+ *mods = xpdfKeyModNone;
+ p0 = modKeyStr->getCString();
+ while (1) {
+ if (!strncmp(p0, "shift-", 6)) {
+ *mods |= xpdfKeyModShift;
+ p0 += 6;
+ } else if (!strncmp(p0, "ctrl-", 5)) {
+ *mods |= xpdfKeyModCtrl;
+ p0 += 5;
+ } else if (!strncmp(p0, "alt-", 4)) {
+ *mods |= xpdfKeyModAlt;
+ p0 += 4;
+ } else {
+ break;
+ }
+ }
+
+ if (!strcmp(p0, "space")) {
+ *code = ' ';
+ } else if (!strcmp(p0, "tab")) {
+ *code = xpdfKeyCodeTab;
+ } else if (!strcmp(p0, "return")) {
+ *code = xpdfKeyCodeReturn;
+ } else if (!strcmp(p0, "enter")) {
+ *code = xpdfKeyCodeEnter;
+ } else if (!strcmp(p0, "backspace")) {
+ *code = xpdfKeyCodeBackspace;
+ } else if (!strcmp(p0, "insert")) {
+ *code = xpdfKeyCodeInsert;
+ } else if (!strcmp(p0, "delete")) {
+ *code = xpdfKeyCodeDelete;
+ } else if (!strcmp(p0, "home")) {
+ *code = xpdfKeyCodeHome;
+ } else if (!strcmp(p0, "end")) {
+ *code = xpdfKeyCodeEnd;
+ } else if (!strcmp(p0, "pgup")) {
+ *code = xpdfKeyCodePgUp;
+ } else if (!strcmp(p0, "pgdn")) {
+ *code = xpdfKeyCodePgDn;
+ } else if (!strcmp(p0, "left")) {
+ *code = xpdfKeyCodeLeft;
+ } else if (!strcmp(p0, "right")) {
+ *code = xpdfKeyCodeRight;
+ } else if (!strcmp(p0, "up")) {
+ *code = xpdfKeyCodeUp;
+ } else if (!strcmp(p0, "down")) {
+ *code = xpdfKeyCodeDown;
+ } else if (p0[0] == 'f' && p0[1] >= '1' && p0[1] <= '9' && !p0[2]) {
+ *code = xpdfKeyCodeF1 + (p0[1] - '1');
+ } else if (p0[0] == 'f' &&
+ ((p0[1] >= '1' && p0[1] <= '2' && p0[2] >= '0' && p0[2] <= '9') ||
+ (p0[1] == '3' && p0[2] >= '0' && p0[2] <= '5')) &&
+ !p0[3]) {
+ *code = xpdfKeyCodeF1 + 10 * (p0[1] - '0') + (p0[2] - '0') - 1;
+ } else if (!strncmp(p0, "mousePress", 10) &&
+ p0[10] >= '1' && p0[10] <= '7' && !p0[11]) {
+ *code = xpdfKeyCodeMousePress1 + (p0[10] - '1');
+ } else if (!strncmp(p0, "mouseRelease", 12) &&
+ p0[12] >= '1' && p0[12] <= '7' && !p0[13]) {
+ *code = xpdfKeyCodeMouseRelease1 + (p0[12] - '1');
+ } else if (*p0 >= 0x20 && *p0 <= 0x7e && !p0[1]) {
+ *code = (int)*p0;
+ } else {
+ error(-1, "Bad key/modifier in '%s' config file command (%s:%d)",
+ cmdName, fileName->getCString(), line);
+ return gFalse;
+ }
+
+ p0 = contextStr->getCString();
+ if (!strcmp(p0, "any")) {
+ *context = xpdfKeyContextAny;
+ } else {
+ *context = xpdfKeyContextAny;
+ while (1) {
+ if (!strncmp(p0, "fullScreen", 10)) {
+ *context |= xpdfKeyContextFullScreen;
+ p0 += 10;
+ } else if (!strncmp(p0, "window", 6)) {
+ *context |= xpdfKeyContextWindow;
+ p0 += 6;
+ } else if (!strncmp(p0, "continuous", 10)) {
+ *context |= xpdfKeyContextContinuous;
+ p0 += 10;
+ } else if (!strncmp(p0, "singlePage", 10)) {
+ *context |= xpdfKeyContextSinglePage;
+ p0 += 10;
+ } else if (!strncmp(p0, "overLink", 8)) {
+ *context |= xpdfKeyContextOverLink;
+ p0 += 8;
+ } else if (!strncmp(p0, "offLink", 7)) {
+ *context |= xpdfKeyContextOffLink;
+ p0 += 7;
+ } else if (!strncmp(p0, "outline", 7)) {
+ *context |= xpdfKeyContextOutline;
+ p0 += 7;
+ } else if (!strncmp(p0, "mainWin", 7)) {
+ *context |= xpdfKeyContextMainWin;
+ p0 += 7;
+ } else if (!strncmp(p0, "scrLockOn", 9)) {
+ *context |= xpdfKeyContextScrLockOn;
+ p0 += 9;
+ } else if (!strncmp(p0, "scrLockOff", 10)) {
+ *context |= xpdfKeyContextScrLockOff;
+ p0 += 10;
+ } else {
+ error(-1, "Bad context in '%s' config file command (%s:%d)",
+ cmdName, fileName->getCString(), line);
+ return gFalse;
+ }
+ if (!*p0) {
+ break;
+ }
+ if (*p0 != ',') {
+ error(-1, "Bad context in '%s' config file command (%s:%d)",
+ cmdName, fileName->getCString(), line);
+ return gFalse;
+ }
+ ++p0;
+ }
+ }
+
+ return gTrue;
+}
+#endif
+
void GlobalParams::parseCommand(char *cmdName, GString **val,
GList *tokens, GString *fileName, int line) {
if (tokens->getLength() != 2) {
@@ -1152,6 +1825,69 @@ GBool GlobalParams::parseYesNo2(char *token, GBool *flag) {
return gTrue;
}
+void GlobalParams::parseInteger(char *cmdName, int *val,
+ GList *tokens, GString *fileName, int line) {
+ GString *tok;
+ int i;
+
+ if (tokens->getLength() != 2) {
+ error(-1, "Bad '%s' config file command (%s:%d)",
+ cmdName, fileName->getCString(), line);
+ return;
+ }
+ tok = (GString *)tokens->get(1);
+ if (tok->getLength() == 0) {
+ error(-1, "Bad '%s' config file command (%s:%d)",
+ cmdName, fileName->getCString(), line);
+ return;
+ }
+ if (tok->getChar(0) == '-') {
+ i = 1;
+ } else {
+ i = 0;
+ }
+ for (; i < tok->getLength(); ++i) {
+ if (tok->getChar(i) < '0' || tok->getChar(i) > '9') {
+ error(-1, "Bad '%s' config file command (%s:%d)",
+ cmdName, fileName->getCString(), line);
+ return;
+ }
+ }
+ *val = atoi(tok->getCString());
+}
+
+void GlobalParams::parseFloat(char *cmdName, double *val,
+ GList *tokens, GString *fileName, int line) {
+ GString *tok;
+ int i;
+
+ if (tokens->getLength() != 2) {
+ error(-1, "Bad '%s' config file command (%s:%d)",
+ cmdName, fileName->getCString(), line);
+ return;
+ }
+ tok = (GString *)tokens->get(1);
+ if (tok->getLength() == 0) {
+ error(-1, "Bad '%s' config file command (%s:%d)",
+ cmdName, fileName->getCString(), line);
+ return;
+ }
+ if (tok->getChar(0) == '-') {
+ i = 1;
+ } else {
+ i = 0;
+ }
+ for (; i < tok->getLength(); ++i) {
+ if (!((tok->getChar(i) >= '0' && tok->getChar(i) <= '9') ||
+ tok->getChar(i) == '.')) {
+ error(-1, "Bad '%s' config file command (%s:%d)",
+ cmdName, fileName->getCString(), line);
+ return;
+ }
+ }
+ *val = atof(tok->getCString());
+}
+
GlobalParams::~GlobalParams() {
GHashIter *iter;
GString *key;
@@ -1171,6 +1907,11 @@ GlobalParams::~GlobalParams() {
deleteGHash(displayFonts, DisplayFontParam);
deleteGHash(displayCIDFonts, DisplayFontParam);
deleteGHash(displayNamedCIDFonts, DisplayFontParam);
+#ifdef WIN32
+ if (winFontList) {
+ delete winFontList;
+ }
+#endif
if (psFile) {
delete psFile;
}
@@ -1186,6 +1927,9 @@ GlobalParams::~GlobalParams() {
if (movieCommand) {
delete movieCommand;
}
+#ifndef PDF_PARSER_ONLY
+ deleteGList(keyBindings, KeyBinding);
+#endif
cMapDirs->startIter(&iter);
while (cMapDirs->getNext(&iter, &key, (void **)&list)) {
@@ -1241,7 +1985,7 @@ void GlobalParams::setupBaseFonts(char *dir) {
if ((SHGetSpecialFolderPathFunc =
(BOOL (__stdcall *)(HWND hwndOwner, LPTSTR lpszPath,
int nFolder, BOOL fCreate))
- GetProcAddress(shell32Lib, "SHGetSpecialFolderPath"))) {
+ GetProcAddress(shell32Lib, "SHGetSpecialFolderPathA"))) {
if (!(*SHGetSpecialFolderPathFunc)(NULL, winFontDir,
CSIDL_FONTS, FALSE)) {
winFontDir[0] = '\0';
@@ -1317,6 +2061,12 @@ void GlobalParams::setupBaseFonts(char *dir) {
dfp->t1.fileName = fileName;
globalParams->addDisplayFont(dfp);
}
+
+#ifdef WIN32
+ if (winFontDir[0]) {
+ winFontList = new WinFontList(winFontDir);
+ }
+#endif
}
//------------------------------------------------------------------------
@@ -1419,6 +2169,11 @@ DisplayFontParam *GlobalParams::getDisplayFont(GString *fontName) {
lockGlobalParams;
dfp = (DisplayFontParam *)displayFonts->lookup(fontName);
+#ifdef WIN32
+ if (!dfp && winFontList) {
+ dfp = winFontList->find(fontName);
+ }
+#endif
unlockGlobalParams;
return dfp;
}
@@ -1602,6 +2357,15 @@ GBool GlobalParams::getPSEmbedCIDTrueType() {
return e;
}
+GBool GlobalParams::getPSPreload() {
+ GBool preload;
+
+ lockGlobalParams;
+ preload = psPreload;
+ unlockGlobalParams;
+ return preload;
+}
+
GBool GlobalParams::getPSOPI() {
GBool opi;
@@ -1726,6 +2490,78 @@ GBool GlobalParams::getAntialias() {
return f;
}
+GBool GlobalParams::getVectorAntialias() {
+ GBool f;
+
+ lockGlobalParams;
+ f = vectorAntialias;
+ unlockGlobalParams;
+ return f;
+}
+
+GBool GlobalParams::getStrokeAdjust() {
+ GBool f;
+
+ lockGlobalParams;
+ f = strokeAdjust;
+ unlockGlobalParams;
+ return f;
+}
+
+ScreenType GlobalParams::getScreenType() {
+ ScreenType t;
+
+ lockGlobalParams;
+ t = screenType;
+ unlockGlobalParams;
+ return t;
+}
+
+int GlobalParams::getScreenSize() {
+ int size;
+
+ lockGlobalParams;
+ size = screenSize;
+ unlockGlobalParams;
+ return size;
+}
+
+int GlobalParams::getScreenDotRadius() {
+ int r;
+
+ lockGlobalParams;
+ r = screenDotRadius;
+ unlockGlobalParams;
+ return r;
+}
+
+double GlobalParams::getScreenGamma() {
+ double gamma;
+
+ lockGlobalParams;
+ gamma = screenGamma;
+ unlockGlobalParams;
+ return gamma;
+}
+
+double GlobalParams::getScreenBlackThreshold() {
+ double thresh;
+
+ lockGlobalParams;
+ thresh = screenBlackThreshold;
+ unlockGlobalParams;
+ return thresh;
+}
+
+double GlobalParams::getScreenWhiteThreshold() {
+ double thresh;
+
+ lockGlobalParams;
+ thresh = screenWhiteThreshold;
+ unlockGlobalParams;
+ return thresh;
+}
+
GBool GlobalParams::getMapNumericCharNames() {
GBool map;
@@ -1735,6 +2571,43 @@ GBool GlobalParams::getMapNumericCharNames() {
return map;
}
+GBool GlobalParams::getMapUnknownCharNames() {
+ GBool map;
+
+ lockGlobalParams;
+ map = mapUnknownCharNames;
+ unlockGlobalParams;
+ return map;
+}
+
+#ifndef PDF_PARSER_ONLY
+GList *GlobalParams::getKeyBinding(int code, int mods, int context) {
+ KeyBinding *binding;
+ GList *cmds;
+ int modMask;
+ int i, j;
+
+ lockGlobalParams;
+ cmds = NULL;
+ // for ASCII chars, ignore the shift modifier
+ modMask = code <= 0xff ? ~xpdfKeyModShift : ~0;
+ for (i = 0; i < keyBindings->getLength(); ++i) {
+ binding = (KeyBinding *)keyBindings->get(i);
+ if (binding->code == code &&
+ (binding->mods & modMask) == (mods & modMask) &&
+ (~binding->context | context) == ~0) {
+ cmds = new GList();
+ for (j = 0; j < binding->cmds->getLength(); ++j) {
+ cmds->append(((GString *)binding->cmds->get(j))->copy());
+ }
+ break;
+ }
+ }
+ unlockGlobalParams;
+ return cmds;
+}
+#endif
+
GBool GlobalParams::getPrintCommands() {
GBool p;
@@ -1745,12 +2618,9 @@ GBool GlobalParams::getPrintCommands() {
}
GBool GlobalParams::getErrQuiet() {
- GBool q;
-
- lockGlobalParams;
- q = errQuiet;
- unlockGlobalParams;
- return q;
+ // no locking -- this function may get called from inside a locked
+ // section
+ return errQuiet;
}
CharCodeToUnicode *GlobalParams::getCIDToUnicode(GString *collection) {
@@ -1960,6 +2830,12 @@ void GlobalParams::setPSEmbedCIDTrueType(GBool embed) {
unlockGlobalParams;
}
+void GlobalParams::setPSPreload(GBool preload) {
+ lockGlobalParams;
+ psPreload = preload;
+ unlockGlobalParams;
+}
+
void GlobalParams::setPSOPI(GBool opi) {
lockGlobalParams;
psOPI = opi;
@@ -2048,12 +2924,63 @@ GBool GlobalParams::setAntialias(char *s) {
return ok;
}
+GBool GlobalParams::setVectorAntialias(char *s) {
+ GBool ok;
+
+ lockGlobalParams;
+ ok = parseYesNo2(s, &vectorAntialias);
+ unlockGlobalParams;
+ return ok;
+}
+
+void GlobalParams::setScreenType(ScreenType t) {
+ lockGlobalParams;
+ screenType = t;
+ unlockGlobalParams;
+}
+
+void GlobalParams::setScreenSize(int size) {
+ lockGlobalParams;
+ screenSize = size;
+ unlockGlobalParams;
+}
+
+void GlobalParams::setScreenDotRadius(int r) {
+ lockGlobalParams;
+ screenDotRadius = r;
+ unlockGlobalParams;
+}
+
+void GlobalParams::setScreenGamma(double gamma) {
+ lockGlobalParams;
+ screenGamma = gamma;
+ unlockGlobalParams;
+}
+
+void GlobalParams::setScreenBlackThreshold(double thresh) {
+ lockGlobalParams;
+ screenBlackThreshold = thresh;
+ unlockGlobalParams;
+}
+
+void GlobalParams::setScreenWhiteThreshold(double thresh) {
+ lockGlobalParams;
+ screenWhiteThreshold = thresh;
+ unlockGlobalParams;
+}
+
void GlobalParams::setMapNumericCharNames(GBool map) {
lockGlobalParams;
mapNumericCharNames = map;
unlockGlobalParams;
}
+void GlobalParams::setMapUnknownCharNames(GBool map) {
+ lockGlobalParams;
+ mapUnknownCharNames = map;
+ unlockGlobalParams;
+}
+
void GlobalParams::setPrintCommands(GBool printCommandsA) {
lockGlobalParams;
printCommands = printCommandsA;
@@ -2082,7 +3009,7 @@ XpdfSecurityHandler *GlobalParams::getSecurityHandler(char *name) {
lockGlobalParams;
for (i = 0; i < securityHandlers->getLength(); ++i) {
hdlr = (XpdfSecurityHandler *)securityHandlers->get(i);
- if (!stricmp(hdlr->name, name)) {
+ if (!strcasecmp(hdlr->name, name)) {
unlockGlobalParams;
return hdlr;
}
diff --git a/Build/source/libs/xpdf/xpdf/GlobalParams.h b/Build/source/libs/xpdf/xpdf/GlobalParams.h
index 99f78a76746..566d43ca7e7 100644
--- a/Build/source/libs/xpdf/xpdf/GlobalParams.h
+++ b/Build/source/libs/xpdf/xpdf/GlobalParams.h
@@ -35,6 +35,9 @@ class CMap;
class CMapCache;
struct XpdfSecurityHandler;
class GlobalParams;
+#ifdef WIN32
+class WinFontList;
+#endif
//------------------------------------------------------------------------
@@ -69,7 +72,7 @@ public:
};
DisplayFontParam(GString *nameA, DisplayFontParamKind kindA);
- ~DisplayFontParam();
+ virtual ~DisplayFontParam();
};
//------------------------------------------------------------------------
@@ -111,6 +114,83 @@ enum EndOfLineKind {
//------------------------------------------------------------------------
+enum ScreenType {
+ screenUnset,
+ screenDispersed,
+ screenClustered,
+ screenStochasticClustered
+};
+
+//------------------------------------------------------------------------
+
+#ifndef PDF_PARSER_ONLY
+class KeyBinding {
+public:
+
+ int code; // 0x20 .. 0xfe = ASCII,
+ // >=0x10000 = special keys, mouse buttons,
+ // etc. (xpdfKeyCode* symbols)
+ int mods; // modifiers (xpdfKeyMod* symbols, or-ed
+ // together)
+ int context; // context (xpdfKeyContext* symbols, or-ed
+ // together)
+ GList *cmds; // list of commands [GString]
+
+ KeyBinding(int codeA, int modsA, int contextA, char *cmd0);
+ KeyBinding(int codeA, int modsA, int contextA, char *cmd0, char *cmd1);
+ KeyBinding(int codeA, int modsA, int contextA, GList *cmdsA);
+ ~KeyBinding();
+};
+
+#define xpdfKeyCodeTab 0x1000
+#define xpdfKeyCodeReturn 0x1001
+#define xpdfKeyCodeEnter 0x1002
+#define xpdfKeyCodeBackspace 0x1003
+#define xpdfKeyCodeInsert 0x1004
+#define xpdfKeyCodeDelete 0x1005
+#define xpdfKeyCodeHome 0x1006
+#define xpdfKeyCodeEnd 0x1007
+#define xpdfKeyCodePgUp 0x1008
+#define xpdfKeyCodePgDn 0x1009
+#define xpdfKeyCodeLeft 0x100a
+#define xpdfKeyCodeRight 0x100b
+#define xpdfKeyCodeUp 0x100c
+#define xpdfKeyCodeDown 0x100d
+#define xpdfKeyCodeF1 0x1100
+#define xpdfKeyCodeF35 0x1122
+#define xpdfKeyCodeMousePress1 0x2001
+#define xpdfKeyCodeMousePress2 0x2002
+#define xpdfKeyCodeMousePress3 0x2003
+#define xpdfKeyCodeMousePress4 0x2004
+#define xpdfKeyCodeMousePress5 0x2005
+#define xpdfKeyCodeMousePress6 0x2006
+#define xpdfKeyCodeMousePress7 0x2007
+#define xpdfKeyCodeMouseRelease1 0x2101
+#define xpdfKeyCodeMouseRelease2 0x2102
+#define xpdfKeyCodeMouseRelease3 0x2103
+#define xpdfKeyCodeMouseRelease4 0x2104
+#define xpdfKeyCodeMouseRelease5 0x2105
+#define xpdfKeyCodeMouseRelease6 0x2106
+#define xpdfKeyCodeMouseRelease7 0x2107
+#define xpdfKeyModNone 0
+#define xpdfKeyModShift (1 << 0)
+#define xpdfKeyModCtrl (1 << 1)
+#define xpdfKeyModAlt (1 << 2)
+#define xpdfKeyContextAny 0
+#define xpdfKeyContextFullScreen (1 << 0)
+#define xpdfKeyContextWindow (2 << 0)
+#define xpdfKeyContextContinuous (1 << 2)
+#define xpdfKeyContextSinglePage (2 << 2)
+#define xpdfKeyContextOverLink (1 << 4)
+#define xpdfKeyContextOffLink (2 << 4)
+#define xpdfKeyContextOutline (1 << 6)
+#define xpdfKeyContextMainWin (2 << 6)
+#define xpdfKeyContextScrLockOn (1 << 8)
+#define xpdfKeyContextScrLockOff (2 << 8)
+#endif
+
+//------------------------------------------------------------------------
+
class GlobalParams {
public:
@@ -126,6 +206,10 @@ public:
void setBaseDir(char *dir);
void setupBaseFonts(char *dir);
+#ifndef PDF_PARSER_ONLY
+ void parseLine(char *buf, GString *fileName, int line);
+#endif
+
//----- accessors
CharCode getMacRomanCharCode(char *charName);
@@ -154,6 +238,7 @@ public:
GBool getPSEmbedTrueType();
GBool getPSEmbedCIDPostScript();
GBool getPSEmbedCIDTrueType();
+ GBool getPSPreload();
GBool getPSOPI();
GBool getPSASCIIHex();
GString *getTextEncodingName();
@@ -166,9 +251,21 @@ public:
GBool getEnableT1lib();
GBool getEnableFreeType();
GBool getAntialias();
+ GBool getVectorAntialias();
+ GBool getStrokeAdjust();
+ ScreenType getScreenType();
+ int getScreenSize();
+ int getScreenDotRadius();
+ double getScreenGamma();
+ double getScreenBlackThreshold();
+ double getScreenWhiteThreshold();
GString *getURLCommand() { return urlCommand; }
GString *getMovieCommand() { return movieCommand; }
GBool getMapNumericCharNames();
+ GBool getMapUnknownCharNames();
+#ifndef PDF_PARSER_ONLY
+ GList *getKeyBinding(int code, int mods, int context);
+#endif
GBool getPrintCommands();
GBool getErrQuiet();
@@ -196,6 +293,7 @@ public:
void setPSEmbedTrueType(GBool embed);
void setPSEmbedCIDPostScript(GBool embed);
void setPSEmbedCIDTrueType(GBool embed);
+ void setPSPreload(GBool preload);
void setPSOPI(GBool opi);
void setPSASCIIHex(GBool hex);
void setTextEncoding(char *encodingName);
@@ -207,7 +305,15 @@ public:
GBool setEnableT1lib(char *s);
GBool setEnableFreeType(char *s);
GBool setAntialias(char *s);
+ GBool setVectorAntialias(char *s);
+ void setScreenType(ScreenType t);
+ void setScreenSize(int size);
+ void setScreenDotRadius(int r);
+ void setScreenGamma(double gamma);
+ void setScreenBlackThreshold(double thresh);
+ void setScreenWhiteThreshold(double thresh);
void setMapNumericCharNames(GBool map);
+ void setMapUnknownCharNames(GBool map);
void setPrintCommands(GBool printCommandsA);
void setErrQuiet(GBool errQuietA);
@@ -218,6 +324,9 @@ public:
private:
+#ifndef PDF_PARSER_ONLY
+ void createDefaultKeyBindings();
+#endif
void parseFile(GString *fileName, FILE *f);
void parseNameToUnicode(GList *tokens, GString *fileName, int line);
void parseCIDToUnicode(GList *tokens, GString *fileName, int line);
@@ -239,11 +348,24 @@ private:
void parseTextEOL(GList *tokens, GString *fileName, int line);
void parseFontDir(GList *tokens, GString *fileName, int line);
void parseInitialZoom(GList *tokens, GString *fileName, int line);
+ void parseScreenType(GList *tokens, GString *fileName, int line);
+#ifndef PDF_PARSER_ONLY
+ void parseBind(GList *tokens, GString *fileName, int line);
+ void parseUnbind(GList *tokens, GString *fileName, int line);
+ GBool parseKey(GString *modKeyStr, GString *contextStr,
+ int *code, int *mods, int *context,
+ char *cmdName,
+ GList *tokens, GString *fileName, int line);
+#endif
void parseCommand(char *cmdName, GString **val,
GList *tokens, GString *fileName, int line);
void parseYesNo(char *cmdName, GBool *flag,
GList *tokens, GString *fileName, int line);
GBool parseYesNo2(char *token, GBool *flag);
+ void parseInteger(char *cmdName, int *val,
+ GList *tokens, GString *fileName, int line);
+ void parseFloat(char *cmdName, double *val,
+ GList *tokens, GString *fileName, int line);
UnicodeMap *getUnicodeMap2(GString *encodingName);
#ifdef ENABLE_PLUGINS
GBool loadPlugin(char *type, char *name);
@@ -273,6 +395,9 @@ private:
GList *toUnicodeDirs; // list of ToUnicode CMap dirs [GString]
GHash *displayFonts; // display font info, indexed by font name
// [DisplayFontParam]
+#ifdef WIN32
+ WinFontList *winFontList; // system TrueType fonts
+#endif
GHash *displayCIDFonts; // display CID font info, indexed by
// collection [DisplayFontParam]
GHash *displayNamedCIDFonts; // display CID font info, indexed by
@@ -298,6 +423,8 @@ private:
GBool psEmbedTrueType; // embed TrueType fonts?
GBool psEmbedCIDPostScript; // embed CID PostScript fonts?
GBool psEmbedCIDTrueType; // embed CID TrueType fonts?
+ GBool psPreload; // preload PostScript images and forms into
+ // memory
GBool psOPI; // generate PostScript OPI comments?
GBool psASCIIHex; // use ASCIIHex instead of ASCII85?
GString *textEncoding; // encoding (unicodeMap) to use for text
@@ -311,10 +438,22 @@ private:
GBool continuousView; // continuous view mode
GBool enableT1lib; // t1lib enable flag
GBool enableFreeType; // FreeType enable flag
- GBool antialias; // anti-aliasing enable flag
+ GBool antialias; // font anti-aliasing enable flag
+ GBool vectorAntialias; // vector anti-aliasing enable flag
+ GBool strokeAdjust; // stroke adjustment enable flag
+ ScreenType screenType; // halftone screen type
+ int screenSize; // screen matrix size
+ int screenDotRadius; // screen dot radius
+ double screenGamma; // screen gamma correction
+ double screenBlackThreshold; // screen black clamping threshold
+ double screenWhiteThreshold; // screen white clamping threshold
GString *urlCommand; // command executed for URL links
GString *movieCommand; // command executed for movie annotations
GBool mapNumericCharNames; // map numeric char names (from font subsets)?
+ GBool mapUnknownCharNames; // map unknown char names?
+#ifndef PDF_PARSER_ONLY
+ GList *keyBindings; // key & mouse button bindings [KeyBinding]
+#endif
GBool printCommands; // print the drawing commands
GBool errQuiet; // suppress error messages?
diff --git a/Build/source/libs/xpdf/xpdf/JBIG2Stream.cc b/Build/source/libs/xpdf/xpdf/JBIG2Stream.cc
index 5e263079d3a..a4f1b6eacdc 100644
--- a/Build/source/libs/xpdf/xpdf/JBIG2Stream.cc
+++ b/Build/source/libs/xpdf/xpdf/JBIG2Stream.cc
@@ -1099,7 +1099,7 @@ JBIG2CodeTable::~JBIG2CodeTable() {
// JBIG2Stream
//------------------------------------------------------------------------
-JBIG2Stream::JBIG2Stream(Stream *strA, Object *globalsStream):
+JBIG2Stream::JBIG2Stream(Stream *strA, Object *globalsStreamA):
FilterStream(strA)
{
pageBitmap = NULL;
@@ -1124,22 +1124,15 @@ JBIG2Stream::JBIG2Stream(Stream *strA, Object *globalsStream):
huffDecoder = new JBIG2HuffmanDecoder();
mmrDecoder = new JBIG2MMRDecoder();
- segments = globalSegments = new GList();
- if (globalsStream->isStream()) {
- curStr = globalsStream->getStream();
- curStr->reset();
- arithDecoder->setStream(curStr);
- huffDecoder->setStream(curStr);
- mmrDecoder->setStream(curStr);
- readSegments();
- }
-
- segments = NULL;
+ globalsStreamA->copy(&globalsStream);
+ segments = globalSegments = NULL;
curStr = NULL;
dataPtr = dataEnd = NULL;
}
JBIG2Stream::~JBIG2Stream() {
+ close();
+ globalsStream.free();
delete arithDecoder;
delete genericRegionStats;
delete refinementRegionStats;
@@ -1159,28 +1152,25 @@ JBIG2Stream::~JBIG2Stream() {
delete iaidStats;
delete huffDecoder;
delete mmrDecoder;
- if (pageBitmap) {
- delete pageBitmap;
- }
- if (segments) {
- deleteGList(segments, JBIG2Segment);
- }
- if (globalSegments) {
- deleteGList(globalSegments, JBIG2Segment);
- }
delete str;
}
void JBIG2Stream::reset() {
- if (pageBitmap) {
- delete pageBitmap;
- pageBitmap = NULL;
- }
- if (segments) {
- deleteGList(segments, JBIG2Segment);
+ // read the globals stream
+ globalSegments = new GList();
+ if (globalsStream.isStream()) {
+ segments = globalSegments;
+ curStr = globalsStream.getStream();
+ curStr->reset();
+ arithDecoder->setStream(curStr);
+ huffDecoder->setStream(curStr);
+ mmrDecoder->setStream(curStr);
+ readSegments();
+ curStr->close();
}
- segments = new GList();
+ // read the main stream
+ segments = new GList();
curStr = str;
curStr->reset();
arithDecoder->setStream(curStr);
@@ -1192,10 +1182,27 @@ void JBIG2Stream::reset() {
dataPtr = pageBitmap->getDataPtr();
dataEnd = dataPtr + pageBitmap->getDataSize();
} else {
- dataPtr = NULL;
+ dataPtr = dataEnd = NULL;
}
}
+void JBIG2Stream::close() {
+ if (pageBitmap) {
+ delete pageBitmap;
+ pageBitmap = NULL;
+ }
+ if (segments) {
+ deleteGList(segments, JBIG2Segment);
+ segments = NULL;
+ }
+ if (globalSegments) {
+ deleteGList(globalSegments, JBIG2Segment);
+ globalSegments = NULL;
+ }
+ dataPtr = dataEnd = NULL;
+ FilterStream::close();
+}
+
int JBIG2Stream::getChar() {
if (dataPtr && dataPtr < dataEnd) {
return (*dataPtr++ ^ 0xff) & 0xff;
@@ -2352,9 +2359,9 @@ void JBIG2Stream::readHalftoneRegionSeg(Guint segNum, GBool imm,
skipBitmap = new JBIG2Bitmap(0, gridW, gridH);
skipBitmap->clearToZero();
for (m = 0; m < gridH; ++m) {
- xx = gridX + m * stepY;
- yy = gridY + m * stepX;
for (n = 0; n < gridW; ++n) {
+ xx = gridX + m * stepY + n * stepX;
+ yy = gridY + m * stepX - n * stepY;
if (((xx + (int)patW) >> 8) <= 0 || (xx >> 8) >= (int)w ||
((yy + (int)patH) >> 8) <= 0 || (yy >> 8) >= (int)h) {
skipBitmap->setPixel(n, m);
@@ -2401,6 +2408,9 @@ void JBIG2Stream::readHalftoneRegionSeg(Guint segNum, GBool imm,
}
gfree(grayImg);
+ if (skipBitmap) {
+ delete skipBitmap;
+ }
// combine the region bitmap into the page bitmap
if (imm) {
@@ -3331,7 +3341,7 @@ void JBIG2Stream::resetIntStats(int symCodeLen) {
iardwStats->reset();
iardhStats->reset();
iariStats->reset();
- if (iaidStats->getContextSize() == symCodeLen + 1) {
+ if (iaidStats->getContextSize() == 1 << (symCodeLen + 1)) {
iaidStats->reset();
} else {
delete iaidStats;
diff --git a/Build/source/libs/xpdf/xpdf/JBIG2Stream.h b/Build/source/libs/xpdf/xpdf/JBIG2Stream.h
index 44e09db2891..210d927a7cf 100644
--- a/Build/source/libs/xpdf/xpdf/JBIG2Stream.h
+++ b/Build/source/libs/xpdf/xpdf/JBIG2Stream.h
@@ -33,10 +33,11 @@ class JBIG2MMRDecoder;
class JBIG2Stream: public FilterStream {
public:
- JBIG2Stream(Stream *strA, Object *globalsStream);
+ JBIG2Stream(Stream *strA, Object *globalsStreamA);
virtual ~JBIG2Stream();
virtual StreamKind getKind() { return strJBIG2; }
virtual void reset();
+ virtual void close();
virtual int getChar();
virtual int lookChar();
virtual GString *getPSFilter(int psLevel, char *indent);
@@ -109,6 +110,7 @@ private:
GBool readULong(Guint *x);
GBool readLong(int *x);
+ Object globalsStream;
Guint pageW, pageH, curPageH;
Guint pageDefPixel;
JBIG2Bitmap *pageBitmap;
diff --git a/Build/source/libs/xpdf/xpdf/JPXStream.cc b/Build/source/libs/xpdf/xpdf/JPXStream.cc
index d483cd4bf92..7107854912d 100644
--- a/Build/source/libs/xpdf/xpdf/JPXStream.cc
+++ b/Build/source/libs/xpdf/xpdf/JPXStream.cc
@@ -177,6 +177,59 @@ static Guint signContext[5][5][2] = {
//------------------------------------------------------------------------
+#if 1 //----- disable coverage tracking
+
+#define cover(idx)
+
+#else //----- enable coverage tracking
+
+class JPXCover {
+public:
+
+ JPXCover(int sizeA);
+ ~JPXCover();
+ void incr(int idx);
+
+private:
+
+ int size, used;
+ int *data;
+};
+
+JPXCover::JPXCover(int sizeA) {
+ size = sizeA;
+ used = -1;
+ data = (int *)gmallocn(size, sizeof(int));
+ memset(data, 0, size * sizeof(int));
+}
+
+JPXCover::~JPXCover() {
+ int i;
+
+ printf("JPX coverage:\n");
+ for (i = 0; i <= used; ++i) {
+ printf(" %4d: %8d\n", i, data[i]);
+ }
+ gfree(data);
+}
+
+void JPXCover::incr(int idx) {
+ if (idx < size) {
+ ++data[idx];
+ if (idx > used) {
+ used = idx;
+ }
+ }
+}
+
+JPXCover jpxCover(150);
+
+#define cover(idx) jpxCover.incr(idx)
+
+#endif //----- coverage tracking
+
+//------------------------------------------------------------------------
+
JPXStream::JPXStream(Stream *strA):
FilterStream(strA)
{
@@ -196,6 +249,24 @@ JPXStream::JPXStream(Stream *strA):
}
JPXStream::~JPXStream() {
+ close();
+ delete str;
+}
+
+void JPXStream::reset() {
+ str->reset();
+ if (readBoxes()) {
+ curY = img.yOffset;
+ } else {
+ // readBoxes reported an error, so we go immediately to EOF
+ curY = img.ySize;
+ }
+ curX = img.xOffset;
+ curComp = 0;
+ readBufLen = 0;
+}
+
+void JPXStream::close() {
JPXTile *tile;
JPXTileComp *tileComp;
JPXResLevel *resLevel;
@@ -205,19 +276,23 @@ JPXStream::~JPXStream() {
Guint comp, i, k, r, pre, sb;
gfree(bpc);
+ bpc = NULL;
if (havePalette) {
gfree(palette.bpc);
gfree(palette.c);
+ havePalette = gFalse;
}
if (haveCompMap) {
gfree(compMap.comp);
gfree(compMap.type);
gfree(compMap.pComp);
+ haveCompMap = gFalse;
}
if (haveChannelDefn) {
gfree(channelDefn.idx);
gfree(channelDefn.type);
gfree(channelDefn.assoc);
+ haveChannelDefn = gFalse;
}
if (img.tiles) {
@@ -267,21 +342,9 @@ JPXStream::~JPXStream() {
}
}
gfree(img.tiles);
+ img.tiles = NULL;
}
- delete str;
-}
-
-void JPXStream::reset() {
- str->reset();
- if (readBoxes()) {
- curY = img.yOffset;
- } else {
- // readBoxes reported an error, so we go immediately to EOF
- curY = img.ySize;
- }
- curX = img.xOffset;
- curComp = 0;
- readBufLen = 0;
+ FilterStream::close();
}
int JPXStream::getChar() {
@@ -394,8 +457,10 @@ void JPXStream::getImageParams(int *bitsPerComponent,
} else {
while (readBoxHdr(&boxType, &boxLen, &dataLen)) {
if (boxType == 0x6a703268) { // JP2 header
+ cover(0);
// skip the superbox
} else if (boxType == 0x69686472) { // image header
+ cover(1);
if (readULong(&dummy) &&
readULong(&dummy) &&
readUWord(&dummy) &&
@@ -407,6 +472,7 @@ void JPXStream::getImageParams(int *bitsPerComponent,
haveBPC = gTrue;
}
} else if (boxType == 0x636F6C72) { // color specification
+ cover(2);
if (readByte(&csMeth) &&
readByte(&csPrec1) &&
readByte(&dummy2)) {
@@ -440,11 +506,13 @@ void JPXStream::getImageParams(int *bitsPerComponent,
}
}
} else if (boxType == 0x6A703263) { // codestream
+ cover(3);
if (!(haveBPC && haveCSMode)) {
getImageParams2(bitsPerComponent, csMode);
}
break;
} else {
+ cover(4);
for (i = 0; i < dataLen; ++i) {
str->getChar();
}
@@ -462,6 +530,7 @@ void JPXStream::getImageParams2(int *bitsPerComponent,
while (readMarkerHdr(&segType, &segLen)) {
if (segType == 0x51) { // SIZ - image and tile size
+ cover(5);
if (readUWord(&dummy) &&
readULong(&dummy) &&
readULong(&dummy) &&
@@ -485,6 +554,7 @@ void JPXStream::getImageParams2(int *bitsPerComponent,
}
break;
} else {
+ cover(6);
if (segLen > 2) {
for (i = 0; i < segLen - 2; ++i) {
str->getChar();
@@ -505,6 +575,7 @@ GBool JPXStream::readBoxes() {
// wrapper) -- this appears to be a violation of the PDF spec, but
// Acrobat allows it
if (str->lookChar() == 0xff) {
+ cover(7);
error(getPos(), "Naked JPEG 2000 codestream, missing JP2/JPX wrapper");
readCodestream(0);
nComps = img.nComps;
@@ -525,8 +596,10 @@ GBool JPXStream::readBoxes() {
// some things which should be subboxes of the JP2 header box
// show up outside of it - so we simply ignore the JP2 header
// box
+ cover(8);
break;
case 0x69686472: // image header
+ cover(9);
if (!readULong(&height) ||
!readULong(&width) ||
!readUWord(&nComps) ||
@@ -548,6 +621,7 @@ GBool JPXStream::readBoxes() {
haveImgHdr = gTrue;
break;
case 0x62706363: // bits per component
+ cover(10);
if (!haveImgHdr) {
error(getPos(), "Found bits per component box before image header box in JPX stream");
return gFalse;
@@ -564,11 +638,13 @@ GBool JPXStream::readBoxes() {
}
break;
case 0x636F6C72: // color specification
+ cover(11);
if (!readColorSpecBox(dataLen)) {
return gFalse;
}
break;
case 0x70636c72: // palette
+ cover(12);
if (!readUWord(&palette.nEntries) ||
!readUByte(&palette.nComps)) {
error(getPos(), "Unexpected EOF in JPX stream");
@@ -597,6 +673,7 @@ GBool JPXStream::readBoxes() {
havePalette = gTrue;
break;
case 0x636d6170: // component mapping
+ cover(13);
compMap.nChannels = dataLen / 4;
compMap.comp = (Guint *)gmallocn(compMap.nChannels, sizeof(Guint));
compMap.type = (Guint *)gmallocn(compMap.nChannels, sizeof(Guint));
@@ -612,6 +689,7 @@ GBool JPXStream::readBoxes() {
haveCompMap = gTrue;
break;
case 0x63646566: // channel definition
+ cover(14);
if (!readUWord(&channelDefn.nChannels)) {
error(getPos(), "Unexpected EOF in JPX stream");
return gFalse;
@@ -633,6 +711,7 @@ GBool JPXStream::readBoxes() {
haveChannelDefn = gTrue;
break;
case 0x6A703263: // contiguous codestream
+ cover(15);
if (!bpc) {
error(getPos(), "JPX stream is missing the image header box");
}
@@ -644,6 +723,7 @@ GBool JPXStream::readBoxes() {
}
break;
default:
+ cover(16);
for (i = 0; i < dataLen; ++i) {
if (str->getChar() == EOF) {
error(getPos(), "Unexpected EOF in JPX stream");
@@ -670,6 +750,7 @@ GBool JPXStream::readColorSpecBox(Guint dataLen) {
}
switch (newCS.meth) {
case 1: // enumerated colorspace
+ cover(17);
if (!readULong(&csEnum)) {
goto err;
}
@@ -712,6 +793,7 @@ GBool JPXStream::readColorSpecBox(Guint dataLen) {
}
} else if (dataLen == 7) {
//~ this assumes the 8-bit case
+ cover(92);
newCS.enumerated.cieLab.rl = 100;
newCS.enumerated.cieLab.ol = 0;
newCS.enumerated.cieLab.ra = 255;
@@ -758,6 +840,7 @@ GBool JPXStream::readColorSpecBox(Guint dataLen) {
case 2: // restricted ICC profile
case 3: // any ICC profile (JPX)
case 4: // vendor color (JPX)
+ cover(18);
for (i = 0; i < dataLen - 3; ++i) {
if (str->getChar() == EOF) {
goto err;
@@ -784,7 +867,7 @@ GBool JPXStream::readCodestream(Guint len) {
int segType;
GBool haveSIZ, haveCOD, haveQCD, haveSOT;
Guint precinctSize, style;
- Guint segLen, capabilities, nTiles, comp, i, j, r;
+ Guint segLen, capabilities, comp, i, j, r;
//----- main header
haveSIZ = haveCOD = haveQCD = haveSOT = gFalse;
@@ -796,8 +879,10 @@ GBool JPXStream::readCodestream(Guint len) {
switch (segType) {
case 0x4f: // SOC - start of codestream
// marker only
+ cover(19);
break;
case 0x51: // SIZ - image and tile size
+ cover(20);
if (!readUWord(&capabilities) ||
!readULong(&img.xSize) ||
!readULong(&img.ySize) ||
@@ -819,14 +904,14 @@ GBool JPXStream::readCodestream(Guint len) {
/ img.xTileSize;
img.nYTiles = (img.ySize - img.yTileOffset + img.yTileSize - 1)
/ img.yTileSize;
- nTiles = img.nXTiles * img.nYTiles;
// check for overflow before allocating memory
if (img.nXTiles <= 0 || img.nYTiles <= 0 ||
img.nXTiles >= INT_MAX / img.nYTiles) {
error(getPos(), "Bad tile count in JPX SIZ marker segment");
return gFalse;
}
- img.tiles = (JPXTile *)gmallocn(nTiles, sizeof(JPXTile));
+ img.tiles = (JPXTile *)gmallocn(img.nXTiles * img.nYTiles,
+ sizeof(JPXTile));
for (i = 0; i < img.nXTiles * img.nYTiles; ++i) {
img.tiles[i].tileComps = (JPXTileComp *)gmallocn(img.nComps,
sizeof(JPXTileComp));
@@ -855,6 +940,7 @@ GBool JPXStream::readCodestream(Guint len) {
haveSIZ = gTrue;
break;
case 0x52: // COD - coding style default
+ cover(21);
if (!readUByte(&img.tiles[0].tileComps[0].style) ||
!readUByte(&img.tiles[0].progOrder) ||
!readUWord(&img.tiles[0].nLayers) ||
@@ -901,6 +987,7 @@ GBool JPXStream::readCodestream(Guint len) {
}
for (r = 0; r <= img.tiles[0].tileComps[0].nDecompLevels; ++r) {
if (img.tiles[0].tileComps[0].style & 0x01) {
+ cover(91);
if (!readUByte(&precinctSize)) {
error(getPos(), "Error in JPX COD marker segment");
return gFalse;
@@ -929,6 +1016,7 @@ GBool JPXStream::readCodestream(Guint len) {
haveCOD = gTrue;
break;
case 0x53: // COC - coding style component
+ cover(22);
if (!haveCOD) {
error(getPos(), "JPX COC marker segment before COD segment");
return gFalse;
@@ -998,6 +1086,7 @@ GBool JPXStream::readCodestream(Guint len) {
}
break;
case 0x5c: // QCD - quantization default
+ cover(23);
if (!readUByte(&img.tiles[0].tileComps[0].quantStyle)) {
error(getPos(), "Error in JPX QCD marker segment");
return gFalse;
@@ -1061,6 +1150,7 @@ GBool JPXStream::readCodestream(Guint len) {
haveQCD = gTrue;
break;
case 0x5d: // QCC - quantization component
+ cover(24);
if (!haveQCD) {
error(getPos(), "JPX QCC marker segment before QCD segment");
return gFalse;
@@ -1128,6 +1218,7 @@ GBool JPXStream::readCodestream(Guint len) {
}
break;
case 0x5e: // RGN - region of interest
+ cover(25);
#if 1 //~ ROI is unimplemented
fprintf(stderr, "RGN\n");
for (i = 0; i < segLen - 2; ++i) {
@@ -1148,6 +1239,7 @@ GBool JPXStream::readCodestream(Guint len) {
#endif
break;
case 0x5f: // POC - progression order change
+ cover(26);
#if 1 //~ progression order changes are unimplemented
fprintf(stderr, "POC\n");
for (i = 0; i < segLen - 2; ++i) {
@@ -1175,6 +1267,7 @@ GBool JPXStream::readCodestream(Guint len) {
#endif
break;
case 0x60: // PPM - packed packet headers, main header
+ cover(27);
#if 1 //~ packed packet headers are unimplemented
fprintf(stderr, "PPM\n");
for (i = 0; i < segLen - 2; ++i) {
@@ -1187,6 +1280,7 @@ GBool JPXStream::readCodestream(Guint len) {
break;
case 0x55: // TLM - tile-part lengths
// skipped
+ cover(28);
for (i = 0; i < segLen - 2; ++i) {
if (str->getChar() == EOF) {
error(getPos(), "Error in JPX TLM marker segment");
@@ -1196,6 +1290,7 @@ GBool JPXStream::readCodestream(Guint len) {
break;
case 0x57: // PLM - packet length, main header
// skipped
+ cover(29);
for (i = 0; i < segLen - 2; ++i) {
if (str->getChar() == EOF) {
error(getPos(), "Error in JPX PLM marker segment");
@@ -1205,6 +1300,7 @@ GBool JPXStream::readCodestream(Guint len) {
break;
case 0x63: // CRG - component registration
// skipped
+ cover(30);
for (i = 0; i < segLen - 2; ++i) {
if (str->getChar() == EOF) {
error(getPos(), "Error in JPX CRG marker segment");
@@ -1214,6 +1310,7 @@ GBool JPXStream::readCodestream(Guint len) {
break;
case 0x64: // COM - comment
// skipped
+ cover(31);
for (i = 0; i < segLen - 2; ++i) {
if (str->getChar() == EOF) {
error(getPos(), "Error in JPX COM marker segment");
@@ -1222,9 +1319,11 @@ GBool JPXStream::readCodestream(Guint len) {
}
break;
case 0x90: // SOT - start of tile
+ cover(32);
haveSOT = gTrue;
break;
default:
+ cover(33);
error(getPos(), "Unknown marker segment %02x in JPX stream", segType);
for (i = 0; i < segLen - 2; ++i) {
if (str->getChar() == EOF) {
@@ -1325,6 +1424,7 @@ GBool JPXStream::readTilePart() {
tilePartLen -= 2 + segLen;
switch (segType) {
case 0x52: // COD - coding style default
+ cover(34);
if (!readUByte(&img.tiles[tileIdx].tileComps[0].style) ||
!readUByte(&img.tiles[tileIdx].progOrder) ||
!readUWord(&img.tiles[tileIdx].nLayers) ||
@@ -1392,6 +1492,7 @@ GBool JPXStream::readTilePart() {
}
break;
case 0x53: // COC - coding style component
+ cover(35);
if ((img.nComps > 256 && !readUWord(&comp)) ||
(img.nComps <= 256 && !readUByte(&comp)) ||
comp >= img.nComps ||
@@ -1433,6 +1534,7 @@ GBool JPXStream::readTilePart() {
}
break;
case 0x5c: // QCD - quantization default
+ cover(36);
if (!readUByte(&img.tiles[tileIdx].tileComps[0].quantStyle)) {
error(getPos(), "Error in JPX QCD marker segment");
return gFalse;
@@ -1492,6 +1594,7 @@ GBool JPXStream::readTilePart() {
}
break;
case 0x5d: // QCC - quantization component
+ cover(37);
if ((img.nComps > 256 && !readUWord(&comp)) ||
(img.nComps <= 256 && !readUByte(&comp)) ||
comp >= img.nComps ||
@@ -1543,6 +1646,7 @@ GBool JPXStream::readTilePart() {
}
break;
case 0x5e: // RGN - region of interest
+ cover(38);
#if 1 //~ ROI is unimplemented
fprintf(stderr, "RGN\n");
for (i = 0; i < segLen - 2; ++i) {
@@ -1563,6 +1667,7 @@ GBool JPXStream::readTilePart() {
#endif
break;
case 0x5f: // POC - progression order change
+ cover(39);
#if 1 //~ progression order changes are unimplemented
fprintf(stderr, "POC\n");
for (i = 0; i < segLen - 2; ++i) {
@@ -1590,6 +1695,7 @@ GBool JPXStream::readTilePart() {
#endif
break;
case 0x61: // PPT - packed packet headers, tile-part hdr
+ cover(40);
#if 1 //~ packed packet headers are unimplemented
fprintf(stderr, "PPT\n");
for (i = 0; i < segLen - 2; ++i) {
@@ -1601,6 +1707,7 @@ GBool JPXStream::readTilePart() {
#endif
case 0x58: // PLT - packet length, tile-part header
// skipped
+ cover(41);
for (i = 0; i < segLen - 2; ++i) {
if (str->getChar() == EOF) {
error(getPos(), "Error in JPX PLT marker segment");
@@ -1610,6 +1717,7 @@ GBool JPXStream::readTilePart() {
break;
case 0x64: // COM - comment
// skipped
+ cover(42);
for (i = 0; i < segLen - 2; ++i) {
if (str->getChar() == EOF) {
error(getPos(), "Error in JPX COM marker segment");
@@ -1618,9 +1726,11 @@ GBool JPXStream::readTilePart() {
}
break;
case 0x93: // SOD - start of data
+ cover(43);
haveSOD = gTrue;
break;
default:
+ cover(44);
error(getPos(), "Unknown marker segment %02x in JPX tile-part stream",
segType);
for (i = 0; i < segLen - 2; ++i) {
@@ -1818,6 +1928,7 @@ GBool JPXStream::readTilePartData(Guint tileIdx,
while (1) {
if (tilePartToEOC) {
//~ peek for an EOC marker
+ cover(93);
} else if (tilePartLen == 0) {
break;
}
@@ -1828,12 +1939,16 @@ GBool JPXStream::readTilePartData(Guint tileIdx,
//----- packet header
+ // setup
+ startBitBuf(tilePartLen);
+
// zero-length flag
if (!readBits(1, &bits)) {
goto err;
}
if (!bits) {
// packet is empty -- clear all code-block inclusion flags
+ cover(45);
for (sb = 0; sb < (Guint)(tile->res == 0 ? 1 : 3); ++sb) {
subband = &precinct->subbands[sb];
for (cbY = 0; cbY < subband->nYCBs; ++cbY) {
@@ -1853,16 +1968,19 @@ GBool JPXStream::readTilePartData(Guint tileIdx,
// skip code-blocks with no coefficients
if (cb->x0 >= cb->x1 || cb->y0 >= cb->y1) {
+ cover(46);
cb->included = gFalse;
continue;
}
// code-block inclusion
if (cb->seen) {
+ cover(47);
if (!readBits(1, &cb->included)) {
goto err;
}
} else {
+ cover(48);
ttVal = 0;
i = 0;
for (level = subband->maxTTLevel; level >= 0; --level) {
@@ -1896,9 +2014,11 @@ GBool JPXStream::readTilePartData(Guint tileIdx,
}
if (cb->included) {
+ cover(49);
// zero bit-plane count
if (!cb->seen) {
+ cover(50);
ttVal = 0;
i = 0;
for (level = subband->maxTTLevel; level >= 0; --level) {
@@ -1932,26 +2052,33 @@ GBool JPXStream::readTilePartData(Guint tileIdx,
goto err;
}
if (bits == 0) {
+ cover(51);
cb->nCodingPasses = 1;
} else {
if (!readBits(1, &bits)) {
goto err;
}
if (bits == 0) {
+ cover(52);
cb->nCodingPasses = 2;
} else {
+ cover(53);
if (!readBits(2, &bits)) {
goto err;
}
if (bits < 3) {
+ cover(54);
cb->nCodingPasses = 3 + bits;
} else {
+ cover(55);
if (!readBits(5, &bits)) {
goto err;
}
if (bits < 31) {
+ cover(56);
cb->nCodingPasses = 6 + bits;
} else {
+ cover(57);
if (!readBits(7, &bits)) {
goto err;
}
@@ -1985,8 +2112,7 @@ GBool JPXStream::readTilePartData(Guint tileIdx,
}
}
}
- tilePartLen -= byteCount;
- clearBitBuf();
+ tilePartLen = finishBitBuf();
//----- packet data
@@ -2011,6 +2137,7 @@ GBool JPXStream::readTilePartData(Guint tileIdx,
switch (tile->progOrder) {
case 0: // layer, resolution level, component, precinct
+ cover(58);
if (++tile->comp == img.nComps) {
tile->comp = 0;
if (++tile->res == tile->maxNDecompLevels + 1) {
@@ -2022,6 +2149,7 @@ GBool JPXStream::readTilePartData(Guint tileIdx,
}
break;
case 1: // resolution level, layer, component, precinct
+ cover(59);
if (++tile->comp == img.nComps) {
tile->comp = 0;
if (++tile->layer == tile->nLayers) {
@@ -2034,6 +2162,7 @@ GBool JPXStream::readTilePartData(Guint tileIdx,
break;
case 2: // resolution level, precinct, component, layer
//~ this isn't correct -- see B.12.1.3
+ cover(60);
if (++tile->layer == tile->nLayers) {
tile->layer = 0;
if (++tile->comp == img.nComps) {
@@ -2046,6 +2175,7 @@ GBool JPXStream::readTilePartData(Guint tileIdx,
break;
case 3: // precinct, component, resolution level, layer
//~ this isn't correct -- see B.12.1.4
+ cover(61);
if (++tile->layer == tile->nLayers) {
tile->layer = 0;
if (++tile->res == tile->maxNDecompLevels + 1) {
@@ -2058,6 +2188,7 @@ GBool JPXStream::readTilePartData(Guint tileIdx,
break;
case 4: // component, precinct, resolution level, layer
//~ this isn't correct -- see B.12.1.5
+ cover(62);
if (++tile->layer == tile->nLayers) {
tile->layer = 0;
if (++tile->res == tile->maxNDecompLevels + 1) {
@@ -2090,8 +2221,10 @@ GBool JPXStream::readCodeBlockData(JPXTileComp *tileComp,
Guint i, x, y0, y1, y2;
if (cb->arithDecoder) {
+ cover(63);
cb->arithDecoder->restart(cb->dataLen);
} else {
+ cover(64);
cb->arithDecoder = new JArithmeticDecoder();
cb->arithDecoder->setStream(str, cb->dataLen);
cb->arithDecoder->start();
@@ -2106,6 +2239,7 @@ GBool JPXStream::readCodeBlockData(JPXTileComp *tileComp,
//----- significance propagation pass
case jpxPassSigProp:
+ cover(65);
for (y0 = cb->y0, coeff0 = cb->coeffs;
y0 < cb->y1;
y0 += 4, coeff0 += 4 << tileComp->codeBlockW) {
@@ -2183,6 +2317,7 @@ GBool JPXStream::readCodeBlockData(JPXTileComp *tileComp,
//----- magnitude refinement pass
case jpxPassMagRef:
+ cover(66);
for (y0 = cb->y0, coeff0 = cb->coeffs;
y0 < cb->y1;
y0 += 4, coeff0 += 4 << tileComp->codeBlockW) {
@@ -2244,6 +2379,7 @@ GBool JPXStream::readCodeBlockData(JPXTileComp *tileComp,
//----- cleanup pass
case jpxPassCleanup:
+ cover(67);
for (y0 = cb->y0, coeff0 = cb->coeffs;
y0 < cb->y1;
y0 += 4, coeff0 += 4 << tileComp->codeBlockW) {
@@ -2405,6 +2541,8 @@ void JPXStream::inverseTransform(JPXTileComp *tileComp) {
Guint nx0, ny0, nx1, ny1;
Guint r, cbX, cbY, x, y;
+ cover(68);
+
//----- (NL)LL subband (resolution level 0)
resLevel = &tileComp->resLevels[0];
@@ -2415,14 +2553,17 @@ void JPXStream::inverseTransform(JPXTileComp *tileComp) {
qStyle = tileComp->quantStyle & 0x1f;
guard = (tileComp->quantStyle >> 5) & 7;
if (qStyle == 0) {
+ cover(69);
eps = (tileComp->quantSteps[0] >> 3) & 0x1f;
shift = guard + eps - 1;
mu = 0; // make gcc happy
} else {
+ cover(70);
shift = guard - 1 + tileComp->prec;
mu = (double)(0x800 + (tileComp->quantSteps[0] & 0x7ff)) / 2048.0;
}
if (tileComp->transform == 0) {
+ cover(71);
shift += fracBits;
}
@@ -2442,18 +2583,24 @@ void JPXStream::inverseTransform(JPXTileComp *tileComp) {
if (val != 0) {
shift2 = shift - (cb->nZeroBitPlanes + coeff->len);
if (shift2 > 0) {
+ cover(94);
val = (val << shift2) + (1 << (shift2 - 1));
} else {
+ cover(95);
val >>= -shift2;
}
if (qStyle == 0) {
+ cover(96);
if (tileComp->transform == 0) {
+ cover(97);
val &= -1 << fracBits;
}
} else {
+ cover(98);
val = (int)((double)val * mu);
}
if (coeff->flags & jpxCoeffSign) {
+ cover(99);
val = -val;
}
}
@@ -2474,11 +2621,13 @@ void JPXStream::inverseTransform(JPXTileComp *tileComp) {
// and inverse transform to get (n-1)LL, which will be stored
// in the upper-left corner of the tile-component data array
if (r == tileComp->nDecompLevels) {
+ cover(72);
nx0 = tileComp->x0;
ny0 = tileComp->y0;
nx1 = tileComp->x1;
ny1 = tileComp->y1;
} else {
+ cover(73);
nx0 = tileComp->resLevels[r+1].x0;
ny0 = tileComp->resLevels[r+1].y0;
nx1 = tileComp->resLevels[r+1].x1;
@@ -2531,18 +2680,22 @@ void JPXStream::inverseTransformLevel(JPXTileComp *tileComp,
// i-quant parameters
if (qStyle == 0) {
+ cover(100);
eps = (tileComp->quantSteps[3*r - 2 + sb] >> 3) & 0x1f;
shift = guard + eps - 1;
mu = 0; // make gcc happy
} else {
+ cover(101);
shift = guard + tileComp->prec;
if (sb == 2) {
+ cover(102);
++shift;
}
t = tileComp->quantSteps[qStyle == 1 ? 0 : (3*r - 2 + sb)];
mu = (double)(0x800 + (t & 0x7ff)) / 2048.0;
}
if (tileComp->transform == 0) {
+ cover(103);
shift += fracBits;
}
@@ -2565,18 +2718,23 @@ void JPXStream::inverseTransformLevel(JPXTileComp *tileComp,
if (val != 0) {
shift2 = shift - (cb->nZeroBitPlanes + coeff->len);
if (shift2 > 0) {
+ cover(74);
val = (val << shift2) + (1 << (shift2 - 1));
} else {
+ cover(75);
val >>= -shift2;
}
if (qStyle == 0) {
+ cover(76);
if (tileComp->transform == 0) {
val &= -1 << fracBits;
}
} else {
+ cover(77);
val = (int)((double)val * mu);
}
if (coeff->flags & jpxCoeffSign) {
+ cover(78);
val = -val;
}
}
@@ -2613,11 +2771,14 @@ void JPXStream::inverseTransform1D(JPXTileComp *tileComp,
//----- special case for length = 1
if (i1 - i0 == 1) {
+ cover(79);
if (i0 & 1) {
+ cover(104);
*data >>= 1;
}
} else {
+ cover(80);
// choose an offset: this makes even buf[] indexes correspond to
// odd values of i, and vice versa
@@ -2633,19 +2794,25 @@ void JPXStream::inverseTransform1D(JPXTileComp *tileComp,
//----- extend right
buf[end] = buf[end - 2];
if (i1 - i0 == 2) {
+ cover(81);
buf[end+1] = buf[offset + 1];
buf[end+2] = buf[offset];
buf[end+3] = buf[offset + 1];
} else {
+ cover(82);
buf[end+1] = buf[end - 3];
if (i1 - i0 == 3) {
+ cover(105);
buf[end+2] = buf[offset + 1];
buf[end+3] = buf[offset + 2];
} else {
+ cover(106);
buf[end+2] = buf[end - 4];
if (i1 - i0 == 4) {
+ cover(107);
buf[end+3] = buf[offset + 1];
} else {
+ cover(108);
buf[end+3] = buf[end - 5];
}
}
@@ -2656,12 +2823,14 @@ void JPXStream::inverseTransform1D(JPXTileComp *tileComp,
buf[offset - 2] = buf[offset + 2];
buf[offset - 3] = buf[offset + 3];
if (offset == 4) {
+ cover(83);
buf[0] = buf[offset + 4];
}
//----- 9-7 irreversible filter
if (tileComp->transform == 0) {
+ cover(84);
// step 1 (even)
for (i = 1; i <= end + 2; i += 2) {
buf[i] = (int)(idwtKappa * buf[i]);
@@ -2690,6 +2859,7 @@ void JPXStream::inverseTransform1D(JPXTileComp *tileComp,
//----- 5-3 reversible filter
} else {
+ cover(85);
// step 1 (even)
for (i = 3; i <= end; i += 2) {
buf[i] -= (buf[i-1] + buf[i+1] + 2) >> 2;
@@ -2718,6 +2888,7 @@ GBool JPXStream::inverseMultiCompAndDC(JPXTile *tile) {
//----- inverse multi-component transform
if (tile->multiComp == 1) {
+ cover(86);
if (img.nComps < 3 ||
tile->tileComps[0].hSep != tile->tileComps[1].hSep ||
tile->tileComps[0].vSep != tile->tileComps[1].vSep ||
@@ -2728,6 +2899,7 @@ GBool JPXStream::inverseMultiCompAndDC(JPXTile *tile) {
// inverse irreversible multiple component transform
if (tile->tileComps[0].transform == 0) {
+ cover(87);
j = 0;
for (y = 0; y < tile->tileComps[0].y1 - tile->tileComps[0].y0; ++y) {
for (x = 0; x < tile->tileComps[0].x1 - tile->tileComps[0].x0; ++x) {
@@ -2744,6 +2916,7 @@ GBool JPXStream::inverseMultiCompAndDC(JPXTile *tile) {
// inverse reversible multiple component transform
} else {
+ cover(88);
j = 0;
for (y = 0; y < tile->tileComps[0].y1 - tile->tileComps[0].y0; ++y) {
for (x = 0; x < tile->tileComps[0].x1 - tile->tileComps[0].x0; ++x) {
@@ -2765,6 +2938,7 @@ GBool JPXStream::inverseMultiCompAndDC(JPXTile *tile) {
// signed: clip
if (tileComp->sgned) {
+ cover(89);
minVal = -(1 << (tileComp->prec - 1));
maxVal = (1 << (tileComp->prec - 1)) - 1;
dataPtr = tileComp->data;
@@ -2772,11 +2946,14 @@ GBool JPXStream::inverseMultiCompAndDC(JPXTile *tile) {
for (x = 0; x < tileComp->x1 - tileComp->x0; ++x) {
coeff = *dataPtr;
if (tileComp->transform == 0) {
+ cover(109);
coeff >>= fracBits;
}
if (coeff < minVal) {
+ cover(110);
coeff = minVal;
} else if (coeff > maxVal) {
+ cover(111);
coeff = maxVal;
}
*dataPtr++ = coeff;
@@ -2785,6 +2962,7 @@ GBool JPXStream::inverseMultiCompAndDC(JPXTile *tile) {
// unsigned: inverse DC level shift and clip
} else {
+ cover(90);
maxVal = (1 << tileComp->prec) - 1;
zeroVal = 1 << (tileComp->prec - 1);
dataPtr = tileComp->data;
@@ -2792,12 +2970,15 @@ GBool JPXStream::inverseMultiCompAndDC(JPXTile *tile) {
for (x = 0; x < tileComp->x1 - tileComp->x0; ++x) {
coeff = *dataPtr;
if (tileComp->transform == 0) {
+ cover(112);
coeff >>= fracBits;
}
coeff += zeroVal;
if (coeff < 0) {
+ cover(113);
coeff = 0;
} else if (coeff > maxVal) {
+ cover(114);
coeff = maxVal;
}
*dataPtr++ = coeff;
@@ -2930,10 +3111,10 @@ GBool JPXStream::readBits(int nBits, Guint *x) {
int c;
while (bitBufLen < nBits) {
- if ((c = str->getChar()) == EOF) {
+ if (byteCount == 0 || (c = str->getChar()) == EOF) {
return gFalse;
}
- ++byteCount;
+ --byteCount;
if (bitBufSkip) {
bitBuf = (bitBuf << 7) | (c & 0x7f);
bitBufLen += 7;
@@ -2948,8 +3129,16 @@ GBool JPXStream::readBits(int nBits, Guint *x) {
return gTrue;
}
-void JPXStream::clearBitBuf() {
+void JPXStream::startBitBuf(Guint byteCountA) {
bitBufLen = 0;
bitBufSkip = gFalse;
- byteCount = 0;
+ byteCount = byteCountA;
+}
+
+Guint JPXStream::finishBitBuf() {
+ if (bitBufSkip) {
+ str->getChar();
+ --byteCount;
+ }
+ return byteCount;
}
diff --git a/Build/source/libs/xpdf/xpdf/JPXStream.h b/Build/source/libs/xpdf/xpdf/JPXStream.h
index e64731db08a..e96e7d388e9 100644
--- a/Build/source/libs/xpdf/xpdf/JPXStream.h
+++ b/Build/source/libs/xpdf/xpdf/JPXStream.h
@@ -19,6 +19,7 @@
#include "Object.h"
#include "Stream.h"
+class JArithmeticDecoder;
class JArithmeticDecoderStats;
//------------------------------------------------------------------------
@@ -277,6 +278,7 @@ public:
virtual ~JPXStream();
virtual StreamKind getKind() { return strJPX; }
virtual void reset();
+ virtual void close();
virtual int getChar();
virtual int lookChar();
virtual GString *getPSFilter(int psLevel, char *indent);
@@ -317,7 +319,8 @@ private:
GBool readULong(Guint *x);
GBool readNBytes(int nBytes, GBool signd, int *x);
GBool readBits(int nBits, Guint *x);
- void clearBitBuf();
+ void startBitBuf(Guint byteCountA);
+ Guint finishBitBuf();
Guint nComps; // number of components
Guint *bpc; // bits per component, for each component
@@ -338,8 +341,7 @@ private:
int bitBufLen; // number of bits in bitBuf
GBool bitBufSkip; // true if next bit should be skipped
// (for bit stuffing)
- Guint byteCount; // number of bytes read since last call
- // to clearBitBuf
+ Guint byteCount; // number of available bytes left
Guint curX, curY, curComp; // current position for lookChar/getChar
Guint readBuf; // read buffer
diff --git a/Build/source/libs/xpdf/xpdf/Link.cc b/Build/source/libs/xpdf/xpdf/Link.cc
index 898ca20c355..ae2de537e36 100644
--- a/Build/source/libs/xpdf/xpdf/Link.cc
+++ b/Build/source/libs/xpdf/xpdf/Link.cc
@@ -288,7 +288,7 @@ LinkDest::LinkDest(Array *a) {
kind = destFitH;
if (!a->get(2, &obj2)->isNum()) {
error(-1, "Bad annotation destination position");
- goto err1;
+ kind = destFit;
}
top = obj2.getNum();
obj2.free();
@@ -302,7 +302,7 @@ LinkDest::LinkDest(Array *a) {
kind = destFitV;
if (!a->get(2, &obj2)->isNum()) {
error(-1, "Bad annotation destination position");
- goto err1;
+ kind = destFit;
}
left = obj2.getNum();
obj2.free();
@@ -316,25 +316,25 @@ LinkDest::LinkDest(Array *a) {
kind = destFitR;
if (!a->get(2, &obj2)->isNum()) {
error(-1, "Bad annotation destination position");
- goto err1;
+ kind = destFit;
}
left = obj2.getNum();
obj2.free();
if (!a->get(3, &obj2)->isNum()) {
error(-1, "Bad annotation destination position");
- goto err1;
+ kind = destFit;
}
bottom = obj2.getNum();
obj2.free();
if (!a->get(4, &obj2)->isNum()) {
error(-1, "Bad annotation destination position");
- goto err1;
+ kind = destFit;
}
right = obj2.getNum();
obj2.free();
if (!a->get(5, &obj2)->isNum()) {
error(-1, "Bad annotation destination position");
- goto err1;
+ kind = destFit;
}
top = obj2.getNum();
obj2.free();
@@ -356,7 +356,7 @@ LinkDest::LinkDest(Array *a) {
kind = destFitBH;
if (!a->get(2, &obj2)->isNum()) {
error(-1, "Bad annotation destination position");
- goto err1;
+ kind = destFit;
}
top = obj2.getNum();
obj2.free();
@@ -370,7 +370,7 @@ LinkDest::LinkDest(Array *a) {
kind = destFitBV;
if (!a->get(2, &obj2)->isNum()) {
error(-1, "Bad annotation destination position");
- goto err1;
+ kind = destFit;
}
left = obj2.getNum();
obj2.free();
@@ -635,42 +635,13 @@ LinkUnknown::~LinkUnknown() {
}
//------------------------------------------------------------------------
-// LinkBorderStyle
-//------------------------------------------------------------------------
-
-LinkBorderStyle::LinkBorderStyle(LinkBorderType typeA, double widthA,
- double *dashA, int dashLengthA,
- double rA, double gA, double bA) {
- type = typeA;
- width = widthA;
- dash = dashA;
- dashLength = dashLengthA;
- r = rA;
- g = gA;
- b = bA;
-}
-
-LinkBorderStyle::~LinkBorderStyle() {
- if (dash) {
- gfree(dash);
- }
-}
-
-//------------------------------------------------------------------------
// Link
//------------------------------------------------------------------------
Link::Link(Dict *dict, GString *baseURI) {
- Object obj1, obj2, obj3;
- LinkBorderType borderType;
- double borderWidth;
- double *borderDash;
- int borderDashLength;
- double borderR, borderG, borderB;
+ Object obj1, obj2;
double t;
- int i;
- borderStyle = NULL;
action = NULL;
ok = gFalse;
@@ -715,97 +686,6 @@ Link::Link(Dict *dict, GString *baseURI) {
y2 = t;
}
- // get the border style info
- borderType = linkBorderSolid;
- borderWidth = 1;
- borderDash = NULL;
- borderDashLength = 0;
- borderR = 0;
- borderG = 0;
- borderB = 1;
- if (dict->lookup("BS", &obj1)->isDict()) {
- if (obj1.dictLookup("S", &obj2)->isName()) {
- if (obj2.isName("S")) {
- borderType = linkBorderSolid;
- } else if (obj2.isName("D")) {
- borderType = linkBorderDashed;
- } else if (obj2.isName("B")) {
- borderType = linkBorderEmbossed;
- } else if (obj2.isName("I")) {
- borderType = linkBorderEngraved;
- } else if (obj2.isName("U")) {
- borderType = linkBorderUnderlined;
- }
- }
- obj2.free();
- if (obj1.dictLookup("W", &obj2)->isNum()) {
- borderWidth = obj2.getNum();
- }
- obj2.free();
- if (obj1.dictLookup("D", &obj2)->isArray()) {
- borderDashLength = obj2.arrayGetLength();
- borderDash = (double *)gmallocn(borderDashLength, sizeof(double));
- for (i = 0; i < borderDashLength; ++i) {
- if (obj2.arrayGet(i, &obj3)->isNum()) {
- borderDash[i] = obj3.getNum();
- } else {
- borderDash[i] = 1;
- }
- obj3.free();
- }
- }
- obj2.free();
- } else {
- obj1.free();
- if (dict->lookup("Border", &obj1)->isArray()) {
- if (obj1.arrayGetLength() >= 3) {
- if (obj1.arrayGet(2, &obj2)->isNum()) {
- borderWidth = obj2.getNum();
- }
- obj2.free();
- if (obj1.arrayGetLength() >= 4) {
- if (obj1.arrayGet(3, &obj2)->isArray()) {
- borderType = linkBorderDashed;
- borderDashLength = obj2.arrayGetLength();
- borderDash = (double *)gmallocn(borderDashLength, sizeof(double));
- for (i = 0; i < borderDashLength; ++i) {
- if (obj2.arrayGet(i, &obj3)->isNum()) {
- borderDash[i] = obj3.getNum();
- } else {
- borderDash[i] = 1;
- }
- obj3.free();
- }
- } else {
- // Adobe draws no border at all if the last element is of
- // the wrong type.
- borderWidth = 0;
- }
- obj2.free();
- }
- }
- }
- }
- obj1.free();
- if (dict->lookup("C", &obj1)->isArray() && obj1.arrayGetLength() == 3) {
- if (obj1.arrayGet(0, &obj2)->isNum()) {
- borderR = obj2.getNum();
- }
- obj1.free();
- if (obj1.arrayGet(1, &obj2)->isNum()) {
- borderG = obj2.getNum();
- }
- obj1.free();
- if (obj1.arrayGet(2, &obj2)->isNum()) {
- borderB = obj2.getNum();
- }
- obj1.free();
- }
- obj1.free();
- borderStyle = new LinkBorderStyle(borderType, borderWidth,
- borderDash, borderDashLength,
- borderR, borderG, borderB);
-
// look for destination
if (!dict->lookup("Dest", &obj1)->isNull()) {
action = LinkAction::parseDest(&obj1);
@@ -833,9 +713,6 @@ Link::Link(Dict *dict, GString *baseURI) {
}
Link::~Link() {
- if (borderStyle) {
- delete borderStyle;
- }
if (action) {
delete action;
}
diff --git a/Build/source/libs/xpdf/xpdf/Link.h b/Build/source/libs/xpdf/xpdf/Link.h
index 9f044204966..698f2c85294 100644
--- a/Build/source/libs/xpdf/xpdf/Link.h
+++ b/Build/source/libs/xpdf/xpdf/Link.h
@@ -302,42 +302,6 @@ private:
};
//------------------------------------------------------------------------
-// LinkBorderStyle
-//------------------------------------------------------------------------
-
-enum LinkBorderType {
- linkBorderSolid,
- linkBorderDashed,
- linkBorderEmbossed,
- linkBorderEngraved,
- linkBorderUnderlined
-};
-
-class LinkBorderStyle {
-public:
-
- LinkBorderStyle(LinkBorderType typeA, double widthA,
- double *dashA, int dashLengthA,
- double rA, double gA, double bA);
- ~LinkBorderStyle();
-
- LinkBorderType getType() { return type; }
- double getWidth() { return width; }
- void getDash(double **dashA, int *dashLengthA)
- { *dashA = dash; *dashLengthA = dashLength; }
- void getColor(double *rA, double *gA, double *bA)
- { *rA = r; *gA = g; *bA = b; }
-
-private:
-
- LinkBorderType type;
- double width;
- double *dash;
- int dashLength;
- double r, g, b;
-};
-
-//------------------------------------------------------------------------
// Link
//------------------------------------------------------------------------
@@ -364,14 +328,10 @@ public:
void getRect(double *xa1, double *ya1, double *xa2, double *ya2)
{ *xa1 = x1; *ya1 = y1; *xa2 = x2; *ya2 = y2; }
- // Get the border style info.
- LinkBorderStyle *getBorderStyle() { return borderStyle; }
-
private:
double x1, y1; // lower left corner
double x2, y2; // upper right corner
- LinkBorderStyle *borderStyle; // border style
LinkAction *action; // action
GBool ok; // is link valid?
};
diff --git a/Build/source/libs/xpdf/xpdf/OutputDev.cc b/Build/source/libs/xpdf/xpdf/OutputDev.cc
index cfa41619e04..8d4763b7d83 100644
--- a/Build/source/libs/xpdf/xpdf/OutputDev.cc
+++ b/Build/source/libs/xpdf/xpdf/OutputDev.cc
@@ -55,6 +55,7 @@ void OutputDev::updateAll(GfxState *state) {
updateLineCap(state);
updateMiterLimit(state);
updateLineWidth(state);
+ updateStrokeAdjust(state);
updateFillColorSpace(state);
updateFillColor(state);
updateStrokeColorSpace(state);
@@ -64,6 +65,7 @@ void OutputDev::updateAll(GfxState *state) {
updateStrokeOpacity(state);
updateFillOverprint(state);
updateStrokeOverprint(state);
+ updateTransfer(state);
updateFont(state);
}
diff --git a/Build/source/libs/xpdf/xpdf/OutputDev.h b/Build/source/libs/xpdf/xpdf/OutputDev.h
index fdb0edcbe18..27dc0dd9c16 100644
--- a/Build/source/libs/xpdf/xpdf/OutputDev.h
+++ b/Build/source/libs/xpdf/xpdf/OutputDev.h
@@ -20,14 +20,18 @@
class GString;
class GfxState;
+struct GfxColor;
class GfxColorSpace;
class GfxImageColorMap;
class GfxFunctionShading;
class GfxAxialShading;
class GfxRadialShading;
class Stream;
+class Links;
class Link;
class Catalog;
+class Page;
+class Function;
//------------------------------------------------------------------------
// OutputDev
@@ -61,6 +65,10 @@ public:
// will be reduced to a series of other drawing operations.
virtual GBool useShadedFills() { return gFalse; }
+ // Does this device use drawForm()? If this returns false,
+ // form-type XObjects will be interpreted (i.e., unrolled).
+ virtual GBool useDrawForm() { return gFalse; }
+
// Does this device use beginType3Char/endType3Char? Otherwise,
// text in Type 3 fonts will be drawn with drawChar/drawString.
virtual GBool interpretType3Chars() = 0;
@@ -73,6 +81,18 @@ public:
// Set default transform matrix.
virtual void setDefaultCTM(double *ctm);
+ // Check to see if a page slice should be displayed. If this
+ // returns false, the page display is aborted. Typically, an
+ // OutputDev will use some alternate means to display the page
+ // before returning false.
+ virtual GBool checkPageSlice(Page *page, double hDPI, double vDPI,
+ int rotate, GBool useMediaBox, GBool crop,
+ int sliceX, int sliceY, int sliceW, int sliceH,
+ GBool printing, Catalog *catalog,
+ GBool (*abortCheckCbk)(void *data) = NULL,
+ void *abortCheckCbkData = NULL)
+ { return gTrue; }
+
// Start a page.
virtual void startPage(int pageNum, GfxState *state) {}
@@ -91,9 +111,6 @@ public:
double *getDefCTM() { return defCTM; }
double *getDefICTM() { return defICTM; }
- //----- link borders
- virtual void drawLink(Link *link, Catalog *catalog) {}
-
//----- save/restore graphics state
virtual void saveState(GfxState *state) {}
virtual void restoreState(GfxState *state) {}
@@ -108,6 +125,7 @@ public:
virtual void updateLineCap(GfxState *state) {}
virtual void updateMiterLimit(GfxState *state) {}
virtual void updateLineWidth(GfxState *state) {}
+ virtual void updateStrokeAdjust(GfxState *state) {}
virtual void updateFillColorSpace(GfxState *state) {}
virtual void updateStrokeColorSpace(GfxState *state) {}
virtual void updateFillColor(GfxState *state) {}
@@ -117,6 +135,7 @@ public:
virtual void updateStrokeOpacity(GfxState *state) {}
virtual void updateFillOverprint(GfxState *state) {}
virtual void updateStrokeOverprint(GfxState *state) {}
+ virtual void updateTransfer(GfxState *state) {}
//----- update text state
virtual void updateFont(GfxState *state) {}
@@ -138,14 +157,18 @@ public:
double *mat, double *bbox,
int x0, int y0, int x1, int y1,
double xStep, double yStep) {}
- virtual void functionShadedFill(GfxState *state,
- GfxFunctionShading *shading) {}
- virtual void axialShadedFill(GfxState *state, GfxAxialShading *shading) {}
- virtual void radialShadedFill(GfxState *state, GfxRadialShading *shading) {}
+ virtual GBool functionShadedFill(GfxState *state,
+ GfxFunctionShading *shading)
+ { return gFalse; }
+ virtual GBool axialShadedFill(GfxState *state, GfxAxialShading *shading)
+ { return gFalse; }
+ virtual GBool radialShadedFill(GfxState *state, GfxRadialShading *shading)
+ { return gFalse; }
//----- path clipping
virtual void clip(GfxState *state) {}
virtual void eoClip(GfxState *state) {}
+ virtual void clipToStrokePath(GfxState *state) {}
//----- text drawing
virtual void beginStringOp(GfxState *state) {}
@@ -193,9 +216,31 @@ public:
virtual void type3D1(GfxState *state, double wx, double wy,
double llx, double lly, double urx, double ury) {}
+ //----- form XObjects
+ virtual void drawForm(Ref id) {}
+
//----- PostScript XObjects
virtual void psXObject(Stream *psStream, Stream *level1Stream) {}
+ //----- transparency groups and soft masks
+ virtual void beginTransparencyGroup(GfxState *state, double *bbox,
+ GfxColorSpace *blendingColorSpace,
+ GBool isolated, GBool knockout,
+ GBool forSoftMask) {}
+ virtual void endTransparencyGroup(GfxState *state) {}
+ virtual void paintTransparencyGroup(GfxState *state, double *bbox) {}
+ virtual void setSoftMask(GfxState *state, double *bbox, GBool alpha,
+ Function *transferFunc, GfxColor *backdropColor) {}
+ virtual void clearSoftMask(GfxState *state) {}
+
+ //----- links
+ virtual void processLink(Link *link, Catalog *catalog) {}
+
+#if 1 //~tmp: turn off anti-aliasing temporarily
+ virtual GBool getVectorAntialias() { return gFalse; }
+ virtual void setVectorAntialias(GBool vaa) {}
+#endif
+
private:
double defCTM[6]; // default coordinate transform matrix
diff --git a/Build/source/libs/xpdf/xpdf/PDFDoc.cc b/Build/source/libs/xpdf/xpdf/PDFDoc.cc
index 92863e49e0e..c559eefcfb7 100644
--- a/Build/source/libs/xpdf/xpdf/PDFDoc.cc
+++ b/Build/source/libs/xpdf/xpdf/PDFDoc.cc
@@ -61,7 +61,6 @@ PDFDoc::PDFDoc(GString *fileNameA, GString *ownerPassword,
str = NULL;
xref = NULL;
catalog = NULL;
- links = NULL;
#ifndef DISABLE_OUTLINE
outline = NULL;
#endif
@@ -119,7 +118,6 @@ PDFDoc::PDFDoc(wchar_t *fileNameA, int fileNameLen, GString *ownerPassword,
str = NULL;
xref = NULL;
catalog = NULL;
- links = NULL;
#ifndef DISABLE_OUTLINE
outline = NULL;
#endif
@@ -164,12 +162,15 @@ PDFDoc::PDFDoc(BaseStream *strA, GString *ownerPassword,
ok = gFalse;
errCode = errNone;
guiData = guiDataA;
- fileName = NULL;
+ if (strA->getFileName()) {
+ fileName = strA->getFileName()->copy();
+ } else {
+ fileName = NULL;
+ }
file = NULL;
str = strA;
xref = NULL;
catalog = NULL;
- links = NULL;
#ifndef DISABLE_OUTLINE
outline = NULL;
#endif
@@ -234,9 +235,6 @@ PDFDoc::~PDFDoc() {
if (fileName) {
delete fileName;
}
- if (links) {
- delete links;
- }
}
// Check for a PDF header on this stream. Skip past some garbage
@@ -288,7 +286,8 @@ GBool PDFDoc::checkEncryption(GString *ownerPassword, GString *userPassword) {
secHdlr->getOwnerPasswordOk(),
secHdlr->getFileKey(),
secHdlr->getFileKeyLength(),
- secHdlr->getEncVersion());
+ secHdlr->getEncVersion(),
+ secHdlr->getEncAlgorithm());
ret = gTrue;
} else {
// authorization failed
@@ -307,73 +306,51 @@ GBool PDFDoc::checkEncryption(GString *ownerPassword, GString *userPassword) {
return ret;
}
-void PDFDoc::displayPage(OutputDev *out, int page, double hDPI, double vDPI,
- int rotate, GBool useMediaBox, GBool crop,
- GBool doLinks,
+void PDFDoc::displayPage(OutputDev *out, int page,
+ double hDPI, double vDPI, int rotate,
+ GBool useMediaBox, GBool crop, GBool printing,
GBool (*abortCheckCbk)(void *data),
void *abortCheckCbkData) {
- Page *p;
-
if (globalParams->getPrintCommands()) {
printf("***** page %d *****\n", page);
}
- p = catalog->getPage(page);
- if (doLinks) {
- if (links) {
- delete links;
- }
- getLinks(p);
- p->display(out, hDPI, vDPI, rotate, useMediaBox, crop, links, catalog,
- abortCheckCbk, abortCheckCbkData);
- } else {
- p->display(out, hDPI, vDPI, rotate, useMediaBox, crop, NULL, catalog,
- abortCheckCbk, abortCheckCbkData);
- }
+ catalog->getPage(page)->display(out, hDPI, vDPI,
+ rotate, useMediaBox, crop, printing, catalog,
+ abortCheckCbk, abortCheckCbkData);
}
void PDFDoc::displayPages(OutputDev *out, int firstPage, int lastPage,
double hDPI, double vDPI, int rotate,
- GBool useMediaBox, GBool crop, GBool doLinks,
+ GBool useMediaBox, GBool crop, GBool printing,
GBool (*abortCheckCbk)(void *data),
void *abortCheckCbkData) {
int page;
for (page = firstPage; page <= lastPage; ++page) {
- displayPage(out, page, hDPI, vDPI, rotate, useMediaBox, crop, doLinks,
+ displayPage(out, page, hDPI, vDPI, rotate, useMediaBox, crop, printing,
abortCheckCbk, abortCheckCbkData);
}
}
void PDFDoc::displayPageSlice(OutputDev *out, int page,
double hDPI, double vDPI, int rotate,
- GBool useMediaBox, GBool crop, GBool doLinks,
+ GBool useMediaBox, GBool crop, GBool printing,
int sliceX, int sliceY, int sliceW, int sliceH,
GBool (*abortCheckCbk)(void *data),
void *abortCheckCbkData) {
- Page *p;
-
- p = catalog->getPage(page);
- if (doLinks) {
- if (links) {
- delete links;
- }
- getLinks(p);
- p->displaySlice(out, hDPI, vDPI, rotate, useMediaBox, crop,
- sliceX, sliceY, sliceW, sliceH,
- links, catalog, abortCheckCbk, abortCheckCbkData);
- } else {
- p->displaySlice(out, hDPI, vDPI, rotate, useMediaBox, crop,
- sliceX, sliceY, sliceW, sliceH,
- NULL, catalog, abortCheckCbk, abortCheckCbkData);
- }
+ catalog->getPage(page)->displaySlice(out, hDPI, vDPI,
+ rotate, useMediaBox, crop,
+ sliceX, sliceY, sliceW, sliceH,
+ printing, catalog,
+ abortCheckCbk, abortCheckCbkData);
}
-Links *PDFDoc::takeLinks() {
- Links *ret;
+Links *PDFDoc::getLinks(int page) {
+ return catalog->getPage(page)->getLinks(catalog);
+}
- ret = links;
- links = NULL;
- return ret;
+void PDFDoc::processLinks(OutputDev *out, int page) {
+ catalog->getPage(page)->processLinks(out, catalog);
}
GBool PDFDoc::isLinearized() {
@@ -385,7 +362,8 @@ GBool PDFDoc::isLinearized() {
obj1.initNull();
parser = new Parser(xref,
new Lexer(xref,
- str->makeSubStream(str->getStart(), gFalse, 0, &obj1)));
+ str->makeSubStream(str->getStart(), gFalse, 0, &obj1)),
+ gTrue);
parser->getObj(&obj1);
parser->getObj(&obj2);
parser->getObj(&obj3);
@@ -422,10 +400,3 @@ GBool PDFDoc::saveAs(GString *name) {
fclose(f);
return gTrue;
}
-
-void PDFDoc::getLinks(Page *page) {
- Object obj;
-
- links = new Links(page->getAnnots(&obj), catalog->getBaseURI());
- obj.free();
-}
diff --git a/Build/source/libs/xpdf/xpdf/PDFDoc.h b/Build/source/libs/xpdf/xpdf/PDFDoc.h
index a1f42c08d94..208b61efa97 100644
--- a/Build/source/libs/xpdf/xpdf/PDFDoc.h
+++ b/Build/source/libs/xpdf/xpdf/PDFDoc.h
@@ -86,23 +86,23 @@ public:
Object *getStructTreeRoot() { return catalog->getStructTreeRoot(); }
// Display a page.
- void displayPage(OutputDev *out, int page, double hDPI, double vDPI,
- int rotate, GBool useMediaBox, GBool crop,
- GBool doLinks,
+ void displayPage(OutputDev *out, int page,
+ double hDPI, double vDPI, int rotate,
+ GBool useMediaBox, GBool crop, GBool printing,
GBool (*abortCheckCbk)(void *data) = NULL,
void *abortCheckCbkData = NULL);
// Display a range of pages.
void displayPages(OutputDev *out, int firstPage, int lastPage,
double hDPI, double vDPI, int rotate,
- GBool useMediaBox, GBool crop, GBool doLinks,
+ GBool useMediaBox, GBool crop, GBool printing,
GBool (*abortCheckCbk)(void *data) = NULL,
void *abortCheckCbkData = NULL);
// Display part of a page.
void displayPageSlice(OutputDev *out, int page,
double hDPI, double vDPI, int rotate,
- GBool useMediaBox, GBool crop, GBool doLinks,
+ GBool useMediaBox, GBool crop, GBool printing,
int sliceX, int sliceY, int sliceW, int sliceH,
GBool (*abortCheckCbk)(void *data) = NULL,
void *abortCheckCbkData = NULL);
@@ -113,13 +113,16 @@ public:
// Returns the links for the current page, transferring ownership to
// the caller.
- Links *takeLinks();
+ Links *getLinks(int page);
// Find a named destination. Returns the link destination, or
// NULL if <name> is not a destination.
LinkDest *findDest(GString *name)
{ return catalog->findDest(name); }
+ // Process the links for a page.
+ void processLinks(OutputDev *out, int page);
+
#ifndef DISABLE_OUTLINE
// Return the outline object.
Outline *getOutline() { return outline; }
@@ -160,7 +163,6 @@ private:
GBool setup(GString *ownerPassword, GString *userPassword);
void checkHeader();
GBool checkEncryption(GString *ownerPassword, GString *userPassword);
- void getLinks(Page *page);
GString *fileName;
FILE *file;
@@ -169,7 +171,6 @@ private:
double pdfVersion;
XRef *xref;
Catalog *catalog;
- Links *links;
#ifndef DISABLE_OUTLINE
Outline *outline;
#endif
diff --git a/Build/source/libs/xpdf/xpdf/PSTokenizer.cc b/Build/source/libs/xpdf/xpdf/PSTokenizer.cc
index a65c3241c0f..0ad37618563 100644
--- a/Build/source/libs/xpdf/xpdf/PSTokenizer.cc
+++ b/Build/source/libs/xpdf/xpdf/PSTokenizer.cc
@@ -95,7 +95,7 @@ GBool PSTokenizer::getToken(char *buf, int size, int *length) {
} else if (c == '<') {
while ((c = lookChar()) != EOF) {
getChar();
- if (i < size - 1) {
+ if (i < size - 1 && specialChars[c] != 1) {
buf[i++] = c;
}
if (c == '>') {
diff --git a/Build/source/libs/xpdf/xpdf/Page.cc b/Build/source/libs/xpdf/xpdf/Page.cc
index 47171571cff..2a7540b06c0 100644
--- a/Build/source/libs/xpdf/xpdf/Page.cc
+++ b/Build/source/libs/xpdf/xpdf/Page.cc
@@ -2,7 +2,7 @@
//
// Page.cc
//
-// Copyright 1996-2003 Glyph & Cog, LLC
+// Copyright 1996-2007 Glyph & Cog, LLC
//
//========================================================================
@@ -26,9 +26,37 @@
#include "Annot.h"
#endif
#include "Error.h"
+#include "Catalog.h"
#include "Page.h"
//------------------------------------------------------------------------
+// PDFRectangle
+//------------------------------------------------------------------------
+
+void PDFRectangle::clipTo(PDFRectangle *rect) {
+ if (x1 < rect->x1) {
+ x1 = rect->x1;
+ } else if (x1 > rect->x2) {
+ x1 = rect->x2;
+ }
+ if (x2 < rect->x1) {
+ x2 = rect->x1;
+ } else if (x2 > rect->x2) {
+ x2 = rect->x2;
+ }
+ if (y1 < rect->y1) {
+ y1 = rect->y1;
+ } else if (y1 > rect->y2) {
+ y1 = rect->y2;
+ }
+ if (y2 < rect->y1) {
+ y2 = rect->y1;
+ } else if (y2 > rect->y2) {
+ y2 = rect->y2;
+ }
+}
+
+//------------------------------------------------------------------------
// PageAttrs
//------------------------------------------------------------------------
@@ -74,6 +102,12 @@ PageAttrs::PageAttrs(PageAttrs *attrs, Dict *dict) {
artBox = cropBox;
readBox(dict, "ArtBox", &artBox);
+ // clip all other boxes to the media box
+ cropBox.clipTo(&mediaBox);
+ bleedBox.clipTo(&mediaBox);
+ trimBox.clipTo(&mediaBox);
+ artBox.clipTo(&mediaBox);
+
// rotate
dict->lookup("Rotate", &obj1);
if (obj1.isInt()) {
@@ -213,32 +247,47 @@ Page::~Page() {
contents.free();
}
+Links *Page::getLinks(Catalog *catalog) {
+ Links *links;
+ Object obj;
+
+ links = new Links(getAnnots(&obj), catalog->getBaseURI());
+ obj.free();
+ return links;
+}
+
void Page::display(OutputDev *out, double hDPI, double vDPI,
int rotate, GBool useMediaBox, GBool crop,
- Links *links, Catalog *catalog,
+ GBool printing, Catalog *catalog,
GBool (*abortCheckCbk)(void *data),
void *abortCheckCbkData) {
displaySlice(out, hDPI, vDPI, rotate, useMediaBox, crop,
- -1, -1, -1, -1, links, catalog,
+ -1, -1, -1, -1, printing, catalog,
abortCheckCbk, abortCheckCbkData);
}
void Page::displaySlice(OutputDev *out, double hDPI, double vDPI,
int rotate, GBool useMediaBox, GBool crop,
int sliceX, int sliceY, int sliceW, int sliceH,
- Links *links, Catalog *catalog,
+ GBool printing, Catalog *catalog,
GBool (*abortCheckCbk)(void *data),
void *abortCheckCbkData) {
#ifndef PDF_PARSER_ONLY
- PDFRectangle *mediaBox, *cropBox, *baseBox;
+ PDFRectangle *mediaBox, *cropBox;
PDFRectangle box;
Gfx *gfx;
Object obj;
- Link *link;
Annots *annotList;
- double kx, ky;
+ Dict *acroForm;
int i;
+ if (!out->checkPageSlice(this, hDPI, vDPI, rotate, useMediaBox, crop,
+ sliceX, sliceY, sliceW, sliceH,
+ printing, catalog,
+ abortCheckCbk, abortCheckCbkData)) {
+ return;
+ }
+
rotate += getRotate();
if (rotate >= 360) {
rotate -= 360;
@@ -246,61 +295,12 @@ void Page::displaySlice(OutputDev *out, double hDPI, double vDPI,
rotate += 360;
}
- mediaBox = getMediaBox();
+ makeBox(hDPI, vDPI, rotate, useMediaBox, out->upsideDown(),
+ sliceX, sliceY, sliceW, sliceH, &box, &crop);
cropBox = getCropBox();
- if (sliceW >= 0 && sliceH >= 0) {
- baseBox = useMediaBox ? mediaBox : cropBox;
- kx = 72.0 / hDPI;
- ky = 72.0 / vDPI;
- if (rotate == 90) {
- if (out->upsideDown()) {
- box.x1 = baseBox->x1 + ky * sliceY;
- box.x2 = baseBox->x1 + ky * (sliceY + sliceH);
- } else {
- box.x1 = baseBox->x2 - ky * (sliceY + sliceH);
- box.x2 = baseBox->x2 - ky * sliceY;
- }
- box.y1 = baseBox->y1 + kx * sliceX;
- box.y2 = baseBox->y1 + kx * (sliceX + sliceW);
- } else if (rotate == 180) {
- box.x1 = baseBox->x2 - kx * (sliceX + sliceW);
- box.x2 = baseBox->x2 - kx * sliceX;
- if (out->upsideDown()) {
- box.y1 = baseBox->y1 + ky * sliceY;
- box.y2 = baseBox->y1 + ky * (sliceY + sliceH);
- } else {
- box.y1 = baseBox->y2 - ky * (sliceY + sliceH);
- box.y2 = baseBox->y2 - ky * sliceY;
- }
- } else if (rotate == 270) {
- if (out->upsideDown()) {
- box.x1 = baseBox->x2 - ky * (sliceY + sliceH);
- box.x2 = baseBox->x2 - ky * sliceY;
- } else {
- box.x1 = baseBox->x1 + ky * sliceY;
- box.x2 = baseBox->x1 + ky * (sliceY + sliceH);
- }
- box.y1 = baseBox->y2 - kx * (sliceX + sliceW);
- box.y2 = baseBox->y2 - kx * sliceX;
- } else {
- box.x1 = baseBox->x1 + kx * sliceX;
- box.x2 = baseBox->x1 + kx * (sliceX + sliceW);
- if (out->upsideDown()) {
- box.y1 = baseBox->y2 - ky * (sliceY + sliceH);
- box.y2 = baseBox->y2 - ky * sliceY;
- } else {
- box.y1 = baseBox->y1 + ky * sliceY;
- box.y2 = baseBox->y1 + ky * (sliceY + sliceH);
- }
- }
- } else if (useMediaBox) {
- box = *mediaBox;
- } else {
- box = *cropBox;
- crop = gFalse;
- }
if (globalParams->getPrintCommands()) {
+ mediaBox = getMediaBox();
printf("***** MediaBox = ll:%g,%g ur:%g,%g\n",
mediaBox->x1, mediaBox->y1, mediaBox->x2, mediaBox->y2);
printf("***** CropBox = ll:%g,%g ur:%g,%g\n",
@@ -319,26 +319,25 @@ void Page::displaySlice(OutputDev *out, double hDPI, double vDPI,
}
obj.free();
- // draw links
- if (links) {
- gfx->saveState();
- for (i = 0; i < links->getNumLinks(); ++i) {
- link = links->getLink(i);
- out->drawLink(link, catalog);
+ // draw annotations
+ annotList = new Annots(xref, catalog, getAnnots(&obj));
+ obj.free();
+ acroForm = catalog->getAcroForm()->isDict() ?
+ catalog->getAcroForm()->getDict() : NULL;
+ if (acroForm) {
+ if (acroForm->lookup("NeedAppearances", &obj)) {
+ if (obj.isBool() && obj.getBool()) {
+ annotList->generateAppearances(acroForm);
+ }
}
- gfx->restoreState();
- out->dump();
+ obj.free();
}
-
- // draw non-link annotations
- annotList = new Annots(xref, catalog, annots.fetch(xref, &obj));
- obj.free();
if (annotList->getNumAnnots() > 0) {
if (globalParams->getPrintCommands()) {
printf("***** Annotations\n");
}
for (i = 0; i < annotList->getNumAnnots(); ++i) {
- annotList->getAnnot(i)->draw(gfx);
+ annotList->getAnnot(i)->draw(gfx, printing);
}
out->dump();
}
@@ -348,9 +347,82 @@ void Page::displaySlice(OutputDev *out, double hDPI, double vDPI,
#endif
}
-void Page::getDefaultCTM(double *ctm, double hDPI, double vDPI,
- int rotate, GBool upsideDown) {
+void Page::makeBox(double hDPI, double vDPI, int rotate,
+ GBool useMediaBox, GBool upsideDown,
+ double sliceX, double sliceY, double sliceW, double sliceH,
+ PDFRectangle *box, GBool *crop) {
+ PDFRectangle *mediaBox, *cropBox, *baseBox;
+ double kx, ky;
+
+ mediaBox = getMediaBox();
+ cropBox = getCropBox();
+ if (sliceW >= 0 && sliceH >= 0) {
+ baseBox = useMediaBox ? mediaBox : cropBox;
+ kx = 72.0 / hDPI;
+ ky = 72.0 / vDPI;
+ if (rotate == 90) {
+ if (upsideDown) {
+ box->x1 = baseBox->x1 + ky * sliceY;
+ box->x2 = baseBox->x1 + ky * (sliceY + sliceH);
+ } else {
+ box->x1 = baseBox->x2 - ky * (sliceY + sliceH);
+ box->x2 = baseBox->x2 - ky * sliceY;
+ }
+ box->y1 = baseBox->y1 + kx * sliceX;
+ box->y2 = baseBox->y1 + kx * (sliceX + sliceW);
+ } else if (rotate == 180) {
+ box->x1 = baseBox->x2 - kx * (sliceX + sliceW);
+ box->x2 = baseBox->x2 - kx * sliceX;
+ if (upsideDown) {
+ box->y1 = baseBox->y1 + ky * sliceY;
+ box->y2 = baseBox->y1 + ky * (sliceY + sliceH);
+ } else {
+ box->y1 = baseBox->y2 - ky * (sliceY + sliceH);
+ box->y2 = baseBox->y2 - ky * sliceY;
+ }
+ } else if (rotate == 270) {
+ if (upsideDown) {
+ box->x1 = baseBox->x2 - ky * (sliceY + sliceH);
+ box->x2 = baseBox->x2 - ky * sliceY;
+ } else {
+ box->x1 = baseBox->x1 + ky * sliceY;
+ box->x2 = baseBox->x1 + ky * (sliceY + sliceH);
+ }
+ box->y1 = baseBox->y2 - kx * (sliceX + sliceW);
+ box->y2 = baseBox->y2 - kx * sliceX;
+ } else {
+ box->x1 = baseBox->x1 + kx * sliceX;
+ box->x2 = baseBox->x1 + kx * (sliceX + sliceW);
+ if (upsideDown) {
+ box->y1 = baseBox->y2 - ky * (sliceY + sliceH);
+ box->y2 = baseBox->y2 - ky * sliceY;
+ } else {
+ box->y1 = baseBox->y1 + ky * sliceY;
+ box->y2 = baseBox->y1 + ky * (sliceY + sliceH);
+ }
+ }
+ } else if (useMediaBox) {
+ *box = *mediaBox;
+ } else {
+ *box = *cropBox;
+ *crop = gFalse;
+ }
+}
+
+void Page::processLinks(OutputDev *out, Catalog *catalog) {
+ Links *links;
+ int i;
+
+ links = getLinks(catalog);
+ for (i = 0; i < links->getNumLinks(); ++i) {
+ out->processLink(links->getLink(i), catalog);
+ }
+ delete links;
+}
+
#ifndef PDF_PARSER_ONLY
+void Page::getDefaultCTM(double *ctm, double hDPI, double vDPI,
+ int rotate, GBool useMediaBox, GBool upsideDown) {
GfxState *state;
int i;
@@ -360,10 +432,12 @@ void Page::getDefaultCTM(double *ctm, double hDPI, double vDPI,
} else if (rotate < 0) {
rotate += 360;
}
- state = new GfxState(hDPI, vDPI, getMediaBox(), rotate, upsideDown);
+ state = new GfxState(hDPI, vDPI,
+ useMediaBox ? getMediaBox() : getCropBox(),
+ rotate, upsideDown);
for (i = 0; i < 6; ++i) {
ctm[i] = state->getCTM()[i];
}
delete state;
-#endif
}
+#endif
diff --git a/Build/source/libs/xpdf/xpdf/Page.h b/Build/source/libs/xpdf/xpdf/Page.h
index 36f96e1ad60..cacc0d164bf 100644
--- a/Build/source/libs/xpdf/xpdf/Page.h
+++ b/Build/source/libs/xpdf/xpdf/Page.h
@@ -33,6 +33,7 @@ public:
PDFRectangle(double x1A, double y1A, double x2A, double y2A)
{ x1 = x1A; y1 = y1A; x2 = x2A; y2 = y2A; }
GBool isValid() { return x1 != 0 || y1 != 0 || x2 != 0 || y2 != 0; }
+ void clipTo(PDFRectangle *rect);
};
//------------------------------------------------------------------------
@@ -112,6 +113,7 @@ public:
GBool isOk() { return ok; }
// Get page parameters.
+ int getNum() { return num; }
PDFRectangle *getMediaBox() { return attrs->getMediaBox(); }
PDFRectangle *getCropBox() { return attrs->getCropBox(); }
GBool isCropped() { return attrs->isCropped(); }
@@ -140,13 +142,16 @@ public:
// Get annotations array.
Object *getAnnots(Object *obj) { return annots.fetch(xref, obj); }
+ // Return a list of links.
+ Links *getLinks(Catalog *catalog);
+
// Get contents.
Object *getContents(Object *obj) { return contents.fetch(xref, obj); }
// Display a page.
void display(OutputDev *out, double hDPI, double vDPI,
int rotate, GBool useMediaBox, GBool crop,
- Links *links, Catalog *catalog,
+ GBool printing, Catalog *catalog,
GBool (*abortCheckCbk)(void *data) = NULL,
void *abortCheckCbkData = NULL);
@@ -154,13 +159,22 @@ public:
void displaySlice(OutputDev *out, double hDPI, double vDPI,
int rotate, GBool useMediaBox, GBool crop,
int sliceX, int sliceY, int sliceW, int sliceH,
- Links *links, Catalog *catalog,
+ GBool printing, Catalog *catalog,
GBool (*abortCheckCbk)(void *data) = NULL,
void *abortCheckCbkData = NULL);
+ void makeBox(double hDPI, double vDPI, int rotate,
+ GBool useMediaBox, GBool upsideDown,
+ double sliceX, double sliceY, double sliceW, double sliceH,
+ PDFRectangle *box, GBool *crop);
+
+ void processLinks(OutputDev *out, Catalog *catalog);
+
+#ifndef PDF_PARSER_ONLY
// Get the page's default CTM.
void getDefaultCTM(double *ctm, double hDPI, double vDPI,
- int rotate, GBool upsideDown);
+ int rotate, GBool useMediaBox, GBool upsideDown);
+#endif
private:
diff --git a/Build/source/libs/xpdf/xpdf/Parser.cc b/Build/source/libs/xpdf/xpdf/Parser.cc
index af7c933114a..c1fc715219f 100644
--- a/Build/source/libs/xpdf/xpdf/Parser.cc
+++ b/Build/source/libs/xpdf/xpdf/Parser.cc
@@ -16,15 +16,16 @@
#include "Object.h"
#include "Array.h"
#include "Dict.h"
+#include "Decrypt.h"
#include "Parser.h"
#include "XRef.h"
#include "Error.h"
-#include "Decrypt.h"
-Parser::Parser(XRef *xrefA, Lexer *lexerA) {
+Parser::Parser(XRef *xrefA, Lexer *lexerA, GBool allowStreamsA) {
xref = xrefA;
lexer = lexerA;
inlineImg = 0;
+ allowStreams = allowStreamsA;
lexer->getObj(&buf1);
lexer->getObj(&buf2);
}
@@ -35,17 +36,16 @@ Parser::~Parser() {
delete lexer;
}
-Object *Parser::getObj(Object *obj,
- Guchar *fileKey, int keyLength,
+Object *Parser::getObj(Object *obj, Guchar *fileKey,
+ CryptAlgorithm encAlgorithm, int keyLength,
int objNum, int objGen) {
char *key;
Stream *str;
Object obj2;
int num;
- Decrypt *decrypt;
- GString *s;
- char *p;
- int i;
+ DecryptStream *decrypt;
+ GString *s, *s2;
+ int c;
// refill buffer after inline image data
if (inlineImg == 2) {
@@ -61,7 +61,8 @@ Object *Parser::getObj(Object *obj,
shift();
obj->initArray(xref);
while (!buf1.isCmd("]") && !buf1.isEOF())
- obj->arrayAdd(getObj(&obj2, fileKey, keyLength, objNum, objGen));
+ obj->arrayAdd(getObj(&obj2, fileKey, encAlgorithm, keyLength,
+ objNum, objGen));
if (buf1.isEOF())
error(getPos(), "End of file inside array");
shift();
@@ -81,18 +82,18 @@ Object *Parser::getObj(Object *obj,
gfree(key);
break;
}
- obj->dictAdd(key, getObj(&obj2, fileKey, keyLength, objNum, objGen));
+ obj->dictAdd(key, getObj(&obj2, fileKey, encAlgorithm, keyLength,
+ objNum, objGen));
}
}
if (buf1.isEOF())
error(getPos(), "End of file inside dictionary");
- if (buf2.isCmd("stream")) {
- if ((str = makeStream(obj))) {
+ // stream objects are not allowed inside content streams or
+ // object streams
+ if (allowStreams && buf2.isCmd("stream")) {
+ if ((str = makeStream(obj, fileKey, encAlgorithm, keyLength,
+ objNum, objGen))) {
obj->initStream(str);
- if (fileKey) {
- str->getBaseStream()->doDecryption(fileKey, keyLength,
- objNum, objGen);
- }
} else {
obj->free();
obj->initError();
@@ -115,15 +116,19 @@ Object *Parser::getObj(Object *obj,
// string
} else if (buf1.isString() && fileKey) {
- buf1.copy(obj);
- s = obj->getString();
- decrypt = new Decrypt(fileKey, keyLength, objNum, objGen);
- for (i = 0, p = obj->getString()->getCString();
- i < s->getLength();
- ++i, ++p) {
- *p = decrypt->decryptByte(*p);
+ s = buf1.getString();
+ s2 = new GString();
+ obj2.initNull();
+ decrypt = new DecryptStream(new MemStream(s->getCString(), 0,
+ s->getLength(), &obj2),
+ fileKey, encAlgorithm, keyLength,
+ objNum, objGen);
+ decrypt->reset();
+ while ((c = decrypt->getChar()) != EOF) {
+ s2->append((char)c);
}
delete decrypt;
+ obj->initString(s2);
shift();
// simple object
@@ -135,7 +140,9 @@ Object *Parser::getObj(Object *obj,
return obj;
}
-Stream *Parser::makeStream(Object *dict) {
+Stream *Parser::makeStream(Object *dict, Guchar *fileKey,
+ CryptAlgorithm encAlgorithm, int keyLength,
+ int objNum, int objGen) {
Object obj;
BaseStream *baseStr;
Stream *str;
@@ -186,6 +193,12 @@ Stream *Parser::makeStream(Object *dict) {
// make base stream
str = baseStr->makeSubStream(pos, gTrue, length, dict);
+ // handle decryption
+ if (fileKey) {
+ str = new DecryptStream(str, fileKey, encAlgorithm, keyLength,
+ objNum, objGen);
+ }
+
// get filters
str = str->addFilters(dict);
diff --git a/Build/source/libs/xpdf/xpdf/Parser.h b/Build/source/libs/xpdf/xpdf/Parser.h
index b583baf6398..a109558b026 100644
--- a/Build/source/libs/xpdf/xpdf/Parser.h
+++ b/Build/source/libs/xpdf/xpdf/Parser.h
@@ -25,14 +25,14 @@ class Parser {
public:
// Constructor.
- Parser(XRef *xrefA, Lexer *lexerA);
+ Parser(XRef *xrefA, Lexer *lexerA, GBool allowStreamsA);
// Destructor.
~Parser();
// Get the next object from the input stream.
- Object *getObj(Object *obj,
- Guchar *fileKey = NULL, int keyLength = 0,
+ Object *getObj(Object *obj, Guchar *fileKey = NULL,
+ CryptAlgorithm encAlgorithm = cryptRC4, int keyLength = 0,
int objNum = 0, int objGen = 0);
// Get stream.
@@ -45,10 +45,13 @@ private:
XRef *xref; // the xref table for this PDF file
Lexer *lexer; // input stream
+ GBool allowStreams; // parse stream objects?
Object buf1, buf2; // next two tokens
int inlineImg; // set when inline image data is encountered
- Stream *makeStream(Object *dict);
+ Stream *makeStream(Object *dict, Guchar *fileKey,
+ CryptAlgorithm encAlgorithm, int keyLength,
+ int objNum, int objGen);
void shift();
};
diff --git a/Build/source/libs/xpdf/xpdf/SecurityHandler.cc b/Build/source/libs/xpdf/xpdf/SecurityHandler.cc
index 40e9f59fb15..ea0f9341dd3 100644
--- a/Build/source/libs/xpdf/xpdf/SecurityHandler.cc
+++ b/Build/source/libs/xpdf/xpdf/SecurityHandler.cc
@@ -153,6 +153,7 @@ StandardSecurityHandler::StandardSecurityHandler(PDFDoc *docA,
permObj.isInt()) {
encVersion = versionObj.getInt();
encRevision = revisionObj.getInt();
+ encAlgorithm = cryptRC4;
// revision 2 forces a 40-bit key - some buggy PDF generators
// set the Length value incorrectly
if (encRevision == 2 || !lengthObj.isInt()) {
@@ -172,7 +173,8 @@ StandardSecurityHandler::StandardSecurityHandler(PDFDoc *docA,
!strcmp(streamFilterObj.getName(), stringFilterObj.getName())) {
if (cryptFiltersObj.dictLookup(streamFilterObj.getName(),
&cryptFilterObj)->isDict()) {
- if (cryptFilterObj.dictLookup("CFM", &cfmObj)->isName("V2")) {
+ cryptFilterObj.dictLookup("CFM", &cfmObj);
+ if (cfmObj.isName("V2")) {
encVersion = 2;
encRevision = 3;
if (cryptFilterObj.dictLookup("Length", &cfLengthObj)->isInt()) {
@@ -180,6 +182,15 @@ StandardSecurityHandler::StandardSecurityHandler(PDFDoc *docA,
fileKeyLength = cfLengthObj.getInt();
}
cfLengthObj.free();
+ } else if (cfmObj.isName("AESV2")) {
+ encVersion = 2;
+ encRevision = 3;
+ encAlgorithm = cryptAES;
+ if (cryptFilterObj.dictLookup("Length", &cfLengthObj)->isInt()) {
+ //~ according to the spec, this should be cfLengthObj / 8
+ fileKeyLength = cfLengthObj.getInt();
+ }
+ cfLengthObj.free();
}
cfmObj.free();
}
@@ -312,6 +323,7 @@ ExternalSecurityHandler::ExternalSecurityHandler(PDFDoc *docA,
{
encryptDictA->copy(&encryptDict);
xsh = xshA;
+ encAlgorithm = cryptRC4; //~ this should be obtained via getKey
ok = gFalse;
if (!(*xsh->newDoc)(xsh->handlerData, (XpdfDoc)docA,
diff --git a/Build/source/libs/xpdf/xpdf/SecurityHandler.h b/Build/source/libs/xpdf/xpdf/SecurityHandler.h
index 127acb7695e..a27868c249d 100644
--- a/Build/source/libs/xpdf/xpdf/SecurityHandler.h
+++ b/Build/source/libs/xpdf/xpdf/SecurityHandler.h
@@ -74,6 +74,7 @@ public:
virtual Guchar *getFileKey() = 0;
virtual int getFileKeyLength() = 0;
virtual int getEncVersion() = 0;
+ virtual CryptAlgorithm getEncAlgorithm() = 0;
protected:
@@ -100,6 +101,7 @@ public:
virtual Guchar *getFileKey() { return fileKey; }
virtual int getFileKeyLength() { return fileKeyLength; }
virtual int getEncVersion() { return encVersion; }
+ virtual CryptAlgorithm getEncAlgorithm() { return encAlgorithm; }
private:
@@ -109,6 +111,7 @@ private:
int fileKeyLength;
int encVersion;
int encRevision;
+ CryptAlgorithm encAlgorithm;
GBool encryptMetadata;
GString *ownerKey, *userKey;
@@ -138,6 +141,7 @@ public:
virtual Guchar *getFileKey() { return fileKey; }
virtual int getFileKeyLength() { return fileKeyLength; }
virtual int getEncVersion() { return encVersion; }
+ virtual CryptAlgorithm getEncAlgorithm() { return encAlgorithm; }
private:
@@ -148,6 +152,7 @@ private:
Guchar fileKey[16];
int fileKeyLength;
int encVersion;
+ CryptAlgorithm encAlgorithm;
GBool ok;
};
#endif // ENABLE_PLUGINS
diff --git a/Build/source/libs/xpdf/xpdf/Stream.cc b/Build/source/libs/xpdf/xpdf/Stream.cc
index 5fa7791c436..68abafa7b8d 100644
--- a/Build/source/libs/xpdf/xpdf/Stream.cc
+++ b/Build/source/libs/xpdf/xpdf/Stream.cc
@@ -27,7 +27,6 @@
#include "Error.h"
#include "Object.h"
#include "Lexer.h"
-#include "Decrypt.h"
#include "GfxState.h"
#include "Stream.h"
#include "JBIG2Stream.h"
@@ -142,6 +141,7 @@ Stream *Stream::makeFilter(char *name, Stream *str, Object *params) {
int encoding;
GBool endOfLine, byteAlign, endOfBlock, black;
int columns, rows;
+ int colorXform;
Object globals, obj;
if (!strcmp(name, "ASCIIHexDecode") || !strcmp(name, "AHx")) {
@@ -227,7 +227,14 @@ Stream *Stream::makeFilter(char *name, Stream *str, Object *params) {
str = new CCITTFaxStream(str, encoding, endOfLine, byteAlign,
columns, rows, endOfBlock, black);
} else if (!strcmp(name, "DCTDecode") || !strcmp(name, "DCT")) {
- str = new DCTStream(str);
+ colorXform = -1;
+ if (params->isDict()) {
+ if (params->dictLookup("ColorTransform", &obj)->isInt()) {
+ colorXform = obj.getInt();
+ }
+ obj.free();
+ }
+ str = new DCTStream(str, colorXform);
} else if (!strcmp(name, "FlateDecode") || !strcmp(name, "Fl")) {
pred = 1;
columns = 1;
@@ -273,18 +280,10 @@ Stream *Stream::makeFilter(char *name, Stream *str, Object *params) {
BaseStream::BaseStream(Object *dictA) {
dict = *dictA;
- decrypt = NULL;
}
BaseStream::~BaseStream() {
dict.free();
- if (decrypt)
- delete decrypt;
-}
-
-void BaseStream::doDecryption(Guchar *fileKey, int keyLength,
- int objNum, int objGen) {
- decrypt = new Decrypt(fileKey, keyLength, objNum, objGen);
}
//------------------------------------------------------------------------
@@ -402,8 +401,6 @@ void ImageStream::skipLine() {
StreamPredictor::StreamPredictor(Stream *strA, int predictorA,
int widthA, int nCompsA, int nBitsA) {
- int totalBits;
-
str = strA;
predictor = predictorA;
width = widthA;
@@ -413,7 +410,6 @@ StreamPredictor::StreamPredictor(Stream *strA, int predictorA,
ok = gFalse;
nVals = width * nComps;
- totalBits = nVals * nBits;
if (width <= 0 || nComps <= 0 || nBits <= 0 ||
nComps >= INT_MAX / nBits ||
width >= INT_MAX / nComps / nBits ||
@@ -421,8 +417,8 @@ StreamPredictor::StreamPredictor(Stream *strA, int predictorA,
return;
}
pixBytes = (nComps * nBits + 7) >> 3;
- rowBytes = ((totalBits + 7) >> 3) + pixBytes;
- if (rowBytes < 0) {
+ rowBytes = ((nVals * nBits + 7) >> 3) + pixBytes;
+ if (rowBytes <= 0) {
return;
}
predLine = (Guchar *)gmalloc(rowBytes);
@@ -550,8 +546,8 @@ GBool StreamPredictor::getNextLine() {
inBuf = (inBuf << 8) | (predLine[j++] & 0xff);
inBits += 8;
}
- upLeftBuf[kk] = (upLeftBuf[kk] +
- (inBuf >> (inBits - nBits))) & bitMask;
+ upLeftBuf[kk] = (Guchar)((upLeftBuf[kk] +
+ (inBuf >> (inBits - nBits))) & bitMask);
inBits -= nBits;
outBuf = (outBuf << nBits) | upLeftBuf[kk];
outBits += nBits;
@@ -614,8 +610,6 @@ void FileStream::reset() {
saved = gTrue;
bufPtr = bufEnd = buf;
bufPos = start;
- if (decrypt)
- decrypt->reset();
}
void FileStream::close() {
@@ -633,7 +627,6 @@ void FileStream::close() {
GBool FileStream::fillBuf() {
int n;
- char *p;
bufPos += bufEnd - buf;
bufPtr = bufEnd = buf;
@@ -650,11 +643,6 @@ GBool FileStream::fillBuf() {
if (bufPtr >= bufEnd) {
return gFalse;
}
- if (decrypt) {
- for (p = buf; p < bufEnd; ++p) {
- *p = (char)decrypt->decryptByte((Guchar)*p);
- }
- }
return gTrue;
}
@@ -743,9 +731,6 @@ Stream *MemStream::makeSubStream(Guint startA, GBool limited,
void MemStream::reset() {
bufPtr = buf + start;
- if (decrypt) {
- decrypt->reset();
- }
}
void MemStream::close() {
@@ -773,25 +758,6 @@ void MemStream::moveStart(int delta) {
bufPtr = buf + start;
}
-void MemStream::doDecryption(Guchar *fileKey, int keyLength,
- int objNum, int objGen) {
- char *newBuf;
- char *p, *q;
-
- this->BaseStream::doDecryption(fileKey, keyLength, objNum, objGen);
- if (decrypt) {
- newBuf = (char *)gmalloc(length);
- for (p = buf + start, q = newBuf; p < bufEnd; ++p, ++q) {
- *q = (char)decrypt->decryptByte((Guchar)*p);
- }
- bufEnd = newBuf + length;
- bufPtr = newBuf + (bufPtr - (buf + start));
- start = 0;
- buf = newBuf;
- needFree = gTrue;
- }
-}
-
//------------------------------------------------------------------------
// EmbedStream
//------------------------------------------------------------------------
@@ -1286,8 +1252,8 @@ CCITTFaxStream::CCITTFaxStream(Stream *strA, int encodingA, GBool endOfLineA,
rows = rowsA;
endOfBlock = endOfBlockA;
black = blackA;
- refLine = (short *)gmallocn(columns + 4, sizeof(short));
- codingLine = (short *)gmallocn(columns + 3, sizeof(short));
+ refLine = (short *)gmallocn(columns + 3, sizeof(short));
+ codingLine = (short *)gmallocn(columns + 2, sizeof(short));
eof = gFalse;
row = 0;
@@ -1315,7 +1281,7 @@ void CCITTFaxStream::reset() {
nextLine2D = encoding < 0;
inputBits = 0;
codingLine[0] = 0;
- codingLine[1] = refLine[2] = columns;
+ codingLine[1] = columns;
a0 = 1;
buf = EOF;
@@ -1351,8 +1317,27 @@ int CCITTFaxStream::lookChar() {
// 2-D encoding
if (nextLine2D) {
- for (i = 0; codingLine[i] < columns; ++i)
+ // state:
+ // a0New = current position in coding line (0 <= a0New <= columns)
+ // codingLine[a0] = last change in coding line
+ // (black-to-white if a0 is even,
+ // white-to-black if a0 is odd)
+ // refLine[b1] = next change in reference line of opposite color
+ // to a0
+ // invariants:
+ // 0 <= codingLine[a0] <= a0New
+ // <= refLine[b1] <= refLine[b1+1] <= columns
+ // 0 <= a0 <= columns+1
+ // refLine[0] = 0
+ // refLine[n] = refLine[n+1] = columns
+ // -- for some 1 <= n <= columns+1
+ // end condition:
+ // 0 = codingLine[0] <= codingLine[1] < codingLine[2] < ...
+ // < codingLine[n-1] < codingLine[n] = columns
+ // -- where 1 <= n <= columns+1
+ for (i = 0; codingLine[i] < columns; ++i) {
refLine[i] = codingLine[i];
+ }
refLine[i] = refLine[i + 1] = columns;
b1 = 1;
a0New = codingLine[a0 = 0] = 0;
@@ -1384,68 +1369,93 @@ int CCITTFaxStream::lookChar() {
} while (code3 >= 64);
}
if (code1 > 0 || code2 > 0) {
- codingLine[a0 + 1] = a0New + code1;
+ if (a0New + code1 <= columns) {
+ codingLine[a0 + 1] = a0New + code1;
+ } else {
+ codingLine[a0 + 1] = columns;
+ }
++a0;
- a0New = codingLine[a0 + 1] = codingLine[a0] + code2;
+ if (codingLine[a0] + code2 <= columns) {
+ codingLine[a0 + 1] = codingLine[a0] + code2;
+ } else {
+ codingLine[a0 + 1] = columns;
+ }
++a0;
- while (refLine[b1] <= codingLine[a0] && refLine[b1] < columns)
+ a0New = codingLine[a0];
+ while (refLine[b1] <= a0New && refLine[b1] < columns) {
b1 += 2;
+ }
}
break;
case twoDimVert0:
- a0New = codingLine[++a0] = refLine[b1];
if (refLine[b1] < columns) {
+ a0New = codingLine[++a0] = refLine[b1];
++b1;
- while (refLine[b1] <= codingLine[a0] && refLine[b1] < columns)
+ while (refLine[b1] <= a0New && refLine[b1] < columns) {
b1 += 2;
+ }
+ } else {
+ a0New = codingLine[++a0] = columns;
}
break;
case twoDimVertR1:
- a0New = codingLine[++a0] = refLine[b1] + 1;
- if (refLine[b1] < columns) {
+ if (refLine[b1] + 1 < columns) {
+ a0New = codingLine[++a0] = refLine[b1] + 1;
++b1;
- while (refLine[b1] <= codingLine[a0] && refLine[b1] < columns)
+ while (refLine[b1] <= a0New && refLine[b1] < columns) {
b1 += 2;
+ }
+ } else {
+ a0New = codingLine[++a0] = columns;
}
break;
case twoDimVertL1:
- if (a0 == 0 || refLine[b1] - 1 > a0New) {
+ if (refLine[b1] - 1 > a0New || (a0 == 0 && refLine[b1] == 1)) {
a0New = codingLine[++a0] = refLine[b1] - 1;
--b1;
- while (refLine[b1] <= codingLine[a0] && refLine[b1] < columns)
+ while (refLine[b1] <= a0New && refLine[b1] < columns) {
b1 += 2;
+ }
}
break;
case twoDimVertR2:
- a0New = codingLine[++a0] = refLine[b1] + 2;
- if (refLine[b1] < columns) {
+ if (refLine[b1] + 2 < columns) {
+ a0New = codingLine[++a0] = refLine[b1] + 2;
++b1;
- while (refLine[b1] <= codingLine[a0] && refLine[b1] < columns)
+ while (refLine[b1] <= a0New && refLine[b1] < columns) {
b1 += 2;
+ }
+ } else {
+ a0New = codingLine[++a0] = columns;
}
break;
case twoDimVertL2:
- if (a0 == 0 || refLine[b1] - 2 > a0New) {
+ if (refLine[b1] - 2 > a0New || (a0 == 0 && refLine[b1] == 2)) {
a0New = codingLine[++a0] = refLine[b1] - 2;
--b1;
- while (refLine[b1] <= codingLine[a0] && refLine[b1] < columns)
+ while (refLine[b1] <= a0New && refLine[b1] < columns) {
b1 += 2;
+ }
}
break;
case twoDimVertR3:
- a0New = codingLine[++a0] = refLine[b1] + 3;
- if (refLine[b1] < columns) {
+ if (refLine[b1] + 3 < columns) {
+ a0New = codingLine[++a0] = refLine[b1] + 3;
++b1;
- while (refLine[b1] <= codingLine[a0] && refLine[b1] < columns)
+ while (refLine[b1] <= a0New && refLine[b1] < columns) {
b1 += 2;
+ }
+ } else {
+ a0New = codingLine[++a0] = columns;
}
break;
case twoDimVertL3:
- if (a0 == 0 || refLine[b1] - 3 > a0New) {
+ if (refLine[b1] - 3 > a0New || (a0 == 0 && refLine[b1] == 3)) {
a0New = codingLine[++a0] = refLine[b1] - 3;
--b1;
- while (refLine[b1] <= codingLine[a0] && refLine[b1] < columns)
+ while (refLine[b1] <= a0New && refLine[b1] < columns) {
b1 += 2;
+ }
}
break;
case EOF:
@@ -1469,16 +1479,18 @@ int CCITTFaxStream::lookChar() {
} while (code3 >= 64);
codingLine[a0+1] = codingLine[a0] + code1;
++a0;
- if (codingLine[a0] >= columns)
+ if (codingLine[a0] >= columns) {
break;
+ }
code2 = 0;
do {
code2 += code3 = getBlackCode();
} while (code3 >= 64);
codingLine[a0+1] = codingLine[a0] + code2;
++a0;
- if (codingLine[a0] >= columns)
+ if (codingLine[a0] >= columns) {
break;
+ }
}
}
@@ -1859,10 +1871,11 @@ static int dctZigZag[64] = {
63
};
-DCTStream::DCTStream(Stream *strA):
+DCTStream::DCTStream(Stream *strA, GBool colorXformA):
FilterStream(strA) {
int i, j;
+ colorXform = colorXformA;
progressive = interleaved = gFalse;
width = height = 0;
mcuWidth = mcuHeight = 0;
@@ -1888,20 +1901,8 @@ DCTStream::DCTStream(Stream *strA):
}
DCTStream::~DCTStream() {
- int i, j;
-
+ close();
delete str;
- if (progressive || !interleaved) {
- for (i = 0; i < numComps; ++i) {
- gfree(frameBuf[i]);
- }
- } else {
- for (i = 0; i < numComps; ++i) {
- for (j = 0; j < mcuHeight; ++j) {
- gfree(rowBuf[i][j]);
- }
- }
- }
}
void DCTStream::reset() {
@@ -1915,7 +1916,6 @@ void DCTStream::reset() {
numQuantTables = 0;
numDCHuffTables = 0;
numACHuffTables = 0;
- colorXform = 0;
gotJFIFMarker = gFalse;
gotAdobeMarker = gFalse;
restartInterval = 0;
@@ -1943,14 +1943,18 @@ void DCTStream::reset() {
mcuHeight *= 8;
// figure out color transform
- if (!gotAdobeMarker && numComps == 3) {
- if (gotJFIFMarker) {
- colorXform = 1;
- } else if (compInfo[0].id == 82 && compInfo[1].id == 71 &&
- compInfo[2].id == 66) { // ASCII "RGB"
- colorXform = 0;
+ if (colorXform == -1) {
+ if (numComps == 3) {
+ if (gotJFIFMarker) {
+ colorXform = 1;
+ } else if (compInfo[0].id == 82 && compInfo[1].id == 71 &&
+ compInfo[2].id == 66) { // ASCII "RGB"
+ colorXform = 0;
+ } else {
+ colorXform = 1;
+ }
} else {
- colorXform = 1;
+ colorXform = 0;
}
}
@@ -2000,6 +2004,20 @@ void DCTStream::reset() {
}
}
+void DCTStream::close() {
+ int i, j;
+
+ for (i = 0; i < 4; ++i) {
+ for (j = 0; j < 32; ++j) {
+ gfree(rowBuf[i][j]);
+ rowBuf[i][j] = NULL;
+ }
+ gfree(frameBuf[i]);
+ frameBuf[i] = NULL;
+ }
+ FilterStream::close();
+}
+
int DCTStream::getChar() {
int c;
@@ -2924,11 +2942,8 @@ GBool DCTStream::readBaselineSOF() {
width = read16();
numComps = str->getChar();
if (numComps <= 0 || numComps > 4) {
- error(getPos(), "Bad number of components in DCT stream", prec);
- return gFalse;
- }
- if (numComps <= 0 || numComps > 4) {
- error(getPos(), "Bad number of components in DCT stream", prec);
+ error(getPos(), "Bad number of components in DCT stream");
+ numComps = 0;
return gFalse;
}
if (prec != 8) {
@@ -2962,11 +2977,6 @@ GBool DCTStream::readProgressiveSOF() {
numComps = 0;
return gFalse;
}
- if (numComps <= 0 || numComps > 4) {
- error(getPos(), "Bad number of components in DCT stream");
- numComps = 0;
- return gFalse;
- }
if (prec != 8) {
error(getPos(), "Bad DCT precision %d", prec);
return gFalse;
@@ -3884,6 +3894,7 @@ FlateStream::FlateStream(Stream *strA, int predictor, int columns,
}
litCodeTab.codes = NULL;
distCodeTab.codes = NULL;
+ memset(buf, 0, flateWindow);
}
FlateStream::~FlateStream() {
@@ -4444,33 +4455,61 @@ void ASCII85Encoder::reset() {
GBool ASCII85Encoder::fillBuf() {
Gulong t;
char buf1[5];
- int c;
+ int c0, c1, c2, c3;
int n, i;
- if (eof)
+ if (eof) {
return gFalse;
- t = 0;
- for (n = 0; n < 4; ++n) {
- if ((c = str->getChar()) == EOF)
- break;
- t = (t << 8) + c;
}
+ c0 = str->getChar();
+ c1 = str->getChar();
+ c2 = str->getChar();
+ c3 = str->getChar();
bufPtr = bufEnd = buf;
- if (n > 0) {
- if (n == 4 && t == 0) {
+ if (c3 == EOF) {
+ if (c0 == EOF) {
+ n = 0;
+ t = 0;
+ } else {
+ if (c1 == EOF) {
+ n = 1;
+ t = c0 << 24;
+ } else if (c2 == EOF) {
+ n = 2;
+ t = (c0 << 24) | (c1 << 16);
+ } else {
+ n = 3;
+ t = (c0 << 24) | (c1 << 16) | (c2 << 8);
+ }
+ for (i = 4; i >= 0; --i) {
+ buf1[i] = (char)(t % 85 + 0x21);
+ t /= 85;
+ }
+ for (i = 0; i <= n; ++i) {
+ *bufEnd++ = buf1[i];
+ if (++lineLen == 65) {
+ *bufEnd++ = '\n';
+ lineLen = 0;
+ }
+ }
+ }
+ *bufEnd++ = '~';
+ *bufEnd++ = '>';
+ eof = gTrue;
+ } else {
+ t = (c0 << 24) | (c1 << 16) | (c2 << 8) | c3;
+ if (t == 0) {
*bufEnd++ = 'z';
if (++lineLen == 65) {
*bufEnd++ = '\n';
lineLen = 0;
}
} else {
- if (n < 4)
- t <<= 8 * (4 - n);
for (i = 4; i >= 0; --i) {
buf1[i] = (char)(t % 85 + 0x21);
t /= 85;
}
- for (i = 0; i <= n; ++i) {
+ for (i = 0; i <= 4; ++i) {
*bufEnd++ = buf1[i];
if (++lineLen == 65) {
*bufEnd++ = '\n';
@@ -4479,12 +4518,7 @@ GBool ASCII85Encoder::fillBuf() {
}
}
}
- if (n < 4) {
- *bufEnd++ = '~';
- *bufEnd++ = '>';
- eof = gTrue;
- }
- return bufPtr < bufEnd;
+ return gTrue;
}
//------------------------------------------------------------------------
diff --git a/Build/source/libs/xpdf/xpdf/Stream.h b/Build/source/libs/xpdf/xpdf/Stream.h
index e1e7bae4282..85a84691bd9 100644
--- a/Build/source/libs/xpdf/xpdf/Stream.h
+++ b/Build/source/libs/xpdf/xpdf/Stream.h
@@ -19,7 +19,6 @@
#include "gtypes.h"
#include "Object.h"
-class Decrypt;
class BaseStream;
//------------------------------------------------------------------------
@@ -46,6 +45,15 @@ enum StreamColorSpaceMode {
};
//------------------------------------------------------------------------
+
+// This is in Stream.h instead of Decrypt.h to avoid really annoying
+// include file dependency loops.
+enum CryptAlgorithm {
+ cryptRC4,
+ cryptAES
+};
+
+//------------------------------------------------------------------------
// Stream (base class)
//------------------------------------------------------------------------
@@ -101,6 +109,10 @@ public:
// Get the BaseStream of this stream.
virtual BaseStream *getBaseStream() = 0;
+ // Get the stream after the last decoder (this may be a BaseStream
+ // or a DecryptStream).
+ virtual Stream *getUndecodedStream() = 0;
+
// Get the dictionary associated with this stream.
virtual Dict *getDict() = 0;
@@ -111,6 +123,9 @@ public:
virtual void getImageParams(int *bitsPerComponent,
StreamColorSpaceMode *csMode) {}
+ // Return the next stream in the "stack".
+ virtual Stream *getNextStream() { return NULL; }
+
// Add filters to this stream according to the parameters in <dict>.
// Returns the new stream.
Stream *addFilters(Object *dict);
@@ -138,20 +153,14 @@ public:
virtual void setPos(Guint pos, int dir = 0) = 0;
virtual GBool isBinary(GBool last = gTrue) { return last; }
virtual BaseStream *getBaseStream() { return this; }
+ virtual Stream *getUndecodedStream() { return this; }
virtual Dict *getDict() { return dict.getDict(); }
+ virtual GString *getFileName() { return NULL; }
// Get/set position of first byte of stream within the file.
virtual Guint getStart() = 0;
virtual void moveStart(int delta) = 0;
- // Set decryption for this stream.
- virtual void doDecryption(Guchar *fileKey, int keyLength,
- int objNum, int objGen);
-
-protected:
-
- Decrypt *decrypt;
-
private:
Object dict;
@@ -172,7 +181,9 @@ public:
virtual int getPos() { return str->getPos(); }
virtual void setPos(Guint pos, int dir = 0);
virtual BaseStream *getBaseStream() { return str->getBaseStream(); }
+ virtual Stream *getUndecodedStream() { return str->getUndecodedStream(); }
virtual Dict *getDict() { return str->getDict(); }
+ virtual Stream *getNextStream() { return str; }
protected:
@@ -318,8 +329,6 @@ public:
virtual void setPos(Guint pos, int dir = 0);
virtual Guint getStart() { return start; }
virtual void moveStart(int delta);
- virtual void doDecryption(Guchar *fileKey, int keyLength,
- int objNum, int objGen);
private:
@@ -530,7 +539,7 @@ private:
short getWhiteCode();
short getBlackCode();
short lookBits(int n);
- void eatBits(int n) { inputBits -= n; }
+ void eatBits(int n) { if ((inputBits -= n) < 0) inputBits = 0; }
};
//------------------------------------------------------------------------
@@ -566,10 +575,11 @@ struct DCTHuffTable {
class DCTStream: public FilterStream {
public:
- DCTStream(Stream *strA);
+ DCTStream(Stream *strA, int colorXformA);
virtual ~DCTStream();
virtual StreamKind getKind() { return strDCT; }
virtual void reset();
+ virtual void close();
virtual int getChar();
virtual int lookChar();
virtual GString *getPSFilter(int psLevel, char *indent);
@@ -586,7 +596,9 @@ private:
DCTCompInfo compInfo[4]; // info for each component
DCTScanInfo scanInfo; // info for the current scan
int numComps; // number of components in image
- int colorXform; // need YCbCr-to-RGB transform?
+ int colorXform; // color transform: -1 = unspecified
+ // 0 = none
+ // 1 = YUV/YUVK -> RGB/CMYK
GBool gotJFIFMarker; // set if APP0 JFIF marker was present
GBool gotAdobeMarker; // set if APP14 Adobe marker was present
int restartInterval; // restart interval, in MCUs
diff --git a/Build/source/libs/xpdf/xpdf/XRef.cc b/Build/source/libs/xpdf/xpdf/XRef.cc
index c5a6aca8a6f..367f99b2fe2 100644
--- a/Build/source/libs/xpdf/xpdf/XRef.cc
+++ b/Build/source/libs/xpdf/xpdf/XRef.cc
@@ -90,7 +90,7 @@ ObjectStream::ObjectStream(XRef *xref, int objStrNumA) {
objStr.streamReset();
obj1.initNull();
str = new EmbedStream(objStr.getStream(), &obj1, gTrue, first);
- parser = new Parser(xref, new Lexer(xref, str));
+ parser = new Parser(xref, new Lexer(xref, str), gFalse);
for (i = 0; i < nObjects; ++i) {
parser->getObj(&obj1);
parser->getObj(&obj2);
@@ -131,7 +131,7 @@ ObjectStream::ObjectStream(XRef *xref, int objStrNumA) {
str = new EmbedStream(objStr.getStream(), &obj1, gTrue,
offsets[i+1] - offsets[i]);
}
- parser = new Parser(xref, new Lexer(xref, str));
+ parser = new Parser(xref, new Lexer(xref, str), gFalse);
parser->getObj(&objs[i]);
while (str->getChar() != EOF) ;
delete parser;
@@ -283,7 +283,8 @@ GBool XRef::readXRef(Guint *pos) {
obj.initNull();
parser = new Parser(NULL,
new Lexer(NULL,
- str->makeSubStream(start + *pos, gFalse, 0, &obj)));
+ str->makeSubStream(start + *pos, gFalse, 0, &obj)),
+ gTrue);
parser->getObj(&obj);
// parse an old-style xref table
@@ -624,7 +625,7 @@ GBool XRef::constructXRef() {
size = 0;
entries = NULL;
- error(0, "PDF file is damaged - attempting to reconstruct xref table...");
+ error(-1, "PDF file is damaged - attempting to reconstruct xref table...");
gotRoot = gFalse;
streamEndsLen = streamEndsSize = 0;
@@ -636,12 +637,16 @@ GBool XRef::constructXRef() {
}
p = buf;
+ // skip whitespace
+ while (*p && Lexer::isSpace(*p & 0xff)) ++p;
+
// got trailer dictionary
if (!strncmp(p, "trailer", 7)) {
obj.initNull();
parser = new Parser(NULL,
new Lexer(NULL,
- str->makeSubStream(pos + 7, gFalse, 0, &obj)));
+ str->makeSubStream(pos + 7, gFalse, 0, &obj)),
+ gFalse);
parser->getObj(&newTrailerDict);
if (newTrailerDict.isDict()) {
newTrailerDict.dictLookupNF("Root", &obj);
@@ -724,7 +729,8 @@ GBool XRef::constructXRef() {
}
void XRef::setEncryption(int permFlagsA, GBool ownerPasswordOkA,
- Guchar *fileKeyA, int keyLengthA, int encVersionA) {
+ Guchar *fileKeyA, int keyLengthA, int encVersionA,
+ CryptAlgorithm encAlgorithmA) {
int i;
encrypted = gTrue;
@@ -739,6 +745,7 @@ void XRef::setEncryption(int permFlagsA, GBool ownerPasswordOkA,
fileKey[i] = fileKeyA[i];
}
encVersion = encVersionA;
+ encAlgorithm = encAlgorithmA;
}
GBool XRef::okToPrint(GBool ignoreOwnerPW) {
@@ -777,7 +784,8 @@ Object *XRef::fetch(int num, int gen, Object *obj) {
obj1.initNull();
parser = new Parser(this,
new Lexer(this,
- str->makeSubStream(start + e->offset, gFalse, 0, &obj1)));
+ str->makeSubStream(start + e->offset, gFalse, 0, &obj1)),
+ gTrue);
parser->getObj(&obj1);
parser->getObj(&obj2);
parser->getObj(&obj3);
@@ -790,8 +798,8 @@ Object *XRef::fetch(int num, int gen, Object *obj) {
delete parser;
goto err;
}
- parser->getObj(obj, encrypted ? fileKey : (Guchar *)NULL, keyLength,
- num, gen);
+ parser->getObj(obj, encrypted ? fileKey : (Guchar *)NULL,
+ encAlgorithm, keyLength, num, gen);
obj1.free();
obj2.free();
obj3.free();
diff --git a/Build/source/libs/xpdf/xpdf/XRef.h b/Build/source/libs/xpdf/xpdf/XRef.h
index 91cf28403e2..6eb32b92ae8 100644
--- a/Build/source/libs/xpdf/xpdf/XRef.h
+++ b/Build/source/libs/xpdf/xpdf/XRef.h
@@ -85,7 +85,8 @@ public:
// Set the encryption parameters.
void setEncryption(int permFlagsA, GBool ownerPasswordOkA,
- Guchar *fileKeyA, int keyLengthA, int encVersionA);
+ Guchar *fileKeyA, int keyLengthA, int encVersionA,
+ CryptAlgorithm encAlgorithmA);
// Is the file encrypted?
GBool isEncrypted() { return encrypted; }
@@ -147,7 +148,8 @@ private:
GBool ownerPasswordOk; // true if owner password is correct
Guchar fileKey[16]; // file decryption key
int keyLength; // length of key, in bytes
- int encVersion; // encryption algorithm
+ int encVersion; // encryption version
+ CryptAlgorithm encAlgorithm; // encryption algorithm
Guint getStartXref();
GBool readXRef(Guint *pos);
diff --git a/Build/source/libs/xpdf/xpdf/config.h b/Build/source/libs/xpdf/xpdf/config.h
index 0bd5541c2b0..81d4dd071b5 100644
--- a/Build/source/libs/xpdf/xpdf/config.h
+++ b/Build/source/libs/xpdf/xpdf/config.h
@@ -2,7 +2,7 @@
//
// config.h
//
-// Copyright 1996-2005 Glyph & Cog, LLC
+// Copyright 1996-2007 Glyph & Cog, LLC
//
//========================================================================
@@ -14,26 +14,25 @@
//------------------------------------------------------------------------
// xpdf version
-#define xpdfVersion "3.01"
-#define xpdfVersionNum 3.01
+#define xpdfVersion "3.02"
+#define xpdfVersionNum 3.02
#define xpdfMajorVersion 3
-#define xpdfMinorVersion 1
+#define xpdfMinorVersion 2
#define xpdfUpdateVersion 0
#define xpdfMajorVersionStr "3"
-#define xpdfMinorVersionStr "1"
+#define xpdfMinorVersionStr "2"
#define xpdfUpdateVersionStr "0"
// supported PDF version
-// xpdf says only 1.5, but 1.7 is the same for pdfTeX's purpose
#define supportedPDFVersionStr "1.7"
#define supportedPDFVersionNum 1.7
// copyright notice
-#define xpdfCopyright "Copyright 1996-2005 Glyph & Cog, LLC"
+#define xpdfCopyright "Copyright 1996-2007 Glyph & Cog, LLC"
// Windows resource file stuff
-#define winxpdfVersion "WinXpdf 3.01"
-#define xpdfCopyrightAmp "Copyright 1996-2005 Glyph && Cog, LLC"
+#define winxpdfVersion "WinXpdf 3.02"
+#define xpdfCopyrightAmp "Copyright 1996-2007 Glyph && Cog, LLC"
//------------------------------------------------------------------------
// paper size
diff --git a/Build/source/texk/kpathsea/cnf.c b/Build/source/texk/kpathsea/cnf.c
index 951edd550eb..12a0b574828 100644
--- a/Build/source/texk/kpathsea/cnf.c
+++ b/Build/source/texk/kpathsea/cnf.c
@@ -30,6 +30,7 @@
#include <kpathsea/paths.h>
#include <kpathsea/pathsearch.h>
#include <kpathsea/progname.h>
+#include <kpathsea/recorder.h>
#include <kpathsea/tex-file.h>
#include <kpathsea/variable.h>
@@ -166,6 +167,8 @@ read_all_cnf P1H(void)
for (cnf = cnf_files; *cnf; cnf++) {
string line;
FILE *cnf_file = xfopen (*cnf, FOPEN_R_MODE);
+ if (kpse_record_input)
+ kpse_record_input (*cnf);
while ((line = read_line (cnf_file)) != NULL) {
unsigned len = strlen (line);
diff --git a/Build/source/texk/kpathsea/depend.mak b/Build/source/texk/kpathsea/depend.mak
index 3182cfb7e45..ceb5c840883 100644
--- a/Build/source/texk/kpathsea/depend.mak
+++ b/Build/source/texk/kpathsea/depend.mak
@@ -1199,6 +1199,7 @@ $(objdir)/cnf.obj: \
$(kpathseadir)/line.h \
$(kpathseadir)/paths.h \
$(kpathseadir)/pathsearch.h \
+ $(kpathseadir)/recoder.h \
$(kpathseadir)/str-llist.h \
$(kpathseadir)/tex-file.h \
$(kpathseadir)/c-vararg.h \
diff --git a/Build/source/texk/kpathsea/depend.mk b/Build/source/texk/kpathsea/depend.mk
index 39cf08cca7a..0d80e68cf66 100644
--- a/Build/source/texk/kpathsea/depend.mk
+++ b/Build/source/texk/kpathsea/depend.mk
@@ -39,6 +39,7 @@ cnf.lo: cnf.c $(kpathsea_srcdir)/config.h $(kpathsea_dir)/c-auto.h \
$(kpathsea_srcdir)/cnf.h $(kpathsea_srcdir)/db.h $(kpathsea_srcdir)/str-list.h \
$(kpathsea_srcdir)/hash.h $(kpathsea_srcdir)/line.h $(kpathsea_dir)/paths.h \
$(kpathsea_srcdir)/pathsearch.h $(kpathsea_srcdir)/str-llist.h $(kpathsea_srcdir)/tex-file.h \
+ $(kpathsea_srcdir)/recorder.h \
$(kpathsea_srcdir)/c-vararg.h $(kpathsea_srcdir)/variable.h
concat3.lo: concat3.c $(kpathsea_srcdir)/config.h $(kpathsea_dir)/c-auto.h \
$(kpathsea_srcdir)/c-std.h \
diff --git a/Build/source/texk/kpathsea/kpathsea.h b/Build/source/texk/kpathsea/kpathsea.h
index 4256cb155e2..c8189440253 100644
--- a/Build/source/texk/kpathsea/kpathsea.h
+++ b/Build/source/texk/kpathsea/kpathsea.h
@@ -36,6 +36,7 @@
#include <kpathsea/proginit.h>
#include <kpathsea/progname.h>
#include <kpathsea/readable.h>
+#include <kpathsea/recorder.h>
#include <kpathsea/str-list.h>
#include <kpathsea/str-llist.h>
#include <kpathsea/systypes.h>
diff --git a/Build/source/texk/kpathsea/recorder.h b/Build/source/texk/kpathsea/recorder.h
new file mode 100644
index 00000000000..a3532de1f89
--- /dev/null
+++ b/Build/source/texk/kpathsea/recorder.h
@@ -0,0 +1,30 @@
+/* recorder.h: filename recorder callback.
+
+ Copyright 2007 Karl Berry.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+*/
+
+#ifndef KPATHSEA_RECORDER_H
+#define KPATHSEA_RECORDER_H
+
+/* Thess variables get set by web2c and are used to record filenames for its
+ * filename recorder. This way they can also be used in kpathsea, e.g. for
+ * texmf.cnf */
+void (*kpse_record_input)(char*);
+void (*kpse_record_output)(char*);
+
+#endif /* not KPATHSEA_RECORDER_H */
diff --git a/Build/source/texk/web2c/alephdir/com16bit-rc2.ch b/Build/source/texk/web2c/alephdir/com16bit-rc2.ch
index aa7e8f7f310..096aaa027a2 100644
--- a/Build/source/texk/web2c/alephdir/com16bit-rc2.ch
+++ b/Build/source/texk/web2c/alephdir/com16bit-rc2.ch
@@ -1349,12 +1349,20 @@ var k:0..buf_size; {index into |buffer|}
@y
var k:0..buf_size; {index into |buffer|}
@!saved_cur_name:str_number; {to catch empty terminal input}
+@!saved_cur_ext:str_number; {to catch empty terminal input}
+@!saved_cur_area:str_number; {to catch empty terminal input}
@z
@x [29.530] l.10252 - prompt_file_name: No default extension is TeX input file.
if e=".tex" then show_context;
@y
if (e=".tex") or (e="") then show_context;
+print_ln; print("(Enter the null string to re-try, or <eof> to exit");
+if (e<>"") then
+ begin
+ print(" Default file extension is `"); print(e); print("'");
+ end;
+print(")"); print_ln;
@z
@x [29.530] l.10258 - prompt_file_name: prevent empty filenames.
@@ -1362,9 +1370,17 @@ clear_terminal; prompt_input(": "); @<Scan file name in the buffer@>;
if cur_ext="" then cur_ext:=e;
@y
saved_cur_name:=cur_name;
+saved_cur_ext:=cur_ext;
+saved_cur_area:=cur_area;
clear_terminal; prompt_input(": "); @<Scan file name in the buffer@>;
-if cur_ext="" then cur_ext:=e;
-if length(cur_name)=0 then cur_name:=saved_cur_name;
+if (length(cur_name)=0) and (cur_ext="") and (cur_area="") then
+ begin
+ cur_name:=saved_cur_name;
+ cur_ext:=saved_cur_ext;
+ cur_area:=saved_cur_area;
+ end
+else
+ if cur_ext="" then cur_ext:=e;
@z
@x [29.532] l.10263 - avoid conflict, `logname' in <unistd.h> on some systems.
diff --git a/Build/source/texk/web2c/cpascal.h b/Build/source/texk/web2c/cpascal.h
index c16d12f06d7..b2cc4619848 100644
--- a/Build/source/texk/web2c/cpascal.h
+++ b/Build/source/texk/web2c/cpascal.h
@@ -272,6 +272,8 @@ extern void close_file P1H(FILE *);
extern void recorder_change_filename P1H(string);
extern boolean recorder_enabled;
extern string output_directory;
+extern void recorder_record_input P1H(string);
+extern void recorder_record_output P1H(string);
/* version.c */
extern string versionstring;
diff --git a/Build/source/texk/web2c/lib/openclose.c b/Build/source/texk/web2c/lib/openclose.c
index a4ac21495b8..fc23ab42e88 100644
--- a/Build/source/texk/web2c/lib/openclose.c
+++ b/Build/source/texk/web2c/lib/openclose.c
@@ -58,6 +58,31 @@ recorder_change_filename P1C(string, new_name)
free(recorder_name);
recorder_name = xstrdup(new_name);
}
+
+/* helper for recorder_record_* */
+void
+recorder_record_name P2C(string, prefix, string, nameoffile)
+{
+ if (recorder_enabled) {
+ if (!recorder_file)
+ recorder_start();
+ fprintf(recorder_file, "%s %s\n", prefix, nameoffile);
+ }
+}
+
+/* record an input file */
+void
+recorder_record_input P1C(string, nameoffile)
+{
+ recorder_record_name ("INPUT", nameoffile);
+}
+
+/* record an output file */
+void
+recorder_record_output P1C(string, nameoffile)
+{
+ recorder_record_name ("OUTPUT", nameoffile);
+}
/* Open an input file F, using the kpathsea format FILEFMT and passing
FOPEN_MODE to fopen. The filename is in `nameoffile+1'. We return
@@ -155,11 +180,7 @@ open_input P3C(FILE **, f_ptr, int, filefmt, const_string, fopen_mode)
}
if (*f_ptr) {
- if (recorder_enabled) {
- if (!recorder_file)
- recorder_start();
- fprintf(recorder_file, "INPUT %s\n", nameoffile + 1);
- }
+ recorder_record_input (nameoffile + 1);
/* If we just opened a TFM file, we have to read the first
byte, to pretend we're Pascal. See tex.ch and mp.ch.
@@ -220,11 +241,7 @@ open_output P2C(FILE **, f_ptr, const_string, fopen_mode)
nameoffile = (string)xmalloc (namelength + 2);
strcpy (nameoffile + 1, fname);
}
- if (recorder_enabled) {
- if (!recorder_file)
- recorder_start();
- fprintf(recorder_file, "OUTPUT %s\n", fname);
- }
+ recorder_record_output (fname);
}
if (fname != nameoffile +1)
free(fname);
diff --git a/Build/source/texk/web2c/lib/texmfmp.c b/Build/source/texk/web2c/lib/texmfmp.c
index 12307761463..8b876bb42a5 100644
--- a/Build/source/texk/web2c/lib/texmfmp.c
+++ b/Build/source/texk/web2c/lib/texmfmp.c
@@ -18,6 +18,7 @@
#include <kpathsea/readable.h>
#include <kpathsea/variable.h>
#include <kpathsea/absolute.h>
+#include <kpathsea/recorder.h>
#include <time.h> /* For `struct tm'. */
#if defined (HAVE_SYS_TIME_H)
@@ -186,6 +187,9 @@ maininit P2C(int, ac, string *, av)
/* Must be initialized before options are parsed. */
interactionoption = 4;
+ kpse_record_input = recorder_record_input;
+ kpse_record_output = recorder_record_output;
+
#if defined(pdfTeX)
ptexbanner = BANNER;
#endif
@@ -1357,6 +1361,7 @@ open_in_or_pipe P3C(FILE **, f_ptr, int, filefmt, const_string, fopen_mode)
free (fullnameoffile);
fullnameoffile = xstrdup (fname);
#endif
+ recorder_record_input (fname + 1);
*f_ptr = popen(fname+1,"r");
free(fname);
for (i=0; i<=15; i++) {
@@ -1401,6 +1406,7 @@ open_out_or_pipe P2C(FILE **, f_ptr, const_string, fopen_mode)
} else {
*f_ptr = popen(fname+1,"w");
}
+ recorder_record_output (fname + 1);
free(fname);
for (i=0; i<=15; i++) {
diff --git a/Build/source/texk/web2c/omegadir/com16bit.ch b/Build/source/texk/web2c/omegadir/com16bit.ch
index 98da09fb4ae..5214c8b6cae 100644
--- a/Build/source/texk/web2c/omegadir/com16bit.ch
+++ b/Build/source/texk/web2c/omegadir/com16bit.ch
@@ -1348,12 +1348,20 @@ var k:0..buf_size; {index into |buffer|}
@y
var k:0..buf_size; {index into |buffer|}
@!saved_cur_name:str_number; {to catch empty terminal input}
+@!saved_cur_ext:str_number; {to catch empty terminal input}
+@!saved_cur_area:str_number; {to catch empty terminal input}
@z
@x [29.530] l.10252 - prompt_file_name: No default extension is TeX input file.
if e=".tex" then show_context;
@y
if (e=".tex") or (e="") then show_context;
+print_ln; print("(Enter the null string to re-try, or <eof> to exit");
+if (e<>"") then
+ begin
+ print(" Default file extension is `"); print(e); print("'");
+ end;
+print(")"); print_ln;
@z
@x [29.530] l.10258 - prompt_file_name: prevent empty filenames.
@@ -1361,9 +1369,17 @@ clear_terminal; prompt_input(": "); @<Scan file name in the buffer@>;
if cur_ext="" then cur_ext:=e;
@y
saved_cur_name:=cur_name;
+saved_cur_ext:=cur_ext;
+saved_cur_area:=cur_area;
clear_terminal; prompt_input(": "); @<Scan file name in the buffer@>;
-if cur_ext="" then cur_ext:=e;
-if length(cur_name)=0 then cur_name:=saved_cur_name;
+if (length(cur_name)=0) and (cur_ext="") and (cur_area="") then
+ begin
+ cur_name:=saved_cur_name;
+ cur_ext:=saved_cur_ext;
+ cur_area:=saved_cur_area;
+ end
+else
+ if cur_ext="" then cur_ext:=e;
@z
@x [29.532] l.10263 - avoid conflict, `logname' in <unistd.h> on some systems.
diff --git a/Build/source/texk/web2c/pdftexdir/Makefile.in b/Build/source/texk/web2c/pdftexdir/Makefile.in
index 0f77f973d62..7f4aa216d76 100644
--- a/Build/source/texk/web2c/pdftexdir/Makefile.in
+++ b/Build/source/texk/web2c/pdftexdir/Makefile.in
@@ -1,5 +1,5 @@
# Makefile for libpdf - te@dbs.uni-hannover.de
-# $Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/Makefile.in#23 $
+# $Id: Makefile.in 200 2007-07-11 13:11:12Z oneiros $
kpse_include ../make/common.mk
kpse_include ../make/programs.mk
@@ -59,7 +59,7 @@ clean::
depend:
rm -f $(OBJS) ttf2afm.o pdftosrc.o
XXCFLAGS=-MM XCFLAGS=-MM $(MAKE) -k $(OBJS) ttf2afm.o pdftosrc.o | \
- grep -v "^$(CC)\|$(CXX)\|$(AR)\|make\|klibtool" | \
+ grep -v "^$(CC)\|$(CXX)\|$(AR)\|make\" | \
sed 's: [^ ]*/\.\./libs/[^ ]*::g' > $(srcdir)/depend.mk
kpse_include pdftexdir/depend.mk
diff --git a/Build/source/texk/web2c/pdftexdir/NEWS b/Build/source/texk/web2c/pdftexdir/NEWS
index 466ba74993d..8cac60b4713 100644
--- a/Build/source/texk/web2c/pdftexdir/NEWS
+++ b/Build/source/texk/web2c/pdftexdir/NEWS
@@ -1,4 +1,37 @@
-------------------------------------------------
+pdfTeX 3.141592-1.40.4 was released on 2007-07-11
+-------------------------------------------------
+- Bugfixes:
+ - It was impossible to set the font Flags to 4 in map entries (762)
+ - The font Flags of non-embedded fonts were wrong (794)
+ Now pdfTeX uses the Flags from map entries (if found) or guesses values for
+ the base14 fonts. It also warns when you not-embedd a font without Flags
+ - Subsetted fonts still had their private UniqueID copied (774)
+ - \pdfunescapehex returned a wrong result if the last character was not a
+ hexadecimal digit and the last hex pair was incomplete (777)
+ - Copying a box with \pdfstartlink inside produced the same /Link annotation
+ object multiply, with same object number and identical coordinates on the
+ page (799)
+ - When trying to use a font without TFM, without map entry, and no PK font
+ available, a broken PDF was produced. Now no PDF is generated and the error
+ messages have been improved (721)
+ - Problems with vf fonts (722)
+ - Font expansion led to wrong log output of \kerns (736)
+ - \pdfprimitive was broken (see
+ http://www.ntg.nl/pipermail/ntg-pdftex/2007-April/002860.html)
+ - The -recorder option of web2c didn't record fonts, included images and some
+ other files (772)
+ - Using \pdfximage in IniTeX before \dump caused a crash when the format was
+ used (824)
+ - \letterspacefont had some problems (712)
+ - \letterspacefont and \pdffontexpand had some problems (747)
+- Improvements:
+ - pdf compression is now a bit faster (patch 726)
+ - the behaviour of TeX when it asks for a file name has been improved (756)
+- pdfTeX uses libpng 1.2.18
+- pdfTeX uses xpdf 3.02
+
+-------------------------------------------------
pdfTeX 3.141592-1.40.3 was released on 2007-02-04
-------------------------------------------------
- bugfix: document which used type 1 and truetype or opentype fonts resulted in
@@ -530,5 +563,5 @@ pdfTeX 3.14159-1.00a-pretest-20010806 was released on 2001-08-06
pdfTeX 3.14159-1.00a-pretest-20010804 was released on 2001-08-04
----------------------------------------------------------------
-$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/NEWS#86 $
+$Id: NEWS 200 2007-07-11 13:11:12Z oneiros $
// vim: tw=79:ts=2:expandtab:autoindent
diff --git a/Build/source/texk/web2c/pdftexdir/README b/Build/source/texk/web2c/pdftexdir/README
index b43ecc3dd66..2c9cd21eb67 100644
--- a/Build/source/texk/web2c/pdftexdir/README
+++ b/Build/source/texk/web2c/pdftexdir/README
@@ -1,10 +1,10 @@
pdfTeX
======
-README for version 3.14159-1.40.3
+README for version 3.14159-1.40.4
=================================
-This directory contains the version 1.40.3 of pdfTeX, an extended version
+This directory contains the version 1.40.4 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
@@ -37,8 +37,8 @@ pdfTeX is copyright (c) 1996-2007 Han The Thanh, <thanh@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
-Foundation; either version 2 of the License, or (at your option) any later
-version.
+Foundation; either version 2.1 of the License, or (at your option) any
+later version.
pdfTeX is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
@@ -46,8 +46,8 @@ FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
details.
You should have received a copy of the GNU General Public License along
-with pdfTeX; if not, write to the Free Software Foundation, Inc., 59 Temple
-Place, Suite 330, Boston, MA 02111-1307 USA
+with pdfTeX; if not, write to the Free Software Foundation, Inc., 51
+Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
pdfTeX uses code from TeX; for these parts the original copyright by Don
Knuth applies. See the source files for details.
@@ -69,10 +69,11 @@ CONTRIBUTORS
============
Peter Breitenlohner, Ricardo Sanchez Carmenes, Otfried Cheong, Thomas
-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.
+Esser, Hans Hagen, Hartmut Henkel, Taco Hoekwater, Pawel Jackowski, Pavel
+Janik, Tom Kacvinsky, Akira Kakuto, Reinhard Kotucha, Derek B. Noonburg,
+Heiko Oberdiek, Jiri Osoba, Fabrice Popineau, Sebastian Rahtz, Bernd
+Raichle, 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
@@ -83,5 +84,5 @@ paragraph optimization is inspired by the work of Hermann Zapf.
Please send bug reports, offers of help, etc. to martin@pdftex.org
-$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/README#30 $
+$Id: README 200 2007-07-11 13:11:12Z oneiros $
// vim: tw=75
diff --git a/Build/source/texk/web2c/pdftexdir/avl.c b/Build/source/texk/web2c/pdftexdir/avl.c
index a25239e8d93..79c746cd10d 100644
--- a/Build/source/texk/web2c/pdftexdir/avl.c
+++ b/Build/source/texk/web2c/pdftexdir/avl.c
@@ -33,455 +33,406 @@
with comparison function |compare| using parameter |param|
and memory allocator |allocator|.
Returns |NULL| if memory allocation failed. */
-struct avl_table *
-avl_create (avl_comparison_func *compare, void *param,
- struct libavl_allocator *allocator)
+struct avl_table *avl_create(avl_comparison_func * compare, void *param,
+ struct libavl_allocator *allocator)
{
- struct avl_table *tree;
+ struct avl_table *tree;
- assert (compare != NULL);
+ assert(compare != NULL);
- if (allocator == NULL)
- allocator = &avl_allocator_default;
+ if (allocator == NULL)
+ allocator = &avl_allocator_default;
- tree = allocator->libavl_malloc (allocator, sizeof *tree);
- if (tree == NULL)
- return NULL;
+ tree = allocator->libavl_malloc(allocator, sizeof *tree);
+ if (tree == NULL)
+ return NULL;
- tree->avl_root = NULL;
- tree->avl_compare = compare;
- tree->avl_param = param;
- tree->avl_alloc = allocator;
- tree->avl_count = 0;
- tree->avl_generation = 0;
+ tree->avl_root = NULL;
+ tree->avl_compare = compare;
+ tree->avl_param = param;
+ tree->avl_alloc = allocator;
+ tree->avl_count = 0;
+ tree->avl_generation = 0;
- return tree;
+ return tree;
}
/* Search |tree| for an item matching |item|, and return it if found.
Otherwise return |NULL|. */
-void *
-avl_find (const struct avl_table *tree, const void *item)
+void *avl_find(const struct avl_table *tree, const void *item)
{
- const struct avl_node *p;
-
- assert (tree != NULL && item != NULL);
- for (p = tree->avl_root; p != NULL; )
- {
- int cmp = tree->avl_compare (item, p->avl_data, tree->avl_param);
-
- if (cmp < 0)
- p = p->avl_link[0];
- else if (cmp > 0)
- p = p->avl_link[1];
- else /* |cmp == 0| */
- return p->avl_data;
+ const struct avl_node *p;
+
+ assert(tree != NULL && item != NULL);
+ for (p = tree->avl_root; p != NULL;) {
+ int cmp = tree->avl_compare(item, p->avl_data, tree->avl_param);
+
+ if (cmp < 0)
+ p = p->avl_link[0];
+ else if (cmp > 0)
+ p = p->avl_link[1];
+ else /* |cmp == 0| */
+ return p->avl_data;
}
- return NULL;
+ return NULL;
}
/* Inserts |item| into |tree| and returns a pointer to |item|'s address.
If a duplicate item is found in the tree,
returns a pointer to the duplicate without inserting |item|.
Returns |NULL| in case of memory allocation failure. */
-void **
-avl_probe (struct avl_table *tree, void *item)
+void **avl_probe(struct avl_table *tree, void *item)
{
- struct avl_node *y, *z; /* Top node to update balance factor, and parent. */
- struct avl_node *p, *q; /* Iterator, and parent. */
- struct avl_node *n; /* Newly inserted node. */
- struct avl_node *w; /* New root of rebalanced subtree. */
- int dir; /* Direction to descend. */
-
- unsigned char da[AVL_MAX_HEIGHT]; /* Cached comparison results. */
- int k = 0; /* Number of cached results. */
-
- assert (tree != NULL && item != NULL);
-
- z = (struct avl_node *) &tree->avl_root;
- y = tree->avl_root;
- dir = 0;
- for (q = z, p = y; p != NULL; q = p, p = p->avl_link[dir])
- {
- int cmp = tree->avl_compare (item, p->avl_data, tree->avl_param);
- if (cmp == 0)
- return &p->avl_data;
-
- if (p->avl_balance != 0)
- z = q, y = p, k = 0;
- da[k++] = dir = cmp > 0;
+ struct avl_node *y, *z; /* Top node to update balance factor, and parent. */
+ struct avl_node *p, *q; /* Iterator, and parent. */
+ struct avl_node *n; /* Newly inserted node. */
+ struct avl_node *w; /* New root of rebalanced subtree. */
+ int dir; /* Direction to descend. */
+
+ unsigned char da[AVL_MAX_HEIGHT]; /* Cached comparison results. */
+ int k = 0; /* Number of cached results. */
+
+ assert(tree != NULL && item != NULL);
+
+ z = (struct avl_node *) &tree->avl_root;
+ y = tree->avl_root;
+ dir = 0;
+ for (q = z, p = y; p != NULL; q = p, p = p->avl_link[dir]) {
+ int cmp = tree->avl_compare(item, p->avl_data, tree->avl_param);
+ if (cmp == 0)
+ return &p->avl_data;
+
+ if (p->avl_balance != 0)
+ z = q, y = p, k = 0;
+ da[k++] = dir = cmp > 0;
}
- n = q->avl_link[dir] =
- tree->avl_alloc->libavl_malloc (tree->avl_alloc, sizeof *n);
- if (n == NULL)
- return NULL;
-
- tree->avl_count++;
- n->avl_data = item;
- n->avl_link[0] = n->avl_link[1] = NULL;
- n->avl_balance = 0;
- if (y == NULL)
- return &n->avl_data;
+ n = q->avl_link[dir] =
+ tree->avl_alloc->libavl_malloc(tree->avl_alloc, sizeof *n);
+ if (n == NULL)
+ return NULL;
- for (p = y, k = 0; p != n; p = p->avl_link[da[k]], k++)
- if (da[k] == 0)
- p->avl_balance--;
- else
- p->avl_balance++;
-
- if (y->avl_balance == -2)
- {
- struct avl_node *x = y->avl_link[0];
- if (x->avl_balance == -1)
- {
- w = x;
- y->avl_link[0] = x->avl_link[1];
- x->avl_link[1] = y;
- x->avl_balance = y->avl_balance = 0;
- }
- else
- {
- assert (x->avl_balance == +1);
- w = x->avl_link[1];
- x->avl_link[1] = w->avl_link[0];
- w->avl_link[0] = x;
- y->avl_link[0] = w->avl_link[1];
- w->avl_link[1] = y;
- if (w->avl_balance == -1)
- x->avl_balance = 0, y->avl_balance = +1;
- else if (w->avl_balance == 0)
+ tree->avl_count++;
+ n->avl_data = item;
+ n->avl_link[0] = n->avl_link[1] = NULL;
+ n->avl_balance = 0;
+ if (y == NULL)
+ return &n->avl_data;
+
+ for (p = y, k = 0; p != n; p = p->avl_link[da[k]], k++)
+ if (da[k] == 0)
+ p->avl_balance--;
+ else
+ p->avl_balance++;
+
+ if (y->avl_balance == -2) {
+ struct avl_node *x = y->avl_link[0];
+ if (x->avl_balance == -1) {
+ w = x;
+ y->avl_link[0] = x->avl_link[1];
+ x->avl_link[1] = y;
x->avl_balance = y->avl_balance = 0;
- else /* |w->avl_balance == +1| */
- x->avl_balance = -1, y->avl_balance = 0;
- w->avl_balance = 0;
+ } else {
+ assert(x->avl_balance == +1);
+ w = x->avl_link[1];
+ x->avl_link[1] = w->avl_link[0];
+ w->avl_link[0] = x;
+ y->avl_link[0] = w->avl_link[1];
+ w->avl_link[1] = y;
+ if (w->avl_balance == -1)
+ x->avl_balance = 0, y->avl_balance = +1;
+ else if (w->avl_balance == 0)
+ x->avl_balance = y->avl_balance = 0;
+ else /* |w->avl_balance == +1| */
+ x->avl_balance = -1, y->avl_balance = 0;
+ w->avl_balance = 0;
}
- }
- else if (y->avl_balance == +2)
- {
- struct avl_node *x = y->avl_link[1];
- if (x->avl_balance == +1)
- {
- w = x;
- y->avl_link[1] = x->avl_link[0];
- x->avl_link[0] = y;
- x->avl_balance = y->avl_balance = 0;
- }
- else
- {
- assert (x->avl_balance == -1);
- w = x->avl_link[0];
- x->avl_link[0] = w->avl_link[1];
- w->avl_link[1] = x;
- y->avl_link[1] = w->avl_link[0];
- w->avl_link[0] = y;
- if (w->avl_balance == +1)
- x->avl_balance = 0, y->avl_balance = -1;
- else if (w->avl_balance == 0)
+ } else if (y->avl_balance == +2) {
+ struct avl_node *x = y->avl_link[1];
+ if (x->avl_balance == +1) {
+ w = x;
+ y->avl_link[1] = x->avl_link[0];
+ x->avl_link[0] = y;
x->avl_balance = y->avl_balance = 0;
- else /* |w->avl_balance == -1| */
- x->avl_balance = +1, y->avl_balance = 0;
- w->avl_balance = 0;
+ } else {
+ assert(x->avl_balance == -1);
+ w = x->avl_link[0];
+ x->avl_link[0] = w->avl_link[1];
+ w->avl_link[1] = x;
+ y->avl_link[1] = w->avl_link[0];
+ w->avl_link[0] = y;
+ if (w->avl_balance == +1)
+ x->avl_balance = 0, y->avl_balance = -1;
+ else if (w->avl_balance == 0)
+ x->avl_balance = y->avl_balance = 0;
+ else /* |w->avl_balance == -1| */
+ x->avl_balance = +1, y->avl_balance = 0;
+ w->avl_balance = 0;
}
- }
- else
- return &n->avl_data;
- z->avl_link[y != z->avl_link[0]] = w;
+ } else
+ return &n->avl_data;
+ z->avl_link[y != z->avl_link[0]] = w;
- tree->avl_generation++;
- return &n->avl_data;
+ tree->avl_generation++;
+ return &n->avl_data;
}
/* Inserts |item| into |table|.
Returns |NULL| if |item| was successfully inserted
or if a memory allocation error occurred.
Otherwise, returns the duplicate item. */
-void *
-avl_insert (struct avl_table *table, void *item)
+void *avl_insert(struct avl_table *table, void *item)
{
- void **p = avl_probe (table, item);
- return p == NULL || *p == item ? NULL : *p;
+ void **p = avl_probe(table, item);
+ return p == NULL || *p == item ? NULL : *p;
}
/* Inserts |item| into |table|, replacing any duplicate item.
Returns |NULL| if |item| was inserted without replacing a duplicate,
or if a memory allocation error occurred.
Otherwise, returns the item that was replaced. */
-void *
-avl_replace (struct avl_table *table, void *item)
+void *avl_replace(struct avl_table *table, void *item)
{
- void **p = avl_probe (table, item);
- if (p == NULL || *p == item)
- return NULL;
- else
- {
- void *r = *p;
- *p = item;
- return r;
+ void **p = avl_probe(table, item);
+ if (p == NULL || *p == item)
+ return NULL;
+ else {
+ void *r = *p;
+ *p = item;
+ return r;
}
}
/* Deletes from |tree| and returns an item matching |item|.
Returns a null pointer if no matching item found. */
-void *
-avl_delete (struct avl_table *tree, const void *item)
+void *avl_delete(struct avl_table *tree, const void *item)
{
- /* Stack of nodes. */
- struct avl_node *pa[AVL_MAX_HEIGHT]; /* Nodes. */
- unsigned char da[AVL_MAX_HEIGHT]; /* |avl_link[]| indexes. */
- int k; /* Stack pointer. */
+ /* Stack of nodes. */
+ struct avl_node *pa[AVL_MAX_HEIGHT]; /* Nodes. */
+ unsigned char da[AVL_MAX_HEIGHT]; /* |avl_link[]| indexes. */
+ int k; /* Stack pointer. */
- struct avl_node *p; /* Traverses tree to find node to delete. */
- int cmp; /* Result of comparison between |item| and |p|. */
+ struct avl_node *p; /* Traverses tree to find node to delete. */
+ int cmp; /* Result of comparison between |item| and |p|. */
- assert (tree != NULL && item != NULL);
+ assert(tree != NULL && item != NULL);
- k = 0;
- p = (struct avl_node *) &tree->avl_root;
- for (cmp = -1; cmp != 0;
- cmp = tree->avl_compare (item, p->avl_data, tree->avl_param))
- {
- int dir = cmp > 0;
+ k = 0;
+ p = (struct avl_node *) &tree->avl_root;
+ for (cmp = -1; cmp != 0;
+ cmp = tree->avl_compare(item, p->avl_data, tree->avl_param)) {
+ int dir = cmp > 0;
- pa[k] = p;
- da[k++] = dir;
+ pa[k] = p;
+ da[k++] = dir;
- p = p->avl_link[dir];
- if (p == NULL)
- return NULL;
+ p = p->avl_link[dir];
+ if (p == NULL)
+ return NULL;
}
- item = p->avl_data;
-
- if (p->avl_link[1] == NULL)
- pa[k - 1]->avl_link[da[k - 1]] = p->avl_link[0];
- else
- {
- struct avl_node *r = p->avl_link[1];
- if (r->avl_link[0] == NULL)
- {
- r->avl_link[0] = p->avl_link[0];
- r->avl_balance = p->avl_balance;
- pa[k - 1]->avl_link[da[k - 1]] = r;
- da[k] = 1;
- pa[k++] = r;
- }
- else
- {
- struct avl_node *s;
- int j = k++;
-
- for (;;)
- {
- da[k] = 0;
- pa[k++] = r;
- s = r->avl_link[0];
- if (s->avl_link[0] == NULL)
- break;
-
- r = s;
+ item = p->avl_data;
+
+ if (p->avl_link[1] == NULL)
+ pa[k - 1]->avl_link[da[k - 1]] = p->avl_link[0];
+ else {
+ struct avl_node *r = p->avl_link[1];
+ if (r->avl_link[0] == NULL) {
+ r->avl_link[0] = p->avl_link[0];
+ r->avl_balance = p->avl_balance;
+ pa[k - 1]->avl_link[da[k - 1]] = r;
+ da[k] = 1;
+ pa[k++] = r;
+ } else {
+ struct avl_node *s;
+ int j = k++;
+
+ for (;;) {
+ da[k] = 0;
+ pa[k++] = r;
+ s = r->avl_link[0];
+ if (s->avl_link[0] == NULL)
+ break;
+
+ r = s;
}
- s->avl_link[0] = p->avl_link[0];
- r->avl_link[0] = s->avl_link[1];
- s->avl_link[1] = p->avl_link[1];
- s->avl_balance = p->avl_balance;
+ s->avl_link[0] = p->avl_link[0];
+ r->avl_link[0] = s->avl_link[1];
+ s->avl_link[1] = p->avl_link[1];
+ s->avl_balance = p->avl_balance;
- pa[j - 1]->avl_link[da[j - 1]] = s;
- da[j] = 1;
- pa[j] = s;
+ pa[j - 1]->avl_link[da[j - 1]] = s;
+ da[j] = 1;
+ pa[j] = s;
}
}
- tree->avl_alloc->libavl_free (tree->avl_alloc, p);
-
- assert (k > 0);
- while (--k > 0)
- {
- struct avl_node *y = pa[k];
-
- if (da[k] == 0)
- {
- y->avl_balance++;
- if (y->avl_balance == +1)
- break;
- else if (y->avl_balance == +2)
- {
- struct avl_node *x = y->avl_link[1];
- if (x->avl_balance == -1)
- {
- struct avl_node *w;
- assert (x->avl_balance == -1);
- w = x->avl_link[0];
- x->avl_link[0] = w->avl_link[1];
- w->avl_link[1] = x;
- y->avl_link[1] = w->avl_link[0];
- w->avl_link[0] = y;
- if (w->avl_balance == +1)
- x->avl_balance = 0, y->avl_balance = -1;
- else if (w->avl_balance == 0)
- x->avl_balance = y->avl_balance = 0;
- else /* |w->avl_balance == -1| */
- x->avl_balance = +1, y->avl_balance = 0;
- w->avl_balance = 0;
- pa[k - 1]->avl_link[da[k - 1]] = w;
- }
- else
- {
- y->avl_link[1] = x->avl_link[0];
- x->avl_link[0] = y;
- pa[k - 1]->avl_link[da[k - 1]] = x;
- if (x->avl_balance == 0)
- {
- x->avl_balance = -1;
- y->avl_balance = +1;
- break;
- }
- else
- x->avl_balance = y->avl_balance = 0;
+ tree->avl_alloc->libavl_free(tree->avl_alloc, p);
+
+ assert(k > 0);
+ while (--k > 0) {
+ struct avl_node *y = pa[k];
+
+ if (da[k] == 0) {
+ y->avl_balance++;
+ if (y->avl_balance == +1)
+ break;
+ else if (y->avl_balance == +2) {
+ struct avl_node *x = y->avl_link[1];
+ if (x->avl_balance == -1) {
+ struct avl_node *w;
+ assert(x->avl_balance == -1);
+ w = x->avl_link[0];
+ x->avl_link[0] = w->avl_link[1];
+ w->avl_link[1] = x;
+ y->avl_link[1] = w->avl_link[0];
+ w->avl_link[0] = y;
+ if (w->avl_balance == +1)
+ x->avl_balance = 0, y->avl_balance = -1;
+ else if (w->avl_balance == 0)
+ x->avl_balance = y->avl_balance = 0;
+ else /* |w->avl_balance == -1| */
+ x->avl_balance = +1, y->avl_balance = 0;
+ w->avl_balance = 0;
+ pa[k - 1]->avl_link[da[k - 1]] = w;
+ } else {
+ y->avl_link[1] = x->avl_link[0];
+ x->avl_link[0] = y;
+ pa[k - 1]->avl_link[da[k - 1]] = x;
+ if (x->avl_balance == 0) {
+ x->avl_balance = -1;
+ y->avl_balance = +1;
+ break;
+ } else
+ x->avl_balance = y->avl_balance = 0;
}
}
- }
- else
- {
- y->avl_balance--;
- if (y->avl_balance == -1)
- break;
- else if (y->avl_balance == -2)
- {
- struct avl_node *x = y->avl_link[0];
- if (x->avl_balance == +1)
- {
- struct avl_node *w;
- assert (x->avl_balance == +1);
- w = x->avl_link[1];
- x->avl_link[1] = w->avl_link[0];
- w->avl_link[0] = x;
- y->avl_link[0] = w->avl_link[1];
- w->avl_link[1] = y;
- if (w->avl_balance == -1)
- x->avl_balance = 0, y->avl_balance = +1;
- else if (w->avl_balance == 0)
- x->avl_balance = y->avl_balance = 0;
- else /* |w->avl_balance == +1| */
- x->avl_balance = -1, y->avl_balance = 0;
- w->avl_balance = 0;
- pa[k - 1]->avl_link[da[k - 1]] = w;
- }
- else
- {
- y->avl_link[0] = x->avl_link[1];
- x->avl_link[1] = y;
- pa[k - 1]->avl_link[da[k - 1]] = x;
- if (x->avl_balance == 0)
- {
- x->avl_balance = +1;
- y->avl_balance = -1;
- break;
- }
- else
- x->avl_balance = y->avl_balance = 0;
+ } else {
+ y->avl_balance--;
+ if (y->avl_balance == -1)
+ break;
+ else if (y->avl_balance == -2) {
+ struct avl_node *x = y->avl_link[0];
+ if (x->avl_balance == +1) {
+ struct avl_node *w;
+ assert(x->avl_balance == +1);
+ w = x->avl_link[1];
+ x->avl_link[1] = w->avl_link[0];
+ w->avl_link[0] = x;
+ y->avl_link[0] = w->avl_link[1];
+ w->avl_link[1] = y;
+ if (w->avl_balance == -1)
+ x->avl_balance = 0, y->avl_balance = +1;
+ else if (w->avl_balance == 0)
+ x->avl_balance = y->avl_balance = 0;
+ else /* |w->avl_balance == +1| */
+ x->avl_balance = -1, y->avl_balance = 0;
+ w->avl_balance = 0;
+ pa[k - 1]->avl_link[da[k - 1]] = w;
+ } else {
+ y->avl_link[0] = x->avl_link[1];
+ x->avl_link[1] = y;
+ pa[k - 1]->avl_link[da[k - 1]] = x;
+ if (x->avl_balance == 0) {
+ x->avl_balance = +1;
+ y->avl_balance = -1;
+ break;
+ } else
+ x->avl_balance = y->avl_balance = 0;
}
}
}
}
- tree->avl_count--;
- tree->avl_generation++;
- return (void *) item;
+ tree->avl_count--;
+ tree->avl_generation++;
+ return (void *) item;
}
/* Refreshes the stack of parent pointers in |trav|
and updates its generation number. */
-static void
-trav_refresh (struct avl_traverser *trav)
+static void trav_refresh(struct avl_traverser *trav)
{
- assert (trav != NULL);
+ assert(trav != NULL);
- trav->avl_generation = trav->avl_table->avl_generation;
+ trav->avl_generation = trav->avl_table->avl_generation;
- if (trav->avl_node != NULL)
- {
- avl_comparison_func *cmp = trav->avl_table->avl_compare;
- void *param = trav->avl_table->avl_param;
- struct avl_node *node = trav->avl_node;
- struct avl_node *i;
+ if (trav->avl_node != NULL) {
+ avl_comparison_func *cmp = trav->avl_table->avl_compare;
+ void *param = trav->avl_table->avl_param;
+ struct avl_node *node = trav->avl_node;
+ struct avl_node *i;
- trav->avl_height = 0;
- for (i = trav->avl_table->avl_root; i != node; )
- {
- assert (trav->avl_height < AVL_MAX_HEIGHT);
- assert (i != NULL);
+ trav->avl_height = 0;
+ for (i = trav->avl_table->avl_root; i != node;) {
+ assert(trav->avl_height < AVL_MAX_HEIGHT);
+ assert(i != NULL);
- trav->avl_stack[trav->avl_height++] = i;
- i = i->avl_link[cmp (node->avl_data, i->avl_data, param) > 0];
+ trav->avl_stack[trav->avl_height++] = i;
+ i = i->avl_link[cmp(node->avl_data, i->avl_data, param) > 0];
}
}
}
/* Initializes |trav| for use with |tree|
and selects the null node. */
-void
-avl_t_init (struct avl_traverser *trav, struct avl_table *tree)
+void avl_t_init(struct avl_traverser *trav, struct avl_table *tree)
{
- trav->avl_table = tree;
- trav->avl_node = NULL;
- trav->avl_height = 0;
- trav->avl_generation = tree->avl_generation;
+ trav->avl_table = tree;
+ trav->avl_node = NULL;
+ trav->avl_height = 0;
+ trav->avl_generation = tree->avl_generation;
}
/* Initializes |trav| for |tree|
and selects and returns a pointer to its least-valued item.
Returns |NULL| if |tree| contains no nodes. */
-void *
-avl_t_first (struct avl_traverser *trav, struct avl_table *tree)
+void *avl_t_first(struct avl_traverser *trav, struct avl_table *tree)
{
- struct avl_node *x;
+ struct avl_node *x;
- assert (tree != NULL && trav != NULL);
+ assert(tree != NULL && trav != NULL);
- trav->avl_table = tree;
- trav->avl_height = 0;
- trav->avl_generation = tree->avl_generation;
+ trav->avl_table = tree;
+ trav->avl_height = 0;
+ trav->avl_generation = tree->avl_generation;
- x = tree->avl_root;
- if (x != NULL)
- while (x->avl_link[0] != NULL)
- {
- assert (trav->avl_height < AVL_MAX_HEIGHT);
- trav->avl_stack[trav->avl_height++] = x;
- x = x->avl_link[0];
- }
- trav->avl_node = x;
+ x = tree->avl_root;
+ if (x != NULL)
+ while (x->avl_link[0] != NULL) {
+ assert(trav->avl_height < AVL_MAX_HEIGHT);
+ trav->avl_stack[trav->avl_height++] = x;
+ x = x->avl_link[0];
+ }
+ trav->avl_node = x;
- return x != NULL ? x->avl_data : NULL;
+ return x != NULL ? x->avl_data : NULL;
}
/* Initializes |trav| for |tree|
and selects and returns a pointer to its greatest-valued item.
Returns |NULL| if |tree| contains no nodes. */
-void *
-avl_t_last (struct avl_traverser *trav, struct avl_table *tree)
+void *avl_t_last(struct avl_traverser *trav, struct avl_table *tree)
{
- struct avl_node *x;
+ struct avl_node *x;
- assert (tree != NULL && trav != NULL);
+ assert(tree != NULL && trav != NULL);
- trav->avl_table = tree;
- trav->avl_height = 0;
- trav->avl_generation = tree->avl_generation;
+ trav->avl_table = tree;
+ trav->avl_height = 0;
+ trav->avl_generation = tree->avl_generation;
- x = tree->avl_root;
- if (x != NULL)
- while (x->avl_link[1] != NULL)
- {
- assert (trav->avl_height < AVL_MAX_HEIGHT);
- trav->avl_stack[trav->avl_height++] = x;
- x = x->avl_link[1];
- }
- trav->avl_node = x;
+ x = tree->avl_root;
+ if (x != NULL)
+ while (x->avl_link[1] != NULL) {
+ assert(trav->avl_height < AVL_MAX_HEIGHT);
+ trav->avl_stack[trav->avl_height++] = x;
+ x = x->avl_link[1];
+ }
+ trav->avl_node = x;
- return x != NULL ? x->avl_data : NULL;
+ return x != NULL ? x->avl_data : NULL;
}
/* Searches for |item| in |tree|.
@@ -489,36 +440,34 @@ avl_t_last (struct avl_traverser *trav, struct avl_table *tree)
as well.
If there is no matching item, initializes |trav| to the null item
and returns |NULL|. */
-void *
-avl_t_find (struct avl_traverser *trav, struct avl_table *tree, void *item)
+void *avl_t_find(struct avl_traverser *trav, struct avl_table *tree, void *item)
{
- struct avl_node *p, *q;
-
- assert (trav != NULL && tree != NULL && item != NULL);
- trav->avl_table = tree;
- trav->avl_height = 0;
- trav->avl_generation = tree->avl_generation;
- for (p = tree->avl_root; p != NULL; p = q)
- {
- int cmp = tree->avl_compare (item, p->avl_data, tree->avl_param);
-
- if (cmp < 0)
- q = p->avl_link[0];
- else if (cmp > 0)
- q = p->avl_link[1];
- else /* |cmp == 0| */
- {
- trav->avl_node = p;
- return p->avl_data;
+ struct avl_node *p, *q;
+
+ assert(trav != NULL && tree != NULL && item != NULL);
+ trav->avl_table = tree;
+ trav->avl_height = 0;
+ trav->avl_generation = tree->avl_generation;
+ for (p = tree->avl_root; p != NULL; p = q) {
+ int cmp = tree->avl_compare(item, p->avl_data, tree->avl_param);
+
+ if (cmp < 0)
+ q = p->avl_link[0];
+ else if (cmp > 0)
+ q = p->avl_link[1];
+ else { /* |cmp == 0| */
+
+ trav->avl_node = p;
+ return p->avl_data;
}
- assert (trav->avl_height < AVL_MAX_HEIGHT);
- trav->avl_stack[trav->avl_height++] = p;
+ assert(trav->avl_height < AVL_MAX_HEIGHT);
+ trav->avl_stack[trav->avl_height++] = p;
}
- trav->avl_height = 0;
- trav->avl_node = NULL;
- return NULL;
+ trav->avl_height = 0;
+ trav->avl_node = NULL;
+ return NULL;
}
/* Attempts to insert |item| into |tree|.
@@ -528,193 +477,166 @@ avl_t_find (struct avl_traverser *trav, struct avl_table *tree, void *item)
its location. No replacement of the item occurs.
If a memory allocation failure occurs, |NULL| is returned and |trav|
is initialized to the null item. */
-void *
-avl_t_insert (struct avl_traverser *trav, struct avl_table *tree, void *item)
+void *avl_t_insert(struct avl_traverser *trav, struct avl_table *tree,
+ void *item)
{
- void **p;
-
- assert (trav != NULL && tree != NULL && item != NULL);
-
- p = avl_probe (tree, item);
- if (p != NULL)
- {
- trav->avl_table = tree;
- trav->avl_node =
- ((struct avl_node *)
- ((char *) p - offsetof (struct avl_node, avl_data)));
- trav->avl_generation = tree->avl_generation - 1;
- return *p;
- }
- else
- {
- avl_t_init (trav, tree);
- return NULL;
+ void **p;
+
+ assert(trav != NULL && tree != NULL && item != NULL);
+
+ p = avl_probe(tree, item);
+ if (p != NULL) {
+ trav->avl_table = tree;
+ trav->avl_node = ((struct avl_node *)
+ ((char *) p - offsetof(struct avl_node, avl_data)));
+ trav->avl_generation = tree->avl_generation - 1;
+ return *p;
+ } else {
+ avl_t_init(trav, tree);
+ return NULL;
}
}
/* Initializes |trav| to have the same current node as |src|. */
-void *
-avl_t_copy (struct avl_traverser *trav, const struct avl_traverser *src)
+void *avl_t_copy(struct avl_traverser *trav, const struct avl_traverser *src)
{
- assert (trav != NULL && src != NULL);
-
- if (trav != src)
- {
- trav->avl_table = src->avl_table;
- trav->avl_node = src->avl_node;
- trav->avl_generation = src->avl_generation;
- if (trav->avl_generation == trav->avl_table->avl_generation)
- {
- trav->avl_height = src->avl_height;
- memcpy (trav->avl_stack, (const void *) src->avl_stack,
- sizeof *trav->avl_stack * trav->avl_height);
+ assert(trav != NULL && src != NULL);
+
+ if (trav != src) {
+ trav->avl_table = src->avl_table;
+ trav->avl_node = src->avl_node;
+ trav->avl_generation = src->avl_generation;
+ if (trav->avl_generation == trav->avl_table->avl_generation) {
+ trav->avl_height = src->avl_height;
+ memcpy(trav->avl_stack, (const void *) src->avl_stack,
+ sizeof *trav->avl_stack * trav->avl_height);
}
}
- return trav->avl_node != NULL ? trav->avl_node->avl_data : NULL;
+ return trav->avl_node != NULL ? trav->avl_node->avl_data : NULL;
}
/* Returns the next data item in inorder
within the tree being traversed with |trav|,
or if there are no more data items returns |NULL|. */
-void *
-avl_t_next (struct avl_traverser *trav)
+void *avl_t_next(struct avl_traverser *trav)
{
- struct avl_node *x;
+ struct avl_node *x;
- assert (trav != NULL);
+ assert(trav != NULL);
- if (trav->avl_generation != trav->avl_table->avl_generation)
- trav_refresh (trav);
+ if (trav->avl_generation != trav->avl_table->avl_generation)
+ trav_refresh(trav);
- x = trav->avl_node;
- if (x == NULL)
- {
- return avl_t_first (trav, trav->avl_table);
- }
- else if (x->avl_link[1] != NULL)
- {
- assert (trav->avl_height < AVL_MAX_HEIGHT);
- trav->avl_stack[trav->avl_height++] = x;
- x = x->avl_link[1];
-
- while (x->avl_link[0] != NULL)
- {
- assert (trav->avl_height < AVL_MAX_HEIGHT);
- trav->avl_stack[trav->avl_height++] = x;
- x = x->avl_link[0];
+ x = trav->avl_node;
+ if (x == NULL) {
+ return avl_t_first(trav, trav->avl_table);
+ } else if (x->avl_link[1] != NULL) {
+ assert(trav->avl_height < AVL_MAX_HEIGHT);
+ trav->avl_stack[trav->avl_height++] = x;
+ x = x->avl_link[1];
+
+ while (x->avl_link[0] != NULL) {
+ assert(trav->avl_height < AVL_MAX_HEIGHT);
+ trav->avl_stack[trav->avl_height++] = x;
+ x = x->avl_link[0];
}
- }
- else
- {
- struct avl_node *y;
-
- do
- {
- if (trav->avl_height == 0)
- {
- trav->avl_node = NULL;
- return NULL;
+ } else {
+ struct avl_node *y;
+
+ do {
+ if (trav->avl_height == 0) {
+ trav->avl_node = NULL;
+ return NULL;
}
- y = x;
- x = trav->avl_stack[--trav->avl_height];
+ y = x;
+ x = trav->avl_stack[--trav->avl_height];
}
- while (y == x->avl_link[1]);
+ while (y == x->avl_link[1]);
}
- trav->avl_node = x;
+ trav->avl_node = x;
- return x->avl_data;
+ return x->avl_data;
}
/* Returns the previous data item in inorder
within the tree being traversed with |trav|,
or if there are no more data items returns |NULL|. */
-void *
-avl_t_prev (struct avl_traverser *trav)
+void *avl_t_prev(struct avl_traverser *trav)
{
- struct avl_node *x;
+ struct avl_node *x;
- assert (trav != NULL);
+ assert(trav != NULL);
- if (trav->avl_generation != trav->avl_table->avl_generation)
- trav_refresh (trav);
+ if (trav->avl_generation != trav->avl_table->avl_generation)
+ trav_refresh(trav);
- x = trav->avl_node;
- if (x == NULL)
- {
- return avl_t_last (trav, trav->avl_table);
- }
- else if (x->avl_link[0] != NULL)
- {
- assert (trav->avl_height < AVL_MAX_HEIGHT);
- trav->avl_stack[trav->avl_height++] = x;
- x = x->avl_link[0];
-
- while (x->avl_link[1] != NULL)
- {
- assert (trav->avl_height < AVL_MAX_HEIGHT);
- trav->avl_stack[trav->avl_height++] = x;
- x = x->avl_link[1];
+ x = trav->avl_node;
+ if (x == NULL) {
+ return avl_t_last(trav, trav->avl_table);
+ } else if (x->avl_link[0] != NULL) {
+ assert(trav->avl_height < AVL_MAX_HEIGHT);
+ trav->avl_stack[trav->avl_height++] = x;
+ x = x->avl_link[0];
+
+ while (x->avl_link[1] != NULL) {
+ assert(trav->avl_height < AVL_MAX_HEIGHT);
+ trav->avl_stack[trav->avl_height++] = x;
+ x = x->avl_link[1];
}
- }
- else
- {
- struct avl_node *y;
-
- do
- {
- if (trav->avl_height == 0)
- {
- trav->avl_node = NULL;
- return NULL;
+ } else {
+ struct avl_node *y;
+
+ do {
+ if (trav->avl_height == 0) {
+ trav->avl_node = NULL;
+ return NULL;
}
- y = x;
- x = trav->avl_stack[--trav->avl_height];
+ y = x;
+ x = trav->avl_stack[--trav->avl_height];
}
- while (y == x->avl_link[0]);
+ while (y == x->avl_link[0]);
}
- trav->avl_node = x;
+ trav->avl_node = x;
- return x->avl_data;
+ return x->avl_data;
}
/* Returns |trav|'s current item. */
-void *
-avl_t_cur (struct avl_traverser *trav)
+void *avl_t_cur(struct avl_traverser *trav)
{
- assert (trav != NULL);
+ assert(trav != NULL);
- return trav->avl_node != NULL ? trav->avl_node->avl_data : NULL;
+ return trav->avl_node != NULL ? trav->avl_node->avl_data : NULL;
}
/* Replaces the current item in |trav| by |new| and returns the item replaced.
|trav| must not have the null item selected.
The new item must not upset the ordering of the tree. */
-void *
-avl_t_replace (struct avl_traverser *trav, void *new)
+void *avl_t_replace(struct avl_traverser *trav, void *new)
{
- void *old;
+ void *old;
- assert (trav != NULL && trav->avl_node != NULL && new != NULL);
- old = trav->avl_node->avl_data;
- trav->avl_node->avl_data = new;
- return old;
+ assert(trav != NULL && trav->avl_node != NULL && new != NULL);
+ old = trav->avl_node->avl_data;
+ trav->avl_node->avl_data = new;
+ return old;
}
/* Destroys |new| with |avl_destroy (new, destroy)|,
first setting right links of nodes in |stack| within |new|
to null pointers to avoid touching uninitialized data. */
static void
-copy_error_recovery (struct avl_node **stack, int height,
- struct avl_table *new, avl_item_func *destroy)
+copy_error_recovery(struct avl_node **stack, int height,
+ struct avl_table *new, avl_item_func * destroy)
{
- assert (stack != NULL && height >= 0 && new != NULL);
+ assert(stack != NULL && height >= 0 && new != NULL);
- for (; height > 2; height -= 2)
- stack[height - 1]->avl_link[1] = NULL;
- avl_destroy (new, destroy);
+ for (; height > 2; height -= 2)
+ stack[height - 1]->avl_link[1] = NULL;
+ avl_destroy(new, destroy);
}
/* Copies |org| to a newly created tree, which is returned.
@@ -726,168 +648,147 @@ copy_error_recovery (struct avl_node **stack, int height,
and returns |NULL|.
If |allocator != NULL|, it is used for allocation in the new tree.
Otherwise, the same allocator used for |org| is used. */
-struct avl_table *
-avl_copy (const struct avl_table *org, avl_copy_func *copy,
- avl_item_func *destroy, struct libavl_allocator *allocator)
+struct avl_table *avl_copy(const struct avl_table *org, avl_copy_func * copy,
+ avl_item_func * destroy,
+ struct libavl_allocator *allocator)
{
- struct avl_node *stack[2 * (AVL_MAX_HEIGHT + 1)];
- int height = 0;
+ struct avl_node *stack[2 * (AVL_MAX_HEIGHT + 1)];
+ int height = 0;
- struct avl_table *new;
- const struct avl_node *x;
- struct avl_node *y;
+ struct avl_table *new;
+ const struct avl_node *x;
+ struct avl_node *y;
- assert (org != NULL);
- new = avl_create (org->avl_compare, org->avl_param,
- allocator != NULL ? allocator : org->avl_alloc);
- if (new == NULL)
- return NULL;
- new->avl_count = org->avl_count;
- if (new->avl_count == 0)
- return new;
-
- x = (const struct avl_node *) &org->avl_root;
- y = (struct avl_node *) &new->avl_root;
- for (;;)
- {
- while (x->avl_link[0] != NULL)
- {
- assert (height < 2 * (AVL_MAX_HEIGHT + 1));
-
- y->avl_link[0] =
- new->avl_alloc->libavl_malloc (new->avl_alloc,
- sizeof *y->avl_link[0]);
- if (y->avl_link[0] == NULL)
- {
- if (y != (struct avl_node *) &new->avl_root)
- {
- y->avl_data = NULL;
- y->avl_link[1] = NULL;
+ assert(org != NULL);
+ new = avl_create(org->avl_compare, org->avl_param,
+ allocator != NULL ? allocator : org->avl_alloc);
+ if (new == NULL)
+ return NULL;
+ new->avl_count = org->avl_count;
+ if (new->avl_count == 0)
+ return new;
+
+ x = (const struct avl_node *) &org->avl_root;
+ y = (struct avl_node *) &new->avl_root;
+ for (;;) {
+ while (x->avl_link[0] != NULL) {
+ assert(height < 2 * (AVL_MAX_HEIGHT + 1));
+
+ y->avl_link[0] =
+ new->avl_alloc->libavl_malloc(new->avl_alloc,
+ sizeof *y->avl_link[0]);
+ if (y->avl_link[0] == NULL) {
+ if (y != (struct avl_node *) &new->avl_root) {
+ y->avl_data = NULL;
+ y->avl_link[1] = NULL;
}
- copy_error_recovery (stack, height, new, destroy);
- return NULL;
+ copy_error_recovery(stack, height, new, destroy);
+ return NULL;
}
- stack[height++] = (struct avl_node *) x;
- stack[height++] = y;
- x = x->avl_link[0];
- y = y->avl_link[0];
+ stack[height++] = (struct avl_node *) x;
+ stack[height++] = y;
+ x = x->avl_link[0];
+ y = y->avl_link[0];
}
- y->avl_link[0] = NULL;
-
- for (;;)
- {
- y->avl_balance = x->avl_balance;
- if (copy == NULL)
- y->avl_data = x->avl_data;
- else
- {
- y->avl_data = copy (x->avl_data, org->avl_param);
- if (y->avl_data == NULL)
- {
- y->avl_link[1] = NULL;
- copy_error_recovery (stack, height, new, destroy);
- return NULL;
+ y->avl_link[0] = NULL;
+
+ for (;;) {
+ y->avl_balance = x->avl_balance;
+ if (copy == NULL)
+ y->avl_data = x->avl_data;
+ else {
+ y->avl_data = copy(x->avl_data, org->avl_param);
+ if (y->avl_data == NULL) {
+ y->avl_link[1] = NULL;
+ copy_error_recovery(stack, height, new, destroy);
+ return NULL;
}
}
- if (x->avl_link[1] != NULL)
- {
- y->avl_link[1] =
- new->avl_alloc->libavl_malloc (new->avl_alloc,
- sizeof *y->avl_link[1]);
- if (y->avl_link[1] == NULL)
- {
- copy_error_recovery (stack, height, new, destroy);
- return NULL;
+ if (x->avl_link[1] != NULL) {
+ y->avl_link[1] =
+ new->avl_alloc->libavl_malloc(new->avl_alloc,
+ sizeof *y->avl_link[1]);
+ if (y->avl_link[1] == NULL) {
+ copy_error_recovery(stack, height, new, destroy);
+ return NULL;
}
- x = x->avl_link[1];
- y = y->avl_link[1];
- break;
- }
- else
- y->avl_link[1] = NULL;
+ x = x->avl_link[1];
+ y = y->avl_link[1];
+ break;
+ } else
+ y->avl_link[1] = NULL;
- if (height <= 2)
- return new;
+ if (height <= 2)
+ return new;
- y = stack[--height];
- x = stack[--height];
+ y = stack[--height];
+ x = stack[--height];
}
}
}
/* Frees storage allocated for |tree|.
If |destroy != NULL|, applies it to each data item in inorder. */
-void
-avl_destroy (struct avl_table *tree, avl_item_func *destroy)
+void avl_destroy(struct avl_table *tree, avl_item_func * destroy)
{
- struct avl_node *p, *q;
-
- assert (tree != NULL);
-
- for (p = tree->avl_root; p != NULL; p = q)
- if (p->avl_link[0] == NULL)
- {
- q = p->avl_link[1];
- if (destroy != NULL && p->avl_data != NULL)
- destroy (p->avl_data, tree->avl_param);
- tree->avl_alloc->libavl_free (tree->avl_alloc, p);
- }
- else
- {
- q = p->avl_link[0];
- p->avl_link[0] = q->avl_link[1];
- q->avl_link[1] = p;
- }
-
- tree->avl_alloc->libavl_free (tree->avl_alloc, tree);
+ struct avl_node *p, *q;
+
+ assert(tree != NULL);
+
+ for (p = tree->avl_root; p != NULL; p = q)
+ if (p->avl_link[0] == NULL) {
+ q = p->avl_link[1];
+ if (destroy != NULL && p->avl_data != NULL)
+ destroy(p->avl_data, tree->avl_param);
+ tree->avl_alloc->libavl_free(tree->avl_alloc, p);
+ } else {
+ q = p->avl_link[0];
+ p->avl_link[0] = q->avl_link[1];
+ q->avl_link[1] = p;
+ }
+
+ tree->avl_alloc->libavl_free(tree->avl_alloc, tree);
}
/* Allocates |size| bytes of space using |malloc()|.
Returns a null pointer if allocation fails. */
-void *
-avl_malloc (struct libavl_allocator *allocator, size_t size)
+void *avl_malloc(struct libavl_allocator *allocator, size_t size)
{
- assert (allocator != NULL && size > 0);
- return malloc (size);
+ assert(allocator != NULL && size > 0);
+ return malloc(size);
}
/* Frees |block|. */
-void
-avl_free (struct libavl_allocator *allocator, void *block)
+void avl_free(struct libavl_allocator *allocator, void *block)
{
- assert (allocator != NULL && block != NULL);
- free (block);
+ assert(allocator != NULL && block != NULL);
+ free(block);
}
/* Default memory allocator that uses |malloc()| and |free()|. */
-struct libavl_allocator avl_allocator_default =
- {
+struct libavl_allocator avl_allocator_default = {
avl_malloc,
avl_free
- };
+};
#undef NDEBUG
#include <assert.h>
/* Asserts that |avl_insert()| succeeds at inserting |item| into |table|. */
void
-(avl_assert_insert) (struct avl_table *table, void *item)
-{
- void **p = avl_probe (table, item);
- assert (p != NULL && *p == item);
+ (avl_assert_insert) (struct avl_table * table, void *item) {
+ void **p = avl_probe(table, item);
+ assert(p != NULL && *p == item);
}
/* Asserts that |avl_delete()| really removes |item| from |table|,
and returns the removed item. */
-void *
-(avl_assert_delete) (struct avl_table *table, void *item)
-{
- void *p = avl_delete (table, item);
- assert (p != NULL);
- return p;
+void *(avl_assert_delete) (struct avl_table * table, void *item) {
+ void *p = avl_delete(table, item);
+ assert(p != NULL);
+ return p;
}
-
diff --git a/Build/source/texk/web2c/pdftexdir/avlstuff.c b/Build/source/texk/web2c/pdftexdir/avlstuff.c
index 1a05c762eb1..8b0ae737477 100644
--- a/Build/source/texk/web2c/pdftexdir/avlstuff.c
+++ b/Build/source/texk/web2c/pdftexdir/avlstuff.c
@@ -1,5 +1,5 @@
/*
-Copyright (c) 2004-2005 Han The Thanh, <thanh@pdftex.org>
+Copyright (c) 2004-2007 Han The Thanh, <thanh@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
@@ -12,10 +12,10 @@ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License along
-with this file; if not, write to the Free Software Foundation, Inc.,
-59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+with pdfTeX; if not, write to the Free Software Foundation, Inc., 51
+Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-$Id: avlstuff.c,v 1.12 2005/07/11 20:27:39 hahe Exp hahe $
+$Id: avlstuff.c 200 2007-07-11 13:11:12Z oneiros $
*/
diff --git a/Build/source/texk/web2c/pdftexdir/avlstuff.h b/Build/source/texk/web2c/pdftexdir/avlstuff.h
index 2ffa57b627d..2dc4d8c277b 100644
--- a/Build/source/texk/web2c/pdftexdir/avlstuff.h
+++ b/Build/source/texk/web2c/pdftexdir/avlstuff.h
@@ -1,5 +1,5 @@
/*
-Copyright (c) 2004 Han The Thanh, <thanh@pdftex.org>
+Copyright (c) 2004-2007 Han The Thanh, <thanh@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
@@ -12,12 +12,10 @@ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License along
-with this file; if not, write to the Free Software Foundation, Inc.,
-59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+with pdfTeX; if not, write to the Free Software Foundation, Inc., 51
+Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/avlstuff.h#5 $
-
-formatted by indent -kr
+$Id: avlstuff.h 200 2007-07-11 13:11:12Z oneiros $
*/
#include "avl.h"
diff --git a/Build/source/texk/web2c/pdftexdir/epdf.c b/Build/source/texk/web2c/pdftexdir/epdf.c
index 1b13c2b0d8c..53164e66ae2 100644
--- a/Build/source/texk/web2c/pdftexdir/epdf.c
+++ b/Build/source/texk/web2c/pdftexdir/epdf.c
@@ -1,5 +1,5 @@
/*
-Copyright (c) 1996-2002 Han The Thanh, <thanh@pdftex.org>
+Copyright (c) 1996-2007 Han The Thanh, <thanh@pdftex.org>
This file is part of pdfTeX.
@@ -13,11 +13,11 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
-You should have received a copy of the GNU General Public License
-along with pdfTeX; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+You should have received a copy of the GNU General Public License along
+with pdfTeX; if not, write to the Free Software Foundation, Inc., 51
+Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-$Id: epdf.c,v 1.45 2006/08/20 10:56:04 hahe Exp hahe $
+$Id: epdf.c 200 2007-07-11 13:11:12Z oneiros $
*/
#include "ptexlib.h"
diff --git a/Build/source/texk/web2c/pdftexdir/epdf.h b/Build/source/texk/web2c/pdftexdir/epdf.h
index 0a13d59df34..3a6265cf679 100644
--- a/Build/source/texk/web2c/pdftexdir/epdf.h
+++ b/Build/source/texk/web2c/pdftexdir/epdf.h
@@ -1,5 +1,5 @@
/*
-Copyright (c) 1996-2006 Han The Thanh, <thanh@pdftex.org>
+Copyright (c) 1996-2007 Han The Thanh, <thanh@pdftex.org>
This file is part of pdfTeX.
@@ -13,11 +13,11 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
-You should have received a copy of the GNU General Public License
-along with pdfTeX; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+You should have received a copy of the GNU General Public License along
+with pdfTeX; if not, write to the Free Software Foundation, Inc., 51
+Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-$Id: epdf.h,v 1.6 2005/11/28 23:29:32 hahe Exp $
+$Id: epdf.h 200 2007-07-11 13:11:12Z oneiros $
*/
extern "C" {
@@ -72,6 +72,7 @@ extern "C" {
extern integer pdfbufsize;
extern integer pdfosmode;
extern eightbits pdflastbyte;
+ extern integer fixedinclusioncopyfont;
extern char notdef[];
diff --git a/Build/source/texk/web2c/pdftexdir/image.h b/Build/source/texk/web2c/pdftexdir/image.h
index 8907e50f603..b8468af5dd2 100644
--- a/Build/source/texk/web2c/pdftexdir/image.h
+++ b/Build/source/texk/web2c/pdftexdir/image.h
@@ -1,5 +1,5 @@
/*
-Copyright (c) 1996-2002 Han The Thanh, <thanh@pdftex.org>
+Copyright (c) 1996-2007 Han The Thanh, <thanh@pdftex.org>
This file is part of pdfTeX.
@@ -13,11 +13,11 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
-You should have received a copy of the GNU General Public License
-along with pdfTeX; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+You should have received a copy of the GNU General Public License along
+with pdfTeX; if not, write to the Free Software Foundation, Inc., 51
+Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/image.h#10 $
+$Id: image.h 200 2007-07-11 13:11:12Z oneiros $
*/
#include <png.h>
diff --git a/Build/source/texk/web2c/pdftexdir/macnames.c b/Build/source/texk/web2c/pdftexdir/macnames.c
index fe9fbf8151d..20a4d2b5381 100644
--- a/Build/source/texk/web2c/pdftexdir/macnames.c
+++ b/Build/source/texk/web2c/pdftexdir/macnames.c
@@ -1,5 +1,5 @@
/*
-Copyright (c) 1996-2002 Han The Thanh, <thanh@pdftex.org>
+Copyright (c) 1996-2007 Han The Thanh, <thanh@pdftex.org>
This file is part of pdfTeX.
@@ -13,11 +13,11 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
-You should have received a copy of the GNU General Public License
-along with pdfTeX; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+You should have received a copy of the GNU General Public License along
+with pdfTeX; if not, write to the Free Software Foundation, Inc., 51
+Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/macnames.c#5 $
+$Id: macnames.c 200 2007-07-11 13:11:12Z oneiros $
*/
const char notdef[] = ".notdef";
diff --git a/Build/source/texk/web2c/pdftexdir/mapfile.c b/Build/source/texk/web2c/pdftexdir/mapfile.c
index 5ac8d51ebfa..87d56f8ea7c 100644
--- a/Build/source/texk/web2c/pdftexdir/mapfile.c
+++ b/Build/source/texk/web2c/pdftexdir/mapfile.c
@@ -1,5 +1,5 @@
/*
-Copyright (c) 1996-2006 Han The Thanh, <thanh@pdftex.org>
+Copyright (c) 1996-2007 Han The Thanh, <thanh@pdftex.org>
This file is part of pdfTeX.
@@ -13,11 +13,11 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
-You should have received a copy of the GNU General Public License
-along with pdfTeX; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+You should have received a copy of the GNU General Public License along
+with pdfTeX; if not, write to the Free Software Foundation, Inc., 51
+Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-$Id: mapfile.c,v 1.1 2006/12/14 01:21:33 hahe Exp hahe $
+$Id: mapfile.c 200 2007-07-11 13:11:12Z oneiros $
*/
#include <math.h>
@@ -71,7 +71,7 @@ fm_entry *new_fm_entry(void)
fm->tfm_name = NULL;
fm->sfd_name = NULL;
fm->ps_name = NULL;
- fm->fd_flags = 4;
+ fm->fd_flags = FD_FLAGS_NOT_SET_IN_MAPLINE;
fm->ff_name = NULL;
fm->encname = NULL;
fm->type = 0;
@@ -347,9 +347,9 @@ int check_fm_entry(fm_entry * fm, boolean warn)
}
/**********************************************************************/
-/* returns true if s is one of the 14 std. font names; speed-trimmed. */
+/* returns the font number if s is one of the 14 std. font names, -1 otherwise; speed-trimmed. */
-boolean check_std_t1font(char *s)
+int check_std_t1font(char *s)
{
static const char *std_t1font_names[] = {
"Courier", /* 0:7 */
@@ -371,6 +371,7 @@ boolean check_std_t1font(char *s)
{ -1, -1, -1, -1, -1, -1, 8, 0, -1, 4, 10, 9, -1, -1, 5, 2, 12, 6, -1,
3, -1, 7
};
+ assert(s != NULL);
const size_t n = strlen(s);
int k = -1;
if (n > 21)
@@ -392,11 +393,10 @@ boolean check_std_t1font(char *s)
} else
k = index[n];
if (k > -1 && strcmp(std_t1font_names[k], s) == 0)
- return true;
- return false;
+ return k;
+ return -1;
};
-
/**********************************************************************/
static void fm_scan_line()
@@ -526,7 +526,7 @@ static void fm_scan_line()
}
}
done:
- if (fm->ps_name != NULL && check_std_t1font(fm->ps_name))
+ if (fm->ps_name != NULL && (check_std_t1font(fm->ps_name) >= 0))
set_std_t1font(fm);
if (is_fontfile(fm)) {
if (strcasecmp(strend(fm_fontfile(fm)) - 4, ".ttf") == 0)
@@ -891,3 +891,4 @@ void fm_free(void)
/**********************************************************************/
/* end of mapfile.c */
+// vim: ts=4
diff --git a/Build/source/texk/web2c/pdftexdir/pdftex.ch b/Build/source/texk/web2c/pdftexdir/pdftex.ch
index 31211b2477f..975559f01b9 100644
--- a/Build/source/texk/web2c/pdftexdir/pdftex.ch
+++ b/Build/source/texk/web2c/pdftexdir/pdftex.ch
@@ -1,5 +1,5 @@
%
-% Copyright (c) 1996-2006 Han The Thanh, <thanh@pdftex.org>
+% Copyright (c) 1996-2007 Han The Thanh, <thanh@pdftex.org>
%
% This file is part of pdfTeX.
%
@@ -13,11 +13,11 @@
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
-% You should have received a copy of the GNU General Public License
-% along with pdfTeX; if not, write to the Free Software
-% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+% You should have received a copy of the GNU General Public License along with
+% pdfTeX; if not, write to the Free Software Foundation, Inc., 51 Franklin
+% Street, Fifth Floor, Boston, MA 02110-1301 USA.
%
-% $Id: //depot/Build/source.development/TeX/texk/web2c/pdfetexdir/pdfetex.ch2#20 $
+% $Id: pdftex.ch 200 2007-07-11 13:11:12Z oneiros $
%
@x [0.0] l.83 - WEAVE: we want the whole file
\def\?##1]{\hbox{Changes to \hbox to 1em{\hfil##1}.\ }}
diff --git a/Build/source/texk/web2c/pdftexdir/pdftex.defines b/Build/source/texk/web2c/pdftexdir/pdftex.defines
index 977b472e168..7b5a52b4c69 100644
--- a/Build/source/texk/web2c/pdftexdir/pdftex.defines
+++ b/Build/source/texk/web2c/pdftexdir/pdftex.defines
@@ -1,5 +1,5 @@
{
-Copyright (c) 1996-2006 Han The Thanh, <thanh@pdftex.org>
+Copyright (c) 1996-2007 Han The Thanh, <thanh@pdftex.org>
This file is part of pdfTeX.
@@ -13,11 +13,11 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
-You should have received a copy of the GNU General Public License
-along with pdfTeX; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+You should have received a copy of the GNU General Public License along
+with pdfTeX; if not, write to the Free Software Foundation, Inc., 51
+Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/pdftex.defines#15 $
+$Id: pdftex.defines 200 2007-07-11 13:11:12Z oneiros $
}
{ pdftex.defines: additions for pdfTeX }
@@ -98,6 +98,7 @@ $Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/pdftex.defines#15
@define function packetbyte;
@define procedure startpacket();
@define procedure storepacket();
+@define function sqxfw();
{ functions from writefont.c }
@define procedure dopdffont();
@@ -121,6 +122,9 @@ $Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/pdftex.defines#15
@define procedure updateimageprocset();
@define procedure writeimage();
+@define procedure dumpimagemeta;
+@define procedure undumpimagemeta();
+
{ functions from writet3.c }
@define function getpkcharwidth();
@@ -134,5 +138,8 @@ $Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/pdftex.defines#15
{ functions from tounicode.c }
@define procedure deftounicode();
+{ functions from pdftex.web (thanks Taco for the trick) }
+@define function autoexpandvf();
+
{ end of pdftex.defines }
{ vim: set syntax=web : }
diff --git a/Build/source/texk/web2c/pdftexdir/pdftex.h b/Build/source/texk/web2c/pdftexdir/pdftex.h
index 805301fc633..f9c7c30e315 100644
--- a/Build/source/texk/web2c/pdftexdir/pdftex.h
+++ b/Build/source/texk/web2c/pdftexdir/pdftex.h
@@ -1,5 +1,5 @@
/*
-Copyright (c) 1996-2006 Han The Thanh, <thanh@pdftex.org>
+Copyright (c) 1996-2007 Han The Thanh, <thanh@pdftex.org>
This file is part of pdfTeX.
@@ -13,11 +13,11 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
-You should have received a copy of the GNU General Public License
-along with pdfTeX; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+You should have received a copy of the GNU General Public License along
+with pdfTeX; if not, write to the Free Software Foundation, Inc., 51
+Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/pdftex.h#4 $
+$Id: pdftex.h 200 2007-07-11 13:11:12Z oneiros $
*/
/* Additions to texmfmp.h for pdfTeX */
diff --git a/Build/source/texk/web2c/pdftexdir/pdftex.web b/Build/source/texk/web2c/pdftexdir/pdftex.web
index 693a347d447..b005393e757 100644
--- a/Build/source/texk/web2c/pdftexdir/pdftex.web
+++ b/Build/source/texk/web2c/pdftexdir/pdftex.web
@@ -1,4 +1,4 @@
-% Copyright (c) 1996-2006 Han Th\^e\llap{\raise 0.5ex\hbox{\'{}}} Th\`anh, <thanh@@pdftex.org>
+% Copyright (c) 1996-2007 Han Th\^e\llap{\raise 0.5ex\hbox{\'{}}} Th\`anh, <thanh@@pdftex.org>
% This file is part of pdfTeX.
@@ -12,8 +12,8 @@
% A PARTICULAR PURPOSE. See the GNU General Public License for more details.
% You should have received a copy of the GNU General Public License along with
-% pdfTeX; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
-% Suite 330, Boston, MA 02111-1307 USA
+% pdfTeX; if not, write to the Free Software Foundation, Inc., 51 Franklin
+% Street, Fifth Floor, Boston, MA 02110-1301 USA.
% e-TeX is copyright (C) 1994,98 by Peter Breitenlohner; all rights are
% reserved. Copying of this file is authorized only if (1) you are Peter
@@ -286,8 +286,8 @@ known as `\eTeX'.
{printed when \eTeX\ starts}
@#
@d pdftex_version==140 { \.{\\pdftexversion} }
-@d pdftex_revision=="3" { \.{\\pdftexrevision} }
-@d pdftex_version_string=='-1.40.3' {current \pdfTeX\ version}
+@d pdftex_revision=="4" { \.{\\pdftexrevision} }
+@d pdftex_version_string=='-1.40.4' {current \pdfTeX\ version}
@#
@d pdfeTeX_banner=='This is pdfeTeX, Version 3.141592',pdftex_version_string,eTeX_version_string
{printed when \pdfeTeX\ starts}
@@ -4781,7 +4781,8 @@ that might be expanded by `\.{\\the}'.
@d hyph_data=99 {hyphenation data ( \.{\\hyphenation}, \.{\\patterns} )}
@d set_interaction=100 {define level of interaction ( \.{\\batchmode}, etc.~)}
@d letterspace_font=101 {letterspace a font ( \.{\\letterspacefont} )}
-@d max_command=101 {the largest command code seen at |big_switch|}
+@d pdf_copy_font=102 {create a new font instance ( \.{\\pdfcopyfont} )}
+@d max_command=102 {the largest command code seen at |big_switch|}
@ The remaining command codes are extra special, since they cannot get through
\TeX's scanner to the main control routine. They have been given values higher
@@ -4919,7 +4920,7 @@ level is kept in the global quantities |mode|, |head|, |tail|, |prev_graf|,
|aux|, and |mode_line|, which live in a \PASCAL\ record that is ready to
be pushed onto |nest| if necessary.
-@d ignore_depth==-65536000 {|prev_depth| value that is ignored}
+@d ignore_depth==-65536000 {magic dimension value to mean `ignore me'}
@<Types...@>=
@!list_state_record=record@!mode_field:-mmode..mmode;@+
@@ -5033,7 +5034,7 @@ end;
@ @<Show the auxiliary...@>=
case abs(m) div (max_command+1) of
0: begin print_nl("prevdepth ");
- if a.sc<=ignore_depth then print("ignored")
+ if a.sc<=pdf_ignored_dimen then print("ignored")
else print_scaled(a.sc);
if nest[p].pg_field<>0 then
begin print(", prevgraf ");
@@ -5658,7 +5659,8 @@ that will be defined later.
@d pdf_append_kern_code = pdftex_first_integer_code + 23 {append kern before certain characters?}
@d pdf_gen_tounicode_code = pdftex_first_integer_code + 24 {generate ToUnicode for fonts?}
@d pdf_draftmode_code = pdftex_first_integer_code + 25 {switch on draftmode if positive}
-@d pdf_int_pars=pdftex_first_integer_code + 26 {total number of \pdfTeX's integer parameters}
+@d pdf_inclusion_copy_font_code = pdftex_first_integer_code + 26 {generate ToUnicode for fonts?}
+@d pdf_int_pars=pdftex_first_integer_code + 27 {total number of \pdfTeX's integer parameters}
@#
@d etex_int_base=pdf_int_pars {base for \eTeX's integer parameters}
@d tracing_assigns_code=etex_int_base {show assignments}
@@ -5763,6 +5765,7 @@ that will be defined later.
@d pdf_image_hicolor == int_par(pdf_image_hicolor_code)
@d pdf_image_apply_gamma == int_par(pdf_image_apply_gamma_code)
@d pdf_draftmode == int_par(pdf_draftmode_code)
+@d pdf_inclusion_copy_font == int_par(pdf_inclusion_copy_font_code)
@#
@d tracing_assigns==int_par(tracing_assigns_code)
@d tracing_groups==int_par(tracing_groups_code)
@@ -5864,6 +5867,7 @@ pdf_prepend_kern_code: print_esc("pdfprependkern");
pdf_append_kern_code: print_esc("pdfappendkern");
pdf_gen_tounicode_code: print_esc("pdfgentounicode");
pdf_draftmode_code: print_esc("pdfdraftmode");
+pdf_inclusion_copy_font_code: print_esc("pdfinclusioncopyfonts");
@/@<Cases for |print_param|@>@/
othercases print("[unknown integer parameter!]")
endcases;
@@ -6039,6 +6043,8 @@ primitive("pdfgentounicode",assign_int,int_base+pdf_gen_tounicode_code);@/
@!@:pdf_gen_tounicode_}{\.{\\pdfgentounicode} primitive@>
primitive("pdfdraftmode",assign_int,int_base+pdf_draftmode_code);@/
@!@:pdf_draftmode_}{\.{\\pdfdraftmode} primitive@>
+primitive("pdfinclusioncopyfonts",assign_int,int_base+pdf_inclusion_copy_font_code);@/
+@!@:pdf_inclusion_copy_font_}{\.{\\pdfinclusioncopyfonts} primitive@>
@ @<Cases of |print_cmd_chr|...@>=
assign_int: if chr_code<count_base then print_param(chr_code-int_base)
@@ -6146,8 +6152,9 @@ here, and the 256 \.{\\dimen} registers.
@d pdf_last_line_depth_code = pdftex_first_dimen_code + 8
@d pdf_each_line_height_code = pdftex_first_dimen_code + 9
@d pdf_each_line_depth_code = pdftex_first_dimen_code + 10
-@d pdf_px_dimen_code = pdftex_first_dimen_code + 11
-@d pdftex_last_dimen_code = pdftex_first_dimen_code + 11 {last number defined in this section}
+@d pdf_ignored_dimen_code = pdftex_first_dimen_code + 11
+@d pdf_px_dimen_code = pdftex_first_dimen_code + 12
+@d pdftex_last_dimen_code = pdftex_first_dimen_code + 12 {last number defined in this section}
@d dimen_pars = pdftex_last_dimen_code + 1 {total number of dimension parameters}
@d scaled_base=dimen_base+dimen_pars
{table of 256 user-defined \.{\\dimen} registers}
@@ -6187,6 +6194,7 @@ here, and the 256 \.{\\dimen} registers.
@d pdf_last_line_depth == dimen_par(pdf_last_line_depth_code)
@d pdf_each_line_height == dimen_par(pdf_each_line_height_code)
@d pdf_each_line_depth == dimen_par(pdf_each_line_depth_code)
+@d pdf_ignored_dimen == dimen_par(pdf_ignored_dimen_code)
@d pdf_px_dimen == dimen_par(pdf_px_dimen_code)
@p procedure print_length_param(@!n:integer);
@@ -6223,6 +6231,7 @@ pdf_first_line_height_code: print_esc("pdffirstlineheight");
pdf_last_line_depth_code: print_esc("pdflastlinedepth");
pdf_each_line_height_code: print_esc("pdfeachlineheight");
pdf_each_line_depth_code: print_esc("pdfeachlinedepth");
+pdf_ignored_dimen_code: print_esc("pdfignoreddimen");
pdf_px_dimen_code: print_esc("pdfpxdimen");
othercases print("[unknown dimen parameter!]")
endcases;
@@ -6295,6 +6304,8 @@ primitive("pdfeachlineheight",assign_dimen,dimen_base+pdf_each_line_height_code)
@!@:pdf_each_line_height_}{\.{\\pdfeachlineheight} primitive@>
primitive("pdfeachlinedepth",assign_dimen,dimen_base+pdf_each_line_depth_code);@/
@!@:pdf_each_line_depth_}{\.{\\pdfeachlinedepth} primitive@>
+primitive("pdfignoreddimen",assign_dimen,dimen_base+pdf_ignored_dimen_code);@/
+@!@:pdf_ignored_dimen_}{\.{\\pdfignoreddimen} primitive@>
primitive("pdfpxdimen",assign_dimen,dimen_base+pdf_px_dimen_code);@/
@!@:pdf_px_dimen_}{\.{\\pdfpxdimen} primitive@>
@@ -6662,6 +6673,8 @@ primitive("font",def_font,0);@/
@!@:font_}{\.{\\font} primitive@>
primitive("letterspacefont",letterspace_font,0);@/
@!@:letterspace_font_}{\.{\\letterspacefont} primitive@>
+primitive("pdfcopyfont",pdf_copy_font,0);@/
+@!@:pdf_copy_font_}{\.{\\pdfcopyfont} primitive@>
primitive("fontdimen",assign_font_dimen,0);@/
@!@:font_dimen_}{\.{\\fontdimen} primitive@>
primitive("halign",halign,0);@/
@@ -6740,6 +6753,7 @@ char_num: print_esc("char");
cs_name: print_esc("csname");
def_font: print_esc("font");
letterspace_font: print_esc("letterspacefont");
+pdf_copy_font: print_esc("pdfcopyfont");
delim_num: print_esc("delimiter");
divide: print_esc("divide");
end_cs_name: print_esc("endcsname");
@@ -8856,8 +8870,9 @@ if cur_cs < hash_base then
else
cur_cs := prim_lookup(text(cur_cs));
if cur_cs<>undefined_primitive then begin
- if cur_cmd>max_command then begin
- cur_cmd := prim_eq_type(cur_cs);
+ t := prim_eq_type(cur_cs);
+ if t>max_command then begin
+ cur_cmd := t;
cur_chr := prim_equiv(cur_cs);
cur_tok := (cur_cmd*@'400)+cur_chr;
cur_cs := 0;
@@ -9524,7 +9539,7 @@ var m:halfword; {|chr_code| part of the operand token}
begin m:=cur_chr;
case cur_cmd of
def_code: @<Fetch a character code from some table@>;
-toks_register,assign_toks,def_family,set_font,def_font,letterspace_font: @<Fetch a token list or
+toks_register,assign_toks,def_family,set_font,def_font,letterspace_font,pdf_copy_font: @<Fetch a token list or
font identifier, provided that |level=tok_val|@>;
assign_int: scanned_result(eqtb[m].int)(int_val);
assign_dimen: scanned_result(eqtb[m].sc)(dimen_val);
@@ -10333,7 +10348,7 @@ if mag<>1000 then
end
@ The necessary conversion factors can all be specified exactly as
-fractions whose numerator and denominator are 65535 or less.
+fractions whose numerator and denominator add to 32768 or less.
According to the definitions here, $\rm2660\,dd\approx1000.33297\,mm$;
this agrees well with the value $\rm1000.333\,mm$ cited by Bosshard
@^Bosshard, Hans Rudolf@>
@@ -10341,7 +10356,13 @@ in {\sl Technische Grundlagen zur Satzherstellung\/} (Bern, 1980).
The Didot point has been newly standardized in 1978;
it's now exactly $\rm 1\,nd=0.375\,mm$.
Conversion uses the equation $0.375=21681/20320/72.27\cdot25.4$.
-The new Cicero follows the new Didot point; $\rm 1\,nc=12\,nd$.
+The new Cicero follows the new Didot point; $\rm 1\,nc=12\,nd$.
+These would lead to the ratios $21681/20320$ and $65043/5080$,
+respectively.
+The closest approximations supported by the algorithm would be
+$11183/10481$ and $1370/107$. In order to maintain the
+relation $\rm 1\,nc=12\,nd$, we pick the ratio $685/642$ for
+$\rm nd$, however.
@d set_conversion_end(#)== denom:=#; end
@d set_conversion(#)==@+begin num:=#; set_conversion_end
@@ -10361,9 +10382,9 @@ else if scan_keyword("dd") then set_conversion(1238)(1157)
@.dd@>
else if scan_keyword("cc") then set_conversion(14856)(1157)
@.cc@>
-else if scan_keyword("nd") then set_conversion(21681)(20320)
+else if scan_keyword("nd") then set_conversion(685)(642)
@.nd@>
-else if scan_keyword("nc") then set_conversion(65043)(5080)
+else if scan_keyword("nc") then set_conversion(1370)(107)
@.nc@>
else if scan_keyword("sp") then goto done
@.sp@>
@@ -10756,7 +10777,7 @@ pdf_font_name_code, pdf_font_objnum_code, pdf_font_size_code: begin
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);
+ pdf_check_vf_cur_val;
if not font_used[cur_val] then
pdf_init_font_cur_val;
end;
@@ -13176,7 +13197,7 @@ procedure scan_font_ident;
var f:internal_font_number;
@!m:halfword;
begin @<Get the next non-blank non-call...@>;
-if (cur_cmd=def_font) or (cur_cmd=letterspace_font) then f:=cur_font
+if (cur_cmd=def_font) or (cur_cmd=letterspace_font) or (cur_cmd=pdf_copy_font) then f:=cur_font
else if cur_cmd=set_font then f:=cur_chr
else if cur_cmd=def_family then
begin m:=cur_chr; scan_four_bit_int; f:=equiv(m+cur_val);
@@ -15149,6 +15170,7 @@ begin
fixed_image_apply_gamma := fix_int(pdf_image_apply_gamma, 0, 1);
fixed_pdf_objcompresslevel := fix_int(pdf_objcompresslevel, 0, 3);
fixed_pdf_draftmode := fix_int(pdf_draftmode, 0, 1);
+ fixed_inclusion_copy_font := fix_int(pdf_inclusion_copy_font, 0, 1);
if (fixed_pdf_minor_version >= 5) and (fixed_pdf_objcompresslevel > 0) then
pdf_os_enable := true
else begin
@@ -15304,6 +15326,7 @@ begin
print(": "); print(p);
if append_nl then
print_ln;
+ if history=spotless then history:=warning_issued;
end;
procedure pdf_os_get_os_buf(s: integer); {check that |s| bytes more
@@ -15625,6 +15648,7 @@ DVI}
@!fixed_pk_resolution: integer;
@!fixed_decimal_digits: integer;
@!fixed_gen_tounicode: integer;
+@!fixed_inclusion_copy_font: integer;
@!pk_scale_factor: integer;
@!pdf_output_option: integer;
@!pdf_output_value: integer;
@@ -15989,7 +16013,7 @@ 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 five integer fields and represents an object
+|obj_entry|. Each entry contains five 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.
@@ -16007,10 +16031,9 @@ The second field of |obj_entry| contains link to the next
object in |obj_tab| if this object is linked in a list.
The third field holds the byte offset of the object in the output PDF file,
-or its byte offset within an object stream.
-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.
+or its byte offset within an object stream. As long as the object is not
+written, this field is used for flags about the write status of the object;
+then it has a negative value.
The fourth field holds the object number of the object stream, into which
the object is included.
@@ -16021,10 +16044,14 @@ well.
@d obj_info(#) == obj_tab[#].int0 {information representing identifier of this object}
@d obj_link(#) == obj_tab[#].int1 {link to the next entry in linked list}
-@d obj_offset(#) == obj_tab[#].int2 {byte offset for this object in PDF output file, or object stream number for this object}
+@d obj_offset(#) == obj_tab[#].int2 {negative (flags), or byte offset for this object in PDF output file, or object stream number for this object}
@d obj_os_idx(#) == obj_tab[#].int3 {index of this object in object stream}
@d obj_aux(#) == obj_tab[#].int4 {auxiliary pointer}
-@d is_obj_written(#) == (obj_offset(#) <> 0)
+
+@d set_obj_fresh(#) == obj_offset(#) := -2
+@d set_obj_scheduled(#) == if obj_offset(#) = -2 then obj_offset(#) := -1
+@d is_obj_scheduled(#) == (obj_offset(#) > -2)
+@d is_obj_written(#) == (obj_offset(#) > -1)
@# {types of objects}
@d obj_type_others == 0 {objects which are not linked in any list}
@@ -16055,7 +16082,7 @@ destination |pdf_left| and |pdf_top| are used for some types of destinations}
@d pdf_right(#) == mem[# + 3].sc
@d pdf_bottom(#) == mem[# + 4].sc
-@# {dimesion of destinations/threads/annotations (in whatsit node)}
+@# {dimension of destinations/threads/annotations (in whatsit node)}
@d pdf_width(#) == mem[# + 1].sc
@d pdf_height(#) == mem[# + 2].sc
@d pdf_depth(#) == mem[# + 3].sc
@@ -16089,7 +16116,7 @@ destination |pdf_left| and |pdf_top| are used for some types of destinations}
@d pdf_setmatrix_node_size == 2
@d pdf_setmatrix_data(#) == link(#+1) {data}
-@# {data structure for \.{\\pdsave}}
+@# {data structure for \.{\\pdfsave}}
@d pdf_save_node_size == 2
@# {data structure for \.{\\pdfrestore}}
@@ -16328,7 +16355,7 @@ begin
incr(sys_obj_ptr);
obj_ptr := sys_obj_ptr;
obj_info(obj_ptr) := i;
- obj_offset(obj_ptr) := 0;
+ set_obj_fresh(obj_ptr);
obj_aux(obj_ptr) := 0;
avl_put_obj(obj_ptr, t);
if t = obj_type_page then begin
@@ -16712,28 +16739,15 @@ during adjusting spacing. Such fonts are linked via the |pdf_font_elink| array.
@d virtual_font_type = 1 {virtual font}
@d real_font_type = 2 {real font}
@d subst_font_type = 3 {substituted font}
-@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
-
-@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 for \pdfTeX@>=
-procedure do_vf; forward;
+procedure pdf_check_vf_cur_val; forward;
procedure pdf_init_font_cur_val; 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; {temporary register to pass parameter to some subroutines}
@ Here come some subroutines to deal with expanded fonts for HZ-algorithm.
@@ -16747,6 +16761,8 @@ else if type(#) = ligature_node then begin
f := font(lig_char(#));
end
+@d non_existent_path == "///..."
+
@p
procedure set_tag_code(f: internal_font_number; c: eight_bits; i: integer);
var fixedi:integer;
@@ -17020,7 +17036,10 @@ var k: internal_font_number;
begin
if fs <> 0 then begin
for k := font_base + 1 to font_ptr do
- if str_eq_str(font_name[k], s) and (font_size[k] = fs) then begin
+ if (font_area[k] <> non_existent_path) and
+ str_eq_str(font_name[k], s) and
+ (font_size[k] = fs) then
+ begin
flush_str(s);
tfm_lookup := k;
return;
@@ -17028,7 +17047,9 @@ begin
end
else begin
for k := font_base + 1 to font_ptr do
- if str_eq_str(font_name[k], s) then begin
+ if (font_area[k] <> non_existent_path) and
+ str_eq_str(font_name[k], s) then
+ begin
flush_str(s);
tfm_lookup := k;
return;
@@ -17056,45 +17077,6 @@ begin
load_expand_font := k;
end;
-function auto_expand_vf(f: internal_font_number): boolean;
-{check for a virtual auto-expanded font}
-var save_f, bf, lf: internal_font_number;
- e, k: integer;
-begin
- auto_expand_vf := false;
- if (not pdf_font_auto_expand[f]) or (pdf_font_blink[f] = null_font) then
- return; {not an auto-expanded font}
- bf := pdf_font_blink[f];
- if pdf_font_type[bf] = new_font_type then {we must process the base font first}
- begin
- save_f := tmp_f;
- tmp_f := bf;
- do_vf;
- tmp_f := save_f;
- end;
-
- if pdf_font_type[bf] <> virtual_font_type then
- return; {not a virtual font}
-
- e := pdf_font_expand_ratio[f];
- for k := 0 to vf_local_font_num[bf] - 1 do begin
- lf := vf_default_font[bf] + k;
- allocvffnts;
- {copy vf local font numbers:}
- vf_e_fnts[vf_nf] := vf_e_fnts[lf];
- {definition of local vf fonts are expanded from base fonts:}
- vf_i_fnts[vf_nf] := auto_expand_font(vf_i_fnts[lf], e);
- copy_expand_params(vf_i_fnts[vf_nf], vf_i_fnts[lf], e);
- incr(vf_nf);
- end;
- vf_packet_base[f] := vf_packet_base[bf];
- vf_local_font_num[f] := vf_local_font_num[bf];
- vf_default_font[f] := vf_nf - vf_local_font_num[f];
-
- pdf_font_type[f] := virtual_font_type;
- auto_expand_vf := true;
-end;
-
function fix_expand_value(f: internal_font_number; e: integer): integer;
{return the multiple of |pdf_font_step[f]| that is nearest to |e|}
var step: integer;
@@ -17160,15 +17142,15 @@ begin
end;
procedure set_expand_params(f: internal_font_number; auto_expand: boolean;
- font_stretch, font_shrink, font_step, expand_ratio: integer);
+ stretch_limit, shrink_limit, font_step, expand_ratio: integer);
{expand a font with given parameters}
begin
pdf_font_step[f] := font_step;
pdf_font_auto_expand[f] := auto_expand;
- if font_stretch > 0 then
- pdf_font_stretch[f] := get_expand_font(f, font_stretch);
- if font_shrink > 0 then
- pdf_font_shrink[f] := get_expand_font(f, -font_shrink);
+ if stretch_limit > 0 then
+ pdf_font_stretch[f] := get_expand_font(f, stretch_limit);
+ if shrink_limit > 0 then
+ pdf_font_shrink[f] := get_expand_font(f, -shrink_limit);
if expand_ratio <> 0 then
pdf_font_expand_ratio[f] := expand_ratio;
end;
@@ -17182,7 +17164,7 @@ begin
lf := vf_i_fnts[vf_default_font[f] + k];
set_expand_params(lf, pdf_font_auto_expand[f],
pdf_font_expand_ratio[pdf_font_stretch[f]],
- pdf_font_expand_ratio[pdf_font_shrink[f]],
+ -pdf_font_expand_ratio[pdf_font_shrink[f]],
pdf_font_step[f], pdf_font_expand_ratio[f]);
if pdf_font_type[lf] = virtual_font_type then
vf_expand_local_fonts(lf);
@@ -17190,7 +17172,7 @@ begin
end;
procedure read_expand_font; {read font expansion spec and load expanded font}
-var font_shrink, font_stretch, font_step: integer;
+var shrink_limit, stretch_limit, font_step: integer;
f: internal_font_number;
auto_expand: boolean;
begin
@@ -17200,23 +17182,23 @@ begin
if f = null_font then
pdf_error("font expansion", "invalid font identifier");
if pdf_font_blink[f] <> null_font then
- pdf_error("font expansion", "\pdffontexpand cannot be used this way (the base font has been expanded or letter-spaced)");
+ pdf_error("font expansion", "\pdffontexpand cannot be used this way (the base font has been expanded)");
scan_optional_equals;
scan_int;
- font_stretch := fix_int(cur_val, 0, 1000);
+ stretch_limit := fix_int(cur_val, 0, 1000);
scan_int;
- font_shrink := fix_int(cur_val, 0, 500);
+ shrink_limit := fix_int(cur_val, 0, 500);
scan_int;
font_step := fix_int(cur_val, 0, 100);
if font_step = 0 then
pdf_error("font expansion", "invalid step");
- font_stretch := font_stretch - font_stretch mod font_step;
- if font_stretch < 0 then
- font_stretch := 0;
- font_shrink := font_shrink - font_shrink mod font_step;
- if font_shrink < 0 then
- font_shrink := 0;
- if (font_stretch = 0) and (font_shrink = 0) then
+ stretch_limit := stretch_limit - stretch_limit mod font_step;
+ if stretch_limit < 0 then
+ stretch_limit := 0;
+ shrink_limit := shrink_limit - shrink_limit mod font_step;
+ if shrink_limit < 0 then
+ shrink_limit := 0;
+ if (stretch_limit = 0) and (shrink_limit = 0) then
pdf_error("font expansion", "invalid limit(s)");
auto_expand := false;
if scan_keyword("autoexpand") then begin
@@ -17230,37 +17212,60 @@ begin
if (pdf_font_step[f] <> 0) then
{this font has been expanded, ensure the expansion parameters are identical}
begin
- if (pdf_font_step[f] <> font_step) or
- ((pdf_font_stretch[f] = null_font) and (font_stretch <> 0)) or
- ((pdf_font_stretch[f] <> null_font) and
- (pdf_font_expand_ratio[pdf_font_stretch[f]] <> font_stretch)) or
- ((pdf_font_shrink[f] = null_font) and (font_shrink <> 0)) or
+ if pdf_font_step[f] <> font_step then
+ pdf_error("font expansion", "font has been expanded with different expansion step");
+
+ if ((pdf_font_stretch[f] = null_font) and (stretch_limit <> 0)) or
+ ((pdf_font_stretch[f] <> null_font) and
+ (pdf_font_expand_ratio[pdf_font_stretch[f]] <> stretch_limit)) then
+ pdf_error("font expansion", "font has been expanded with different stretch limit");
+
+ if ((pdf_font_shrink[f] = null_font) and (shrink_limit <> 0)) or
((pdf_font_shrink[f] <> null_font) and
- (pdf_font_expand_ratio[pdf_font_shrink[f]] <> -font_shrink)) or
- (pdf_font_auto_expand[f] <> auto_expand)
- then
- pdf_error("font expansion", "font has been expanded with different parameters");
+ (-pdf_font_expand_ratio[pdf_font_shrink[f]] <> shrink_limit)) then
+ pdf_error("font expansion", "font has been expanded with different shrink limit");
+
+ if pdf_font_auto_expand[f] <> auto_expand then
+ pdf_error("font expansion", "font has been expanded with different auto expansion value");
end
else begin
- if pdf_font_type[f] <> new_font_type then
+ if (pdf_font_type[f] <> new_font_type) and (pdf_font_type[f] <> virtual_font_type) then
pdf_warning("font expansion", "font should be expanded before its first use",
true, true);
- set_expand_params(f, auto_expand, font_stretch, font_shrink, font_step, 0);
+ set_expand_params(f, auto_expand, stretch_limit, shrink_limit, font_step, 0);
if pdf_font_type[f] = virtual_font_type then
vf_expand_local_fonts(f);
end;
end;
+@ We implement robust letter spacing using virtual font.
+
+@d 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
+
+@p
function letter_space_font(u: pointer; f: internal_font_number; e: integer): internal_font_number;
var k: internal_font_number;
- w, r, fs: scaled;
+ w, r: scaled;
s: str_number;
i, nw: integer;
old_setting:0..max_selector;
+ vf_z: integer;
+ vf_alpha: integer;
+ vf_beta: 1..16;
begin
{read a new font and expand the character widths}
k := read_font_info(u, font_name[f], "", font_size[f]);
- set_no_ligatures(k); {disable ligatures for letter-spaced fonts}
+ if scan_keyword("nolig") then
+ set_no_ligatures(k); {disable ligatures for letter-spaced fonts}
nw := height_base[k] - width_base[k];
for i := 0 to nw - 1 do
font_info[width_base[k] + i].sc :=
@@ -17288,8 +17293,7 @@ begin
vf_default_font[k] := vf_nf - 1;
pdf_font_type[k] := virtual_font_type;
- fs := font_size[f];
- vf_z := fs;
+ vf_z := font_size[f];
vf_replace_z;
w := round_xn_over_d(quad(f), e, 2000);
if w > 0 then
@@ -17363,6 +17367,106 @@ begin
equiv(u):=f; eqtb[font_id_base+f]:=eqtb[u]; font_id_text(f):=t;
end;
+function is_letterspaced_font(f: internal_font_number): boolean;
+label done;
+var i, j: pool_pointer;
+begin
+ is_letterspaced_font := false;
+ if pdf_font_type[f] <> virtual_font_type then
+ return;
+ i := str_start[font_name[f] + 1] - 1;
+ j := str_start[font_name[f]];
+ if (str_pool[i - 1] <> 'l') or (str_pool[i] <> 's') then
+ return;
+ i := i - 2;
+ while i >= j do begin
+ if (str_pool[i] < '0') or (str_pool[i] > '9') then
+ goto done;
+ i := i - 1;
+ end;
+done:
+ if i < j then
+ return;
+ if (str_pool[i] <> '+') and (str_pool[i] <> '-') then
+ return;
+ is_letterspaced_font := true;
+end;
+
+function copy_font_info(f: internal_font_number): internal_font_number;
+{create a copy of |f| in the font mem}
+var lf, bc, ec, i: halfword;
+ k: internal_font_number;
+begin
+ if (pdf_font_expand_ratio[f] <> 0) or (pdf_font_step[f] <> 0) then
+ pdf_error("\pdfcopyfont", "cannot copy an expanded font");
+ if is_letterspaced_font(f) then
+ pdf_error("\pdfcopyfont", "cannot copy a letterspaced font");
+
+ k := font_ptr + 1;
+ incr(font_ptr);
+ if (font_ptr >= font_max) then
+ overflow("maximum internal font number (font_max)", font_max);
+ font_name[k] := font_name[f];
+ font_area[k] := non_existent_path; {to avoid interferences with |new_font()| and |tfm_lookup()|}
+ hyphen_char[k] := hyphen_char[f];
+ skew_char[k] := skew_char[f];
+ font_bchar[k] := font_bchar[f];
+ font_false_bchar[k] := font_false_bchar[f];
+ font_bc[k] := font_bc[f];
+ font_ec[k] := font_ec[f];
+ font_size[k] := font_size[f];
+ font_dsize[k] := font_dsize[f];
+ font_params[k] := font_params[f];
+ font_glue[k] := font_glue[f];
+ bchar_label[k] := bchar_label[f];
+
+ {set base addresses}
+ bc := font_bc[f];
+ ec := font_ec[f];
+ char_base[k] := fmem_ptr - bc;
+ width_base[k] := char_base[k] + ec + 1;
+
+ height_base[k] := width_base[k] + (height_base[f] - width_base[f]);
+ depth_base[k] := height_base[k] + (depth_base[f] - height_base[f]);
+ italic_base[k] := depth_base[k] + (italic_base[f] - depth_base[f]);
+ lig_kern_base[k] := italic_base[k] + (lig_kern_base[f] - italic_base[f]);
+ kern_base[k] := lig_kern_base[k] + (kern_base[f] - lig_kern_base[f]);
+ exten_base[k] := kern_base[k] + (exten_base[f] - kern_base[f]);
+ param_base[k] := exten_base[k] + (param_base[f] - exten_base[f]);
+
+ {allocate memory for the new font |k| and copy data from |f|}
+ lf := (param_base[f] - char_base[f]) + font_params[f] + 1;
+ if (fmem_ptr + lf >= font_mem_size) then
+ overflow("number of words of font memory (font_mem_size)", font_mem_size);
+ for i := 0 to lf - 1 do
+ font_info[char_base[k] + bc + i] := font_info[char_base[f] + bc + i];
+ fmem_ptr := fmem_ptr + lf;
+
+ copy_font_info := k;
+end;
+
+procedure make_font_copy(a: small_number);
+{make a font copy for further use with font expansion}
+var u:pointer; {user's font identifier}
+@!t:str_number; {name for the frozen font identifier}
+@!old_setting:0..max_selector; {holds |selector| setting}
+@!f, k:internal_font_number;
+begin
+ get_r_token; u:=cur_cs;
+ if u>=hash_base then t:=text(u)
+ else if u>=single_base then
+ if u=null_cs then t:="FONT"@+else t:=u-single_base
+ else begin old_setting:=selector; selector:=new_string;
+ print("FONT"); print(u-active_base); selector:=old_setting;
+ @.FONTx@>
+ str_room(1); t:=make_string;
+ end;
+ define(u,set_font,null_font); scan_optional_equals; scan_font_ident;
+ k := cur_val;
+ f := copy_font_info(k);
+ equiv(u):=f; eqtb[font_id_base+f]:=eqtb[u]; font_id_text(f):=t;
+end;
+
@ We need to hold information about used characters in each font for partial
downloading.
@@ -17386,50 +17490,24 @@ created by |tokens_to_string|}
pdf_resname_prefix := 0;
last_tokens_string := 0;
-
@ Here we implement reading information from \.{VF} file.
@d vf_max_packet_length = 10000 {max length of character packet in \.{VF} file}
-
@#
-@d vf_error = 61 {label to go to when an error occur}
@d do_char = 70 {label to go to typesetting a character of virtual font}
@#
@d long_char = 242 {\.{VF} command for general character packet}
@d vf_id = 202 {identifies \.{VF} files}
@d put1=133 {typeset a character}
-
-@#
-@d vf_byte == getc(vf_file) {get a byte from\.{VF} file}
-@d vf_packet(#) == vf_packet_start[vf_packet_base[#] + vf_packet_end
-@d vf_packet_end(#) == #]
-
-@#
-@d bad_vf(#) == begin vf_err_str := #; goto vf_error; end {go out \.{VF}
-processing with an error message}
@d four_cases(#) == #,#+1,#+2,#+3
-
@#
@d tmp_b0 == tmp_w.qqqq.b0
@d tmp_b1 == tmp_w.qqqq.b1
@d tmp_b2 == tmp_w.qqqq.b2
@d tmp_b3 == tmp_w.qqqq.b3
@d tmp_int == tmp_w.int
-
@#
-@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
-@d scaled4(#) == {convert |tmp_b0..tmp_b3| to a scaled dimension}
- #:=scaled3u;
- if tmp_b0>0 then if tmp_b0=255 then # := # - vf_alpha
-@d scaled3(#) == {convert |tmp_b1..tmp_b3| to a scaled dimension}
- #:=scaled3u; @+ if tmp_b1>127 then # := # - vf_alpha
-@d scaled2 == {convert |tmp_b2..tmp_b3| to a scaled dimension}
- if tmp_b2>127 then tmp_b1:=255 else tmp_b1:=0;
- scaled3
-@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
+@d bad_vf(#) == vf_error(font_name[f], #) {quit with an error message telling the vf filename}
@<Glob...@>=
@!vf_packet_base: ^integer; {base addresses of character packets from virtual fonts}
@@ -17441,34 +17519,46 @@ processing with an error message}
@!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
+or loaded, otherwise sets |pdf_font_type| to |virtual_font_type|. To
process font definitions in virtual font we call |vf_def_font|.
-@p procedure vf_replace_z;
+@p
+procedure vf_error(filename, msg: str_number);
+var old_setting:0..max_selector; {holds print |selector|}
+ s: str_number;
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;
+ str_room(length(filename) + 3);
+ old_setting:=selector; selector:=new_string;
+ print(filename);
+ print(".vf");
+ s := make_string;
+ selector:=old_setting;
+ pdf_error(s, msg);
+end;
+
+function vf_byte: eight_bits; {read a byte from |vf_file|}
+var i: integer;
+begin
+ i := getc(vf_file);
+ if i < 0 then
+ pdf_error("vf", "unexpected EOF or error");
+ vf_byte := i;
end;
function vf_read(k: integer): integer; {read |k| bytes as an integer from \.{VF} file}
var i: integer;
begin
- i := 0;
+ pdfassert((k > 0) and (k <= 4));
+ i := vf_byte;
+ if (k = 4) and (i > 127) then
+ i := i - 256;
+ decr(k);
while k > 0 do begin
i := i*256 + vf_byte;
decr(k);
@@ -17496,15 +17586,13 @@ var k: internal_font_number;
cs: four_quarters;
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);
+ fs := sqxfw(vf_read(4), font_size[f]);
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}
+ call_func(vf_byte); {skip the font path}
end;
str_room(tmp_b1);
while tmp_b1 > 0 do begin
@@ -17528,23 +17616,19 @@ begin
if (pdf_font_step[f] <> 0) then
set_expand_params(k, pdf_font_auto_expand[f],
pdf_font_expand_ratio[pdf_font_stretch[f]],
- pdf_font_expand_ratio[pdf_font_shrink[f]],
+ -pdf_font_expand_ratio[pdf_font_shrink[f]],
pdf_font_step[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;
+procedure do_vf(f: internal_font_number); {process \.{VF} file with font internal number |f|}
var cmd, k, n: integer;
- cc, cmd_length: integer;
+ cc, cmd_length, packet_length: integer;
tfm_width: scaled;
- vf_err_str, s: str_number;
+ 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}
@@ -17560,16 +17644,6 @@ begin
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@>=
@@ -17584,7 +17658,7 @@ 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;
+ call_func(vf_byte); {skip the comment}
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
@@ -17600,9 +17674,7 @@ if vf_read(4) div @'20 <> font_dsize[f] then begin
print(font_name[f]);
print(".vf ignored");
end;
-update_terminal;
-vf_z := font_size[f];
-vf_replace_z
+update_terminal
@ @<Process the font definitions@>=
cmd := vf_byte;
@@ -17622,38 +17694,36 @@ vf_local_font_num[f] := vf_nf - save_vf_nf;
@ @<Build a character packet@>=
if cmd = long_char then begin
- vf_packet_length := vf_read(4);
+ 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);
+ tfm_width := sqxfw(vf_read(4), font_size[f]);
end
else begin
- vf_packet_length := cmd;
+ 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);
+ tfm_width := sqxfw(vf_read(3), font_size[f]);
end;
-if vf_packet_length < 0 then
+if packet_length < 0 then
bad_vf("negative packet length");
-if vf_packet_length > vf_max_packet_length then
+if 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
+if abs(tfm_width - char_width(f)(char_info(f)(cc))) > 1 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
+str_room(packet_length);
+while packet_length > 0 do begin
cmd := vf_byte;
- decr(vf_packet_length);
+ decr(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;
+ packet_length := packet_length - cmd_length;
while cmd_length > 0 do begin
decr(cmd_length);
append_char(vf_byte);
@@ -17661,7 +17731,7 @@ while vf_packet_length > 0 do begin
end;
if stack_level <> 0 then
bad_vf("more PUSHs than POPs in character packet");
-if vf_packet_length <> 0 then
+if packet_length <> 0 then
bad_vf("invalid packet length or DVI command in packet");
@<Store the packet being built@>;
cmd := vf_byte
@@ -17678,7 +17748,7 @@ 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);
+ packet_length := packet_length - (cmd - fnt1 + 1);
end
else
k := cmd - fnt_num_0;
@@ -17711,7 +17781,7 @@ 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);
+ packet_length := packet_length - (cmd - xxx1 + 1);
if cmd_length > vf_max_packet_length then
bad_vf("packet length too long");
if cmd_length < 0 then
@@ -17739,6 +17809,49 @@ othercases
bad_vf("improver DVI command");
endcases
+@ @p
+procedure pdf_check_vf_cur_val;
+var f: internal_font_number;
+begin
+ f := cur_val;
+ do_vf(f);
+ if pdf_font_type[f] = virtual_font_type then
+ pdf_error("font", "command cannot be used with virtual font");
+end;
+
+function auto_expand_vf(f: internal_font_number): boolean;
+{check for a virtual auto-expanded font}
+var bf, lf: internal_font_number;
+ e, k: integer;
+begin
+ auto_expand_vf := false;
+ if (not pdf_font_auto_expand[f]) or (pdf_font_blink[f] = null_font) then
+ return; {not an auto-expanded font}
+ bf := pdf_font_blink[f];
+ if pdf_font_type[bf] = new_font_type then {we must process the base font first}
+ do_vf(bf);
+ if pdf_font_type[bf] <> virtual_font_type then
+ return; {not a virtual font}
+
+ e := pdf_font_expand_ratio[f];
+ for k := 0 to vf_local_font_num[bf] - 1 do begin
+ lf := vf_default_font[bf] + k;
+ allocvffnts;
+ {copy vf local font numbers:}
+ vf_e_fnts[vf_nf] := vf_e_fnts[lf];
+ {definition of local vf fonts are expanded from base fonts:}
+ vf_i_fnts[vf_nf] := auto_expand_font(vf_i_fnts[lf], e);
+ copy_expand_params(vf_i_fnts[vf_nf], vf_i_fnts[lf], e);
+ incr(vf_nf);
+ end;
+ vf_packet_base[f] := vf_packet_base[bf];
+ vf_local_font_num[f] := vf_local_font_num[bf];
+ vf_default_font[f] := vf_nf - vf_local_font_num[f];
+
+ pdf_font_type[f] := virtual_font_type;
+ auto_expand_vf := true;
+end;
+
@ 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
@@ -17771,7 +17884,11 @@ vf_stack_ptr := 0;
character packet}
var i: integer;
begin
- i := 0;
+ pdfassert((k > 0) and (k <= 4));
+ i := packet_byte;
+ if (k = 4) and (i > 127) then
+ i := i - 256;
+ decr(k);
while k > 0 do begin
i := i*256 + packet_byte;
decr(k);
@@ -17779,43 +17896,27 @@ begin
packet_read := i;
end;
-function packet_scaled(k: integer): integer; {get |k| bytes from packet as a
+function packet_scaled(k: integer; fs: scaled): scaled; {get |k| bytes from packet as a
scaled}
-var s: scaled;
+var fw: integer;
begin
+ fw := packet_read(k);
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");
+ 1: if fw > 127 then
+ fw := fw - 256;
+ 2: if fw > @"8000 then
+ fw := fw - @"10000;
+ 3: if fw > @"800000 then
+ fw := fw - @"1000000;
endcases;
- packet_scaled := s;
+ packet_scaled := sqxfw(fw, fs);
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|}
+procedure do_vf_packet(vf_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_vf, k, n: internal_font_number;
- save_h, save_v: scaled;
+var f, k, n: internal_font_number;
+ save_cur_h, save_cur_v: scaled;
cmd: integer;
char_move: boolean;
w, x, y, z: scaled;
@@ -17824,32 +17925,28 @@ 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;
+ save_cur_v := cur_v;
+ save_cur_h := cur_h;
+ push_packet_state; {save pointer and length of the current packet}
+ start_packet(vf_f, c); {set pointer and length of the new packet}
+ f := vf_i_fnts[vf_default_font[vf_f]];
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;
+ pop_packet_state; {restore pointer and length of the previous packet}
+ cur_v := save_cur_v;
+ cur_h := save_cur_h;
decr(vf_cur_s);
end;
@ The following code typesets a character to PDF output.
-@d output_one_char(#)==begin
- pdf_check_new_font(f);
+@d output_one_char(#) == begin
+ if pdf_font_type[f] = new_font_type then
+ do_vf(f);
if pdf_font_type[f] = virtual_font_type then
do_vf_packet(f, #)
else begin
@@ -17859,7 +17956,6 @@ end;
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
@@ -17876,13 +17972,13 @@ else if ((fnt_num_0 <= cmd) and (cmd <= fnt_num_0 + 63)) or (cmd = fnt1) then be
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
+ while (n < vf_local_font_num[vf_f]) and
+ (vf_e_fnts[vf_default_font[vf_f] + n] <> k) do
incr(n);
- if (n = vf_local_font_num[save_vf]) then
+ if (n = vf_local_font_num[vf_f]) then
pdf_error("vf", "local font not found")
else
- f := vf_i_fnts[vf_default_font[save_vf] + n];
+ f := vf_i_fnts[vf_default_font[vf_f] + n];
end
else case cmd of
push: begin
@@ -17920,8 +18016,8 @@ four_cases(set1), four_cases(put1): begin
goto do_char;
end;
set_rule, put_rule: begin
- rule_ht := packet_scaled(4);
- rule_wd := packet_scaled(4);
+ rule_ht := packet_scaled(4, font_size[vf_f]);
+ rule_wd := packet_scaled(4, font_size[vf_f]);
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
@@ -17929,27 +18025,27 @@ set_rule, put_rule: begin
end;
end;
four_cases(right1):
- cur_h := cur_h + packet_scaled(cmd - right1 + 1);
+ cur_h := cur_h + packet_scaled(cmd - right1 + 1, font_size[vf_f]);
w0, four_cases(w1): begin
if cmd > w0 then
- w := packet_scaled(cmd - w0);
+ w := packet_scaled(cmd - w0, font_size[vf_f]);
cur_h := cur_h + w;
end;
x0, four_cases(x1): begin
if cmd > x0 then
- x := packet_scaled(cmd - x0);
+ x := packet_scaled(cmd - x0, font_size[vf_f]);
cur_h := cur_h + x;
end;
four_cases(down1):
- cur_v := cur_v + packet_scaled(cmd - down1 + 1);
+ cur_v := cur_v + packet_scaled(cmd - down1 + 1, font_size[vf_f]);
y0, four_cases(y1): begin
if cmd > y0 then
- y := packet_scaled(cmd - y0);
+ y := packet_scaled(cmd - y0, font_size[vf_f]);
cur_v := cur_v + y;
end;
z0, four_cases(z1): begin
if cmd > z0 then
- z := packet_scaled(cmd - z0);
+ z := packet_scaled(cmd - z0, font_size[vf_f]);
cur_v := cur_v + z;
end;
four_cases(xxx1): begin
@@ -18536,7 +18632,7 @@ 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}
+ obj_aux(pdf_last_page) := 1; {mark that this page has been created}
pdf_new_dict(obj_type_others, 0, 0);
pdf_last_stream := obj_ptr;
cur_h := cur_h_offset;
@@ -18928,14 +19024,13 @@ if pdf_link_list <> null then begin
i := obj_annot_ptr(info(k));
pdf_begin_dict(info(k), 1);
pdf_print_ln("/Type /Annot");
+ if pdf_action_type(pdf_link_action(i)) <> pdf_action_user then
+ pdf_print_ln("/Subtype /Link");
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");
+ if pdf_action_type(pdf_link_action(i)) <> pdf_action_user then
pdf_print("/A ");
- end;
write_action(pdf_link_action(i));
pdf_end_dict;
k := link(k);
@@ -19350,7 +19445,9 @@ for k := font_base + 1 to font_ptr do
print_font_identifier(i);
print(" and ");
print_font_identifier(k);
- print(" has conflicting attributes"); print_ln; print_ln;
+ print(" have conflicting attributes; I will ignore the attributes assigned to ");
+ print_font_identifier(i);
+ print_ln; print_ln;
end;
end;
fixed_gen_tounicode := pdf_gen_tounicode;
@@ -19645,7 +19742,7 @@ print_mod_date;
@ @<Output the |obj_tab|@>=
l := 0;
for k := 1 to sys_obj_ptr do
- if obj_offset(k) = 0 then begin
+ if not is_obj_written(k) then begin
obj_link(l) := k;
l := k;
end;
@@ -19656,7 +19753,7 @@ 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
+ if not is_obj_written(k) then begin
pdf_print_fw_int(obj_link(k), 10);
pdf_print_ln(" 00000 f ");
end
@@ -19678,7 +19775,7 @@ else
xref_offset_width := 1;
l := 0;
for k := 1 to sys_obj_ptr do
- if obj_offset(k) = 0 then begin
+ if not is_obj_written(k) then begin
obj_link(l) := k;
l := k;
end;
@@ -19701,7 +19798,7 @@ print_ID(output_file_name);
pdf_print_nl;
pdf_begin_stream;
for k := 0 to sys_obj_ptr do begin
- if obj_offset(k) = 0 then begin {a free object}
+ if not is_obj_written(k) then begin {a free object}
pdf_out(0);
pdf_out_bytes(obj_link(k), xref_offset_width);
pdf_out(255);
@@ -19842,8 +19939,8 @@ location |adjust_tail|.
@ @<Glob...@>=
@!pdf_font_blink: ^internal_font_number; {link to base font (used for expanded fonts only)}
@!pdf_font_elink: ^internal_font_number; {link to expanded fonts (used for base fonts only)}
-@!pdf_font_stretch: ^integer; {limit of stretching}
-@!pdf_font_shrink: ^integer; {limit of shrinking}
+@!pdf_font_stretch: ^integer; {link to font expanded by stretch limi}
+@!pdf_font_shrink: ^integer; {link to font expanded by shrink limit}
@!pdf_font_step: ^integer; {amount of one step of expansion}
@!pdf_font_expand_ratio: ^integer; {expansion ratio of a particular font}
@!pdf_font_auto_expand: ^boolean; {this font is auto-expanded?}
@@ -19921,8 +20018,8 @@ begin
k := pdf_font_shrink[f];
if k <> null_font then begin
if max_shrink_ratio < 0 then
- max_shrink_ratio := pdf_font_expand_ratio[k]
- else if max_shrink_ratio <> pdf_font_expand_ratio[k] then
+ max_shrink_ratio := -pdf_font_expand_ratio[k]
+ else if max_shrink_ratio <> -pdf_font_expand_ratio[k] then
pdf_error("font expansion", "using fonts with different limit of expansion in one paragraph is not allowed");
end;
check_expand_pars := true;
@@ -20002,12 +20099,17 @@ begin
return;
l := prev_char_p;
r := link(p);
- if type(l) = ligature_node then
- l := lig_char(l);
- if type(r) = ligature_node then
- r := lig_char(r);
- if not (is_char_node(l) and is_char_node(r) and
- (font(l) = font(r)) and
+ if not is_char_node(l) then
+ if type(l) = ligature_node then
+ l := lig_char(l)
+ else
+ return;
+ if not is_char_node(r) then
+ if type(r) = ligature_node then
+ r := lig_char(r)
+ else
+ return;
+ if not ((font(l) = font(r)) and
(pdf_font_stretch[font(l)] <> null_font))
then
return;
@@ -20026,12 +20128,17 @@ begin
return;
l := prev_char_p;
r := link(p);
- if type(l) = ligature_node then
- l := lig_char(l);
- if type(r) = ligature_node then
- r := lig_char(r);
- if not (is_char_node(l) and is_char_node(r) and
- (font(l) = font(r)) and
+ if not is_char_node(l) then
+ if type(l) = ligature_node then
+ l := lig_char(l)
+ else
+ return;
+ if not is_char_node(r) then
+ if type(r) = ligature_node then
+ r := lig_char(r)
+ else
+ return;
+ if not ((font(l) = font(r)) and
(pdf_font_shrink[font(l)] <> null_font))
then
return;
@@ -20073,13 +20180,13 @@ begin
if ef = 0 then
return;
if (pdf_font_stretch[f] <> null_font) and (ex_ratio > 0) then
- k := expand_font(f, divide_scaled(ex_ratio*
- pdf_font_expand_ratio[pdf_font_stretch[f]]*ef,
- 1000000, 0))
+ k := expand_font(f, ext_xn_over_d(ex_ratio*ef,
+ pdf_font_expand_ratio[pdf_font_stretch[f]],
+ 1000000))
else if (pdf_font_shrink[f] <> null_font) and (ex_ratio < 0) then
- k := expand_font(f, -divide_scaled(ex_ratio*
- pdf_font_expand_ratio[pdf_font_shrink[f]]*ef,
- 1000000, 0))
+ k := expand_font(f, ext_xn_over_d(ex_ratio*ef,
+ -pdf_font_expand_ratio[pdf_font_shrink[f]],
+ 1000000))
else
k := f;
if k <> f then begin
@@ -20228,30 +20335,32 @@ if p<>null then
x := x + width(p);
end;
kern_node: begin
- if (m = cal_expand_ratio) and (subtype(p) = normal) then begin
- k := kern_stretch(p);
- if k <> 0 then begin
- subtype(p) := substituted;
- font_stretch := font_stretch + k;
- end;
- k := kern_shrink(p);
- if k <> 0 then begin
- subtype(p) := substituted;
- font_shrink := font_shrink + k;
+ if subtype(p) = normal then begin
+ if m = cal_expand_ratio then begin
+ font_stretch := font_stretch + kern_stretch(p);
+ font_shrink := font_shrink + kern_shrink(p);
+ end
+ else if m = subst_ex_font then begin
+ if font_expand_ratio > 0 then
+ k := kern_stretch(p)
+ else if font_expand_ratio < 0 then
+ k := kern_shrink(p)
+ else
+ pdfassert(0);
+ if k <> 0 then begin
+ if is_char_node(link(p)) then
+ width(p) := get_kern(font(prev_char_p),
+ character(prev_char_p),
+ character(link(p)))
+ else if type(link(p)) = ligature_node then
+ width(p) := get_kern(font(prev_char_p),
+ character(prev_char_p),
+ character(lig_char(link(p))));
+ end;
end;
- end
- else if (m = subst_ex_font) and (subtype(p) = substituted) then begin
- if type(link(p)) = ligature_node then
- width(p) := get_kern(font(prev_char_p),
- character(prev_char_p),
- character(lig_char(link(p))))
- else
- width(p) := get_kern(font(prev_char_p),
- character(prev_char_p),
- character(link(p)))
- end;
- x := x + width(p);
end;
+ x := x + width(p);
+ end;
math_node: begin x:=x+width(p);
if TeXXeT_en then @<Adjust \(t)the LR stack for the |hpack| routine@>;
end;
@@ -20659,7 +20768,7 @@ baselineskip calculation is handled by the |append_to_vlist| routine.
@p procedure append_to_vlist(@!b:pointer);
var d:scaled; {deficiency of space between baselines}
@!p:pointer; {a new glue specification}
-begin if prev_depth>ignore_depth then
+begin if prev_depth>pdf_ignored_dimen then
begin d:=width(baseline_skip)-prev_depth-height(b);
if d<line_skip_limit then p:=new_param_glue(line_skip_code)
else begin p:=new_skip_param(baseline_skip_code);
@@ -22905,7 +23014,7 @@ entered, so that the columns will generate a list for subsequent packaging.
procedure init_span(@!p:pointer);
begin push_nest;
if mode=-hmode then space_factor:=1000
-else begin prev_depth:=ignore_depth; normal_paragraph;
+else begin prev_depth:=pdf_ignored_dimen; normal_paragraph;
end;
cur_span:=p;
end;
@@ -25221,14 +25330,21 @@ if left_skip<>zero_glue then
link(r):=q; q:=r;
end
+@ @<Initialize table entries...@>=
+pdf_ignored_dimen := ignore_depth;
+pdf_each_line_height := pdf_ignored_dimen;
+pdf_each_line_depth := pdf_ignored_dimen;
+pdf_first_line_height := pdf_ignored_dimen;
+pdf_last_line_depth := pdf_ignored_dimen;
+
@ @<Append the new box to the current vertical list...@>=
-if pdf_each_line_height <> 0 then
+if pdf_each_line_height <> pdf_ignored_dimen then
height(just_box) := pdf_each_line_height;
-if pdf_each_line_depth <> 0 then
+if pdf_each_line_depth <> pdf_ignored_dimen then
depth(just_box) := pdf_each_line_depth;
-if (pdf_first_line_height <> 0) and (cur_line = prev_graf + 1) then
+if (pdf_first_line_height <> pdf_ignored_dimen) and (cur_line = prev_graf + 1) then
height(just_box) := pdf_first_line_height;
-if (pdf_last_line_depth <> 0) and (cur_line + 1 = best_line) then
+if (pdf_last_line_depth <> pdf_ignored_dimen) and (cur_line + 1 = best_line) then
depth(just_box) := pdf_last_line_depth;
if pre_adjust_head <> pre_adjust_tail then
append_list(pre_adjust_head)(pre_adjust_tail);
@@ -27838,7 +27954,7 @@ end
@ @<Fire up the user's output routine and |return|@>=
begin output_active:=true;
incr(dead_cycles);
-push_nest; mode:=-vmode; prev_depth:=ignore_depth; mode_line:=-line;
+push_nest; mode:=-vmode; prev_depth:=pdf_ignored_dimen; mode_line:=-line;
begin_token_list(output_routine,output_text);
new_save_level(output_group); normal_paragraph;
scan_left_brace;
@@ -28474,11 +28590,11 @@ is short, since the |scan_rule_spec| routine already does most of what is
required; thus, there is no need for a special action procedure.
Note that baselineskip calculations are disabled after a rule in vertical
-mode, by setting |prev_depth:=ignore_depth|.
+mode, by setting |prev_depth:=pdf_ignored_dimen|.
@<Cases of |main_control| that build...@>=
vmode+hrule,hmode+vrule,mmode+vrule: begin tail_append(scan_rule_spec);
- if abs(mode)=vmode then prev_depth:=ignore_depth
+ if abs(mode)=vmode then prev_depth:=pdf_ignored_dimen
else if abs(mode)=hmode then space_factor:=1000;
end;
@@ -29003,7 +29119,7 @@ else begin if k=vmode then scan_spec(vbox_group,true)
end;
push_nest; mode:=-k;
if k=vmode then
- begin prev_depth:=ignore_depth;
+ begin prev_depth:=pdf_ignored_dimen;
if every_vbox<>null then begin_token_list(every_vbox,every_vbox_text);
end
else begin space_factor:=1000;
@@ -29204,7 +29320,7 @@ else
saved(1) := 0;
save_ptr := save_ptr + 2;
new_save_level(insert_group); scan_left_brace; normal_paragraph;
-push_nest; mode:=-vmode; prev_depth:=ignore_depth;
+push_nest; mode:=-vmode; prev_depth:=pdf_ignored_dimen;
end;
@ @<Cases of |handle...@>=
@@ -30138,7 +30254,7 @@ end
@ @<Cases of |main_control| that build...@>=
mmode+vcenter: begin scan_spec(vcenter_group,false); normal_paragraph;
- push_nest; mode:=-vmode; prev_depth:=ignore_depth;
+ push_nest; mode:=-vmode; prev_depth:=pdf_ignored_dimen;
if every_vbox<>null then begin_token_list(every_vbox,every_vbox_text);
end;
@@ -30764,6 +30880,7 @@ any_mode(def_family),
any_mode(set_font),
any_mode(def_font),
any_mode(letterspace_font),
+any_mode(pdf_copy_font),
any_mode(register),
any_mode(advance),
any_mode(multiply),
@@ -31506,6 +31623,7 @@ endcases;
@<Assignments@>=
def_font: new_font(a);
letterspace_font: new_letterspaced_font(a);
+pdf_copy_font: make_font_copy(a);
@ @<Declare subprocedures for |prefixed_command|@>=
procedure new_font(@!a:small_number);
@@ -31947,6 +32065,7 @@ begin @<If dumping is not allowed, abort@>;
@<Dump the table of equivalents@>;
@<Dump the font information@>;
@<Dump the hyphenation tables@>;
+@<Dump pdftex data@>;
@<Dump a couple more things and the closing check word@>;
@<Close the format file@>;
end;
@@ -31976,7 +32095,9 @@ begin @<Undump constants for consistency check@>;
@<Undump the table of equivalents@>;
@<Undump the font information@>;
@<Undump the hyphenation tables@>;
+@<Undump pdftex data@>;
@<Undump a couple more things and the closing check word@>;
+prev_depth := pdf_ignored_dimen;
load_fmt_file:=true; return; {it worked!}
bad_fmt: wake_up_terminal;
wterm_ln('(Fatal format file error; I''m stymied)');
@@ -32367,6 +32488,78 @@ while j>0 do
end;
@!init trie_not_ready:=false @+tini
+@ Store some of the pdftex data structures in the format. The idea here is
+to ensure that any data structures referenced from pdftex-specific whatsit
+nodes are retained. For the sake of simplicity and speed, all the filled parts
+of |pdf_mem| and |obj_tab| are retained, in the present implementation. We also
+retain three of the linked lists that start from |head_tab|, so that it is
+possible to, say, load an image in the \.{INITEX} run and then reference it in a
+\.{VIRTEX} run that uses the dumped format.
+
+@<Dump pdftex data@>=
+begin
+dumpimagemeta; {the image information array }
+dump_int(pdf_mem_size);
+dump_int(pdf_mem_ptr);
+for k:=1 to pdf_mem_ptr-1 do begin
+ dump_int(pdf_mem[k]);
+ end;
+print_ln; print_int(pdf_mem_ptr-1); print(" words of pdfTeX memory");
+dump_int(obj_tab_size);
+dump_int(obj_ptr);
+dump_int(sys_obj_ptr);
+for k:=1 to sys_obj_ptr do begin
+ dump_int(obj_tab[k].int0);
+ dump_int(obj_tab[k].int1);
+ dump_int(obj_tab[k].int3);
+ dump_int(obj_tab[k].int4);
+ end;
+print_ln; print_int(sys_obj_ptr); print(" indirect objects");
+dump_int(pdf_obj_count);
+dump_int(pdf_xform_count);
+dump_int(pdf_ximage_count);
+dump_int(head_tab[obj_type_obj]);
+dump_int(head_tab[obj_type_xform]);
+dump_int(head_tab[obj_type_ximage]);
+dump_int(pdf_last_obj);
+dump_int(pdf_last_xform);
+dump_int(pdf_last_ximage);
+end
+
+@ And restoring the pdftex data structures from the format. The
+two function arguments to |undumpimagemeta| have been restored
+already in an earlier module.
+
+@<Undump pdftex data@>=
+begin
+undumpimagemeta(pdf_minor_version,pdf_inclusion_errorlevel); {the image information array }
+undump_int(pdf_mem_size);
+pdf_mem := xrealloc_array(pdf_mem, integer, pdf_mem_size);
+undump_int(pdf_mem_ptr);
+for k:=1 to pdf_mem_ptr-1 do begin
+ undump_int(pdf_mem[k]);
+ end;
+undump_int(obj_tab_size);
+undump_int(obj_ptr);
+undump_int(sys_obj_ptr);
+for k:=1 to sys_obj_ptr do begin
+ undump_int(obj_tab[k].int0);
+ undump_int(obj_tab[k].int1);
+ obj_tab[k].int2 := -1;
+ undump_int(obj_tab[k].int3);
+ undump_int(obj_tab[k].int4);
+ end;
+undump_int(pdf_obj_count);
+undump_int(pdf_xform_count);
+undump_int(pdf_ximage_count);
+undump_int(head_tab[obj_type_obj]);
+undump_int(head_tab[obj_type_xform]);
+undump_int(head_tab[obj_type_ximage]);
+undump_int(pdf_last_obj);
+undump_int(pdf_last_xform);
+undump_int(pdf_last_ximage);
+end
+
@ We have already printed a lot of statistics, so we set |tracing_stats:=0|
to prevent them from appearing again.
@@ -34276,7 +34469,7 @@ begin
f := cur_val;
if f = null_font then
pdf_error("font", "invalid font identifier");
- pdf_check_vf(f);
+ pdf_check_vf_cur_val;
if not font_used[f] then
pdf_init_font(f);
scan_pdf_ext_toks;
@@ -35283,13 +35476,16 @@ begin
pdf_error("ext4", "annotations cannot be inside an XForm");
if doing_leaders then
return;
+ if is_obj_scheduled(pdf_annot_objnum(p)) then
+ pdf_annot_objnum(p) := pdf_new_objnum;
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);
+ set_obj_scheduled(pdf_annot_objnum(p));
end;
-@ To implement nesting link annotations, we need a stack to hold copy of
+@ To implement nested link annotations, we need a stack to hold copy of
|pdf_start_link_node|'s that are being written out, together with their box
nesting level.
@@ -35338,6 +35534,8 @@ begin
if not is_shipping_page then
pdf_error("ext4", "link annotations cannot be inside an XForm");
pdfassert(type(parent_box) = hlist_node);
+ if is_obj_scheduled(pdf_link_objnum(p)) then
+ pdf_link_objnum(p) := pdf_new_objnum;
push_link_level(p);
set_rect_dimens(p, parent_box, x, y,
pdf_width(p), pdf_height(p), pdf_depth(p),
@@ -35345,6 +35543,7 @@ begin
obj_annot_ptr(pdf_link_objnum(p)) := p; {the reference for the pdf annot object
must be set here}
pdf_append_list(pdf_link_objnum(p))(pdf_link_list);
+ set_obj_scheduled(pdf_link_objnum(p));
end;
procedure end_link;
diff --git a/Build/source/texk/web2c/pdftexdir/pdftexextra.in b/Build/source/texk/web2c/pdftexdir/pdftexextra.in
index fec48fd313e..1af7e0628da 100644
--- a/Build/source/texk/web2c/pdftexdir/pdftexextra.in
+++ b/Build/source/texk/web2c/pdftexdir/pdftexextra.in
@@ -1,5 +1,5 @@
/*
-Copyright (c) 1996-2004 Han The Thanh, <thanh@pdftex.org>
+Copyright (c) 1996-2007 Han The Thanh, <thanh@pdftex.org>
This file is part of pdfTeX.
@@ -13,11 +13,11 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
-You should have received a copy of the GNU General Public License
-along with pdfTeX; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+You should have received a copy of the GNU General Public License along
+with pdfTeX; if not, write to the Free Software Foundation, Inc., 51
+Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-$Id: pdftexextra.in,v 1.4 2004/08/26 18:19:57 olaf Exp $
+$Id: pdftexextra.in 200 2007-07-11 13:11:12Z oneiros $
*/
/* pdftexextra.in: banner etc. for pdfTeX.
diff --git a/Build/source/texk/web2c/pdftexdir/pdftoepdf.cc b/Build/source/texk/web2c/pdftexdir/pdftoepdf.cc
index 780cd75bda2..ae770e2e6bf 100644
--- a/Build/source/texk/web2c/pdftexdir/pdftoepdf.cc
+++ b/Build/source/texk/web2c/pdftexdir/pdftoepdf.cc
@@ -1,5 +1,5 @@
/*
-Copyright 1996-2006 Han The Thanh, <thanh@pdftex.org>
+Copyright 1996-2007 Han The Thanh, <thanh@pdftex.org>
This file is part of pdfTeX.
@@ -13,11 +13,11 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
-You should have received a copy of the GNU General Public License
-along with pdfTeX; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+You should have received a copy of the GNU General Public License along
+with pdfTeX; if not, write to the Free Software Foundation, Inc., 51
+Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-$Id: pdftoepdf.cc,v 1.9 2006/09/01 18:06:52 hahe Exp hahe $
+$Id: pdftoepdf.cc 200 2007-07-11 13:11:12Z oneiros $
*/
#include <stdlib.h>
@@ -281,7 +281,7 @@ static void copyName(char *s)
pdf_puts("/");
for (; *s != 0; s++) {
if (isdigit(*s) || isupper(*s) || islower(*s) || *s == '_' ||
- *s == '.' || *s == '-')
+ *s == '.' || *s == '-' || *s == '+')
pdfout(*s);
else
pdf_printf("#%.2X", *s & 0xFF);
@@ -381,7 +381,7 @@ static void copyFont(char *tag, Object * fontRef)
}
// Only handle included Type1 (and Type1C) fonts; anything else will be copied.
// Type1C fonts are replaced by Type1 fonts, if REPLACE_TYPE1C is true.
- if (fontRef->fetch(xref, &fontdict)->isDict()
+ if (!fixedinclusioncopyfont && fontRef->fetch(xref, &fontdict)->isDict()
&& fontdict->dictLookup("Subtype", &subtype)->isName()
&& !strcmp(subtype->getName(), "Type1")
&& fontdict->dictLookup("BaseFont", &basefont)->isName()
@@ -575,9 +575,9 @@ static void copyObject(Object * obj)
} else if (obj->isRef()) {
ref = obj->getRef();
if (ref.num == 0) {
- pdftex_warn
- ("PDF inclusion: reference to invalid object was replaced by <null>");
- pdf_puts("null");
+ pdftex_fail
+ ("PDF inclusion: reference to invalid object"
+ " (is the included pdf broken?)");
} else
pdf_printf("%d 0 R", addOther(ref));
} else {
@@ -622,8 +622,9 @@ static void writeEncodings()
for (r = encodingList; r != 0; r = r->next) {
for (i = 0; i < 256; i++) {
if (r->font->isCIDFont()) {
- pdftex_warn
- ("PDF inclusion: CID font included, encoding maybe wrong");
+ pdftex_fail
+ ("PDF inclusion: CID fonts are not supported"
+ " (try to disable font replacement to fix this)");
}
if ((s = ((Gfx8BitFont *) r->font)->getCharName(i)) != 0)
glyphNames[i] = s;
@@ -849,14 +850,14 @@ void write_epdf(void)
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));
+ pdf_puts(stripzeros(s));
}
}
}
sprintf(s, "/BBox [%.8f %.8f %.8f %.8f]\n",
pagebox->x1, pagebox->y1, pagebox->x2, pagebox->y2);
- pdf_printf(stripzeros(s));
+ pdf_puts(stripzeros(s));
// write the page Group if it's there
if (page->getGroup() != NULL) {
diff --git a/Build/source/texk/web2c/pdftexdir/pdftosrc.cc b/Build/source/texk/web2c/pdftexdir/pdftosrc.cc
index 13cf34d74c6..8b63daed92b 100644
--- a/Build/source/texk/web2c/pdftexdir/pdftosrc.cc
+++ b/Build/source/texk/web2c/pdftexdir/pdftosrc.cc
@@ -1,5 +1,5 @@
/*
-Copyright (c) 1996-2006 Han The Thanh, <thanh@pdftex.org>
+Copyright (c) 1996-2007 Han The Thanh, <thanh@pdftex.org>
This file is part of pdfTeX.
@@ -13,11 +13,11 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
-You should have received a copy of the GNU General Public License
-along with pdfTeX; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+You should have received a copy of the GNU General Public License along
+with pdfTeX; if not, write to the Free Software Foundation, Inc., 51
+Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/pdftosrc.cc#10 $
+$Id: pdftosrc.cc 200 2007-07-11 13:11:12Z oneiros $
*/
#include <stdlib.h>
diff --git a/Build/source/texk/web2c/pdftexdir/pkin.c b/Build/source/texk/web2c/pdftexdir/pkin.c
index 7d7c863b7a4..a25b9bec7a7 100644
--- a/Build/source/texk/web2c/pdftexdir/pkin.c
+++ b/Build/source/texk/web2c/pdftexdir/pkin.c
@@ -1,5 +1,5 @@
/*
-Copyright (c) 1996-2002 Han The Thanh, <thanh@pdftex.org>
+Copyright (c) 1996-2007 Han The Thanh, <thanh@pdftex.org>
This file is part of pdfTeX.
@@ -13,11 +13,11 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
-You should have received a copy of the GNU General Public License
-along with pdfTeX; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+You should have received a copy of the GNU General Public License along
+with pdfTeX; if not, write to the Free Software Foundation, Inc., 51
+Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/pkin.c#4 $
+$Id: pkin.c 200 2007-07-11 13:11:12Z oneiros $
*/
/*
diff --git a/Build/source/texk/web2c/pdftexdir/ptexlib.h b/Build/source/texk/web2c/pdftexdir/ptexlib.h
index c915b8fd47b..b3633cdb63e 100644
--- a/Build/source/texk/web2c/pdftexdir/ptexlib.h
+++ b/Build/source/texk/web2c/pdftexdir/ptexlib.h
@@ -1,5 +1,5 @@
/*
-Copyright (c) 1996-2006 Han The Thanh, <thanh@pdftex.org>
+Copyright (c) 1996-2007 Han The Thanh, <thanh@pdftex.org>
This file is part of pdfTeX.
@@ -13,11 +13,11 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
-You should have received a copy of the GNU General Public License
-along with pdfTeX; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+You should have received a copy of the GNU General Public License along
+with pdfTeX; if not, write to the Free Software Foundation, Inc., 51
+Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/ptexlib.h#26 $
+$Id: ptexlib.h 200 2007-07-11 13:11:12Z oneiros $
*/
#ifndef PDFTEXLIB
@@ -76,6 +76,11 @@ typedef struct {
char *unicode_seq; /* multiple unicode sequence */
} glyph_unicode_entry;
+# define FD_FLAGS_NOT_SET_IN_MAPLINE -1
+# define FD_FLAGS_DEFAULT_EMBED 4 /* a symbol font */
+# define FD_FLAGS_DEFAULT_NON_EMBED 0x22
+ /* a nonsymbolic serif font */
+
typedef struct {
/* parameters scanned from the map file: */
char *tfm_name; /* TFM file name (1st field in map line) */
@@ -178,6 +183,7 @@ 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);
+extern int check_std_t1font(char *s);
/* papersiz.c */
extern integer myatodim(char **);
@@ -266,13 +272,17 @@ extern scaled getury();
extern void allocvffnts();
/* vfpacket.c */
-extern eightbits packetbyte(void);
extern integer newvfpacket(internalfontnumber);
+extern void storepacket(internalfontnumber, eightbits, strnumber);
+extern void startpacket(internalfontnumber, eightbits);
+extern eightbits packetbyte(void);
extern void poppacketstate(void);
extern void pushpacketstate(void);
-extern void startpacket(internalfontnumber, integer);
-extern void storepacket(integer, integer, integer);
extern void vf_free(void);
+# define SIGNED_QUAD scaled
+# define fixword integer
+extern SIGNED_QUAD sqxfw(SIGNED_QUAD sq, fixword fw);
+
/* writeenc.c */
extern fe_entry *get_fe_entry(char *);
@@ -304,6 +314,8 @@ extern void img_free(void);
extern void updateimageprocset(integer);
extern void writeimage(integer);
extern integer imagecolordepth(integer img);
+extern void dumpimagemeta();
+extern void undumpimagemeta(integer, integer);
/* writejbig2.c */
extern void flushjbig2page0objects();
@@ -325,6 +337,7 @@ extern void ttf_free(void);
/* writezip.c */
extern void writezip(boolean);
+extern void zip_free(void);
/* avlstuff.c */
extern int comp_int_entry(const void *, const void *, void *);
@@ -349,3 +362,4 @@ static const key_entry font_key[FONT_KEYS_NUM] = {
/**********************************************************************/
#endif /* PDFTEXLIB */
+// vim: ts=4
diff --git a/Build/source/texk/web2c/pdftexdir/ptexmac.h b/Build/source/texk/web2c/pdftexdir/ptexmac.h
index 29f441b6457..3a82fc99b35 100644
--- a/Build/source/texk/web2c/pdftexdir/ptexmac.h
+++ b/Build/source/texk/web2c/pdftexdir/ptexmac.h
@@ -1,5 +1,5 @@
/*
-Copyright (c) 1996-2006 Han The Thanh, <thanh@pdftex.org>
+Copyright (c) 1996-2007 Han The Thanh, <thanh@pdftex.org>
This file is part of pdfTeX.
@@ -13,11 +13,11 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
-You should have received a copy of the GNU General Public License
-along with pdfTeX; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+You should have received a copy of the GNU General Public License along
+with pdfTeX; if not, write to the Free Software Foundation, Inc., 51
+Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-$Id: ptexmac.h,v 1.14 2005/11/29 22:05:23 hahe Exp $
+$Id: ptexmac.h 200 2007-07-11 13:11:12Z oneiros $
*/
#ifndef PDFTEXMAC
diff --git a/Build/source/texk/web2c/pdftexdir/subfont.c b/Build/source/texk/web2c/pdftexdir/subfont.c
index 09b681781ef..24c6aab87da 100644
--- a/Build/source/texk/web2c/pdftexdir/subfont.c
+++ b/Build/source/texk/web2c/pdftexdir/subfont.c
@@ -1,5 +1,5 @@
/*
-Copyright (c) 2005-2006 Han The Thanh, <thanh@pdftex.org>
+Copyright (c) 2005-2007 Han The Thanh, <thanh@pdftex.org>
This file is part of pdfTeX.
@@ -13,9 +13,11 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
-You should have received a copy of the GNU General Public License
-along with pdfTeX; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+You should have received a copy of the GNU General Public License along
+with pdfTeX; if not, write to the Free Software Foundation, Inc., 51
+Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+$Id: subfont.c 200 2007-07-11 13:11:12Z oneiros $
*/
#include "ptexlib.h"
diff --git a/Build/source/texk/web2c/pdftexdir/tex.ch0 b/Build/source/texk/web2c/pdftexdir/tex.ch0
index 2dcb3746d6f..c63a9780604 100644
--- a/Build/source/texk/web2c/pdftexdir/tex.ch0
+++ b/Build/source/texk/web2c/pdftexdir/tex.ch0
@@ -1,5 +1,5 @@
%
-% Copyright (c) 1996-2002 Han The Thanh, <thanh@pdftex.org>
+% Copyright (c) 1996-2007 Han The Thanh, <thanh@pdftex.org>
%
% This file is part of pdfTeX.
%
@@ -13,11 +13,11 @@
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
-% You should have received a copy of the GNU General Public License
-% along with pdfTeX; if not, write to the Free Software
-% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+% You should have received a copy of the GNU General Public License along with
+% pdfTeX; if not, write to the Free Software Foundation, Inc., 51 Franklin
+% Street, Fifth Floor, Boston, MA 02110-1301 USA.
%
-% $Id: //depot/Build/source.development/TeX/texk/web2c/pdfetexdir/tex.ch0#10 $
+% $Id: tex.ch0 200 2007-07-11 13:11:12Z oneiros $
%
% Change file to assist in creating the web2c-specific change file.
% This one comes first, resolves inconsistencies between the generated
diff --git a/Build/source/texk/web2c/pdftexdir/tounicode.c b/Build/source/texk/web2c/pdftexdir/tounicode.c
index f30e44eff04..b2126a7890a 100644
--- a/Build/source/texk/web2c/pdftexdir/tounicode.c
+++ b/Build/source/texk/web2c/pdftexdir/tounicode.c
@@ -1,5 +1,5 @@
/*
-Copyright (c) 2006 Han The Thanh, <thanh@pdftex.org>
+Copyright (c) 2006-2007 Han The Thanh, <thanh@pdftex.org>
This file is part of pdfTeX.
@@ -13,9 +13,11 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
-You should have received a copy of the GNU General Public License
-along with pdfTeX; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+You should have received a copy of the GNU General Public License along
+with pdfTeX; if not, write to the Free Software Foundation, Inc., 51
+Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+$Id: tounicode.c 200 2007-07-11 13:11:12Z oneiros $
*/
#include "ptexlib.h"
diff --git a/Build/source/texk/web2c/pdftexdir/ttf2afm.c b/Build/source/texk/web2c/pdftexdir/ttf2afm.c
index ce7af81553a..4b8d2ddec80 100644
--- a/Build/source/texk/web2c/pdftexdir/ttf2afm.c
+++ b/Build/source/texk/web2c/pdftexdir/ttf2afm.c
@@ -1,5 +1,5 @@
/*
-Copyright (c) 1996-2006 Han The Thanh, <thanh@pdftex.org>
+Copyright (c) 1996-2007 Han The Thanh, <thanh@pdftex.org>
This file is part of pdfTeX.
@@ -13,11 +13,11 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
-You should have received a copy of the GNU General Public License
-along with pdfTeX; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+You should have received a copy of the GNU General Public License along
+with pdfTeX; if not, write to the Free Software Foundation, Inc., 51
+Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/ttf2afm.c#21 $
+$Id: ttf2afm.c 200 2007-07-11 13:11:12Z oneiros $
*/
/*
diff --git a/Build/source/texk/web2c/pdftexdir/utils.c b/Build/source/texk/web2c/pdftexdir/utils.c
index f2d12e036a5..b8f63d52201 100644
--- a/Build/source/texk/web2c/pdftexdir/utils.c
+++ b/Build/source/texk/web2c/pdftexdir/utils.c
@@ -1,5 +1,5 @@
/*
-Copyright (c) 1996-2006 Han The Thanh, <thanh@pdftex.org>
+Copyright (c) 1996-2007 Han The Thanh, <thanh@pdftex.org>
This file is part of pdfTeX.
@@ -13,11 +13,11 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
-You should have received a copy of the GNU General Public License
-along with pdfTeX; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+You should have received a copy of the GNU General Public License along
+with pdfTeX; if not, write to the Free Software Foundation, Inc., 51
+Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/utils.c#24 $
+$Id: utils.c 200 2007-07-11 13:11:12Z oneiros $
*/
#include "openbsd-compat.h"
@@ -438,6 +438,7 @@ void libpdffinish()
ttf_free();
sfd_free();
glyph_unicode_free();
+ zip_free();
}
/* Converts any string given in in in an allowed PDF string which can be
@@ -684,7 +685,7 @@ void unescapehex(poolpointer in)
first = true;
}
if (!first) { /* last hex digit is omitted */
- strpool[poolptr++] = ch << 4;
+ strpool[poolptr++] = a;
}
}
@@ -919,6 +920,7 @@ void getfilemoddate(strnumber s)
return; /* empty string */
}
+ recorder_record_input(file_name);
/* get file status */
if (stat(file_name, &file_data) == 0) {
size_t len;
@@ -948,6 +950,7 @@ void getfilesize(strnumber s)
return; /* empty string */
}
+ recorder_record_input(file_name);
/* get file status */
if (stat(file_name, &file_data) == 0) {
size_t len;
@@ -998,6 +1001,7 @@ void getmd5sum(strnumber s, boolean file)
xfree(file_name);
return;
}
+ recorder_record_input(file_name);
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);
@@ -1055,6 +1059,7 @@ void getfiledump(strnumber s, int offset, int length)
xfree(file_name);
return;
}
+ recorder_record_input(file_name);
if (fseek(f, (long) offset, SEEK_SET) != 0) {
xfree(file_name);
return;
@@ -1639,7 +1644,7 @@ void pdfshipoutbegin(boolean shipping_page)
void pdfshipoutend(boolean shipping_page)
{
if (pos_stack_used > 0) {
- pdftex_warn("%u unmatched \\pdfsave after %s shipout",
+ pdftex_fail("%u unmatched \\pdfsave after %s shipout",
(unsigned int) pos_stack_used,
((shipping_page) ? "page" : "form"));
}
diff --git a/Build/source/texk/web2c/pdftexdir/vfpacket.c b/Build/source/texk/web2c/pdftexdir/vfpacket.c
index 09cefeacd39..70accdcf13a 100644
--- a/Build/source/texk/web2c/pdftexdir/vfpacket.c
+++ b/Build/source/texk/web2c/pdftexdir/vfpacket.c
@@ -1,5 +1,5 @@
/*
-Copyright (c) 1996-2002 Han The Thanh, <thanh@pdftex.org>
+Copyright (c) 1996-2007 Han The Thanh, <thanh@pdftex.org>
This file is part of pdfTeX.
@@ -13,19 +13,18 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
-You should have received a copy of the GNU General Public License
-along with pdfTeX; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+You should have received a copy of the GNU General Public License along
+with pdfTeX; if not, write to the Free Software Foundation, Inc., 51
+Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/vfpacket.c#7 $
+$Id: vfpacket.c 200 2007-07-11 13:11:12Z oneiros $
*/
#include "ptexlib.h"
typedef struct {
- internalfontnumber font;
char *dataptr;
- int len;
+ integer len;
} packet_entry;
/* define packet_ptr, packet_array & packet_limit */
@@ -34,7 +33,7 @@ define_array(packet);
typedef struct {
char **data;
int *len;
- internalfontnumber font;
+ int char_count;
} vf_entry;
/* define vf_ptr, vf_array & vf_limit */
@@ -48,15 +47,15 @@ integer newvfpacket(internalfontnumber f)
alloc_array(vf, 1, SMALL_ARRAY_SIZE);
vf_ptr->len = xtalloc(n, int);
vf_ptr->data = xtalloc(n, char *);
+ vf_ptr->char_count = n;
for (i = 0; i < n; i++) {
vf_ptr->data[i] = NULL;
vf_ptr->len[i] = 0;
}
- vf_ptr->font = f;
return vf_ptr++ - vf_array;
}
-void storepacket(integer f, integer c, integer s)
+void storepacket(internalfontnumber f, eightbits c, strnumber s)
{
int l = strstart[s + 1] - strstart[s];
vf_array[vfpacketbase[f]].len[c - fontbc[f]] = l;
@@ -65,10 +64,21 @@ void storepacket(integer f, integer c, integer s)
(void *) (strpool + strstart[s]), (unsigned) l);
}
+void startpacket(internalfontnumber f, eightbits c)
+{
+ packet_data_ptr = vf_array[vfpacketbase[f]].data[c - fontbc[f]];
+ vfpacketlength = vf_array[vfpacketbase[f]].len[c - fontbc[f]];
+}
+
+eightbits packetbyte()
+{
+ vfpacketlength--;
+ return *packet_data_ptr++;
+}
+
void pushpacketstate()
{
alloc_array(packet, 1, SMALL_ARRAY_SIZE);
- packet_ptr->font = f;
packet_ptr->dataptr = packet_data_ptr;
packet_ptr->len = vfpacketlength;
packet_ptr++;
@@ -79,33 +89,18 @@ void poppacketstate()
if (packet_ptr == packet_array)
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)
-{
- packet_data_ptr = vf_array[vfpacketbase[f]].data[c - fontbc[f]];
- vfpacketlength = vf_array[vfpacketbase[f]].len[c - fontbc[f]];
-}
-
-eightbits packetbyte()
-{
- vfpacketlength--;
- return *packet_data_ptr++;
-}
-
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);
- n = fontec[v->font] - fontbc[v->font] + 1;
- for (p = v->data; p - v->data < n; p++)
+ for (p = v->data; p - v->data < v->char_count; p++)
xfree(*p);
xfree(v->data);
}
@@ -113,3 +108,42 @@ void vf_free(void)
}
xfree(packet_array);
}
+
+/* this function was copied/borrowed/stolen from dvipdfm code */
+#define SIGNED_QUAD scaled
+#define fixword integer
+SIGNED_QUAD sqxfw(SIGNED_QUAD sq, fixword fw)
+{
+ int sign = 1;
+ unsigned long a, b, c, d, ad, bd, bc, ac;
+ unsigned long e, f, g, h, i, j, k;
+ unsigned long result;
+ /* Make positive. */
+ if (sq < 0) {
+ sign = -sign;
+ sq = -sq;
+ }
+ if (fw < 0) {
+ sign = -sign;
+ fw = -fw;
+ }
+ a = ((unsigned long) sq) >> 16u;
+ b = ((unsigned long) sq) & 0xffffu;
+ c = ((unsigned long) fw) >> 16u;
+ d = ((unsigned long) fw) & 0xffffu;
+ ad = a * d;
+ bd = b * d;
+ bc = b * c;
+ ac = a * c;
+ e = bd >> 16u;
+ f = ad >> 16u;
+ g = ad & 0xffffu;
+ h = bc >> 16u;
+ i = bc & 0xffffu;
+ j = ac >> 16u;
+ k = ac & 0xffffu;
+ result = (e + g + i + (1 << 3)) >> 4u; /* 1<<3 is for rounding */
+ result += (f + h + k) << 12u;
+ result += j << 28u;
+ return (sign > 0) ? result : -result;
+}
diff --git a/Build/source/texk/web2c/pdftexdir/writeenc.c b/Build/source/texk/web2c/pdftexdir/writeenc.c
index f4c299479d9..e420cf70d29 100644
--- a/Build/source/texk/web2c/pdftexdir/writeenc.c
+++ b/Build/source/texk/web2c/pdftexdir/writeenc.c
@@ -1,5 +1,5 @@
/*
-Copyright (c) 1996-2005 Han The Thanh, <thanh@pdftex.org>
+Copyright (c) 1996-2007 Han The Thanh, <thanh@pdftex.org>
This file is part of pdfTeX.
@@ -13,11 +13,11 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
-You should have received a copy of the GNU General Public License
-along with pdfTeX; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+You should have received a copy of the GNU General Public License along
+with pdfTeX; if not, write to the Free Software Foundation, Inc., 51
+Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-$Id: writeenc.c,v 1.3 2005/12/26 14:20:13 hahe Exp hahe $
+$Id: writeenc.c 200 2007-07-11 13:11:12Z oneiros $
*/
#include "ptexlib.h"
@@ -93,7 +93,7 @@ void epdf_write_enc(char **glyph_names, integer fe_objnum)
assert(fe_objnum != 0);
pdfbegindict(fe_objnum, 1);
pdf_puts("/Type /Encoding\n");
- pdf_printf("/Differences [");
+ pdf_puts("/Differences [");
for (i = 0, i_old = -2; i < 256; i++)
if (glyph_names[i] != notdef) {
if (i == i_old + 1) /* no gap */
@@ -119,7 +119,7 @@ void write_enc(char **glyph_names, struct avl_table *tx_tree, integer fe_objnum)
assert(fe_objnum != 0);
pdfbegindict(fe_objnum, 1);
pdf_puts("/Type /Encoding\n");
- pdf_printf("/Differences [");
+ pdf_puts("/Differences [");
avl_t_init(&t, tx_tree);
for (i_old = -2, p = (int *) avl_t_first(&t, tx_tree); p != NULL;
p = (int *) avl_t_next(&t)) {
diff --git a/Build/source/texk/web2c/pdftexdir/writefont.c b/Build/source/texk/web2c/pdftexdir/writefont.c
index 3a7a13cd5d3..76e2a3a43ef 100644
--- a/Build/source/texk/web2c/pdftexdir/writefont.c
+++ b/Build/source/texk/web2c/pdftexdir/writefont.c
@@ -13,11 +13,11 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
-You should have received a copy of the GNU General Public License
-along with pdfTeX; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+You should have received a copy of the GNU General Public License along
+with pdfTeX; if not, write to the Free Software Foundation, Inc., 51
+Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-$Id: writefont.c,v 1.3 2005/12/27 19:04:42 hahe Exp $
+$Id: writefont.c 200 2007-07-11 13:11:12Z oneiros $
*/
#include "ptexlib.h"
@@ -137,9 +137,32 @@ static void preset_fontmetrics(fd_entry * fd, internalfontnumber f)
fd->font_dim[i].set = true;
}
+static void fix_fontmetrics(fd_entry * fd)
+{
+ intparm *p = (intparm *) fd->font_dim;
+ if (!p[FONTBBOX1_CODE].set || !p[FONTBBOX2_CODE].set ||
+ !p[FONTBBOX3_CODE].set || !p[FONTBBOX4_CODE].set) {
+ pdftex_warn("font `%s' doesn't have a BoundingBox", fd->fm->ff_name);
+ return;
+ }
+ if (!p[ASCENT_CODE].set) {
+ p[ASCENT_CODE].val = p[FONTBBOX4_CODE].val;
+ p[ASCENT_CODE].set = true;
+ }
+ if (!p[DESCENT_CODE].set) {
+ p[DESCENT_CODE].val = p[FONTBBOX2_CODE].val;
+ p[DESCENT_CODE].set = true;
+ }
+ if (!p[CAPHEIGHT_CODE].set) {
+ p[CAPHEIGHT_CODE].val = p[FONTBBOX4_CODE].val;
+ p[CAPHEIGHT_CODE].set = true;
+ }
+}
+
static void write_fontmetrics(fd_entry * fd)
{
int i;
+ fix_fontmetrics(fd);
if (fd->font_dim[FONTBBOX1_CODE].set && fd->font_dim[FONTBBOX2_CODE].set
&& fd->font_dim[FONTBBOX3_CODE].set && fd->font_dim[FONTBBOX4_CODE].set)
pdf_printf("/%s [%i %i %i %i]\n", font_key[FONTBBOX1_CODE].pdfname,
@@ -413,8 +436,29 @@ static void write_fontfile(fd_entry * fd)
static void write_fontdescriptor(fd_entry * fd)
{
+ static const int std_flags[] = {
+ /* indices for << start with 0, but bits start with 1, so the numbers
+ * for << are 1 lower than the bits in table 5.20 */
+ /* *INDENT-OFF* */
+ 1 + 2 + (1 << 5), /* Courier */
+ 1 + 2 + (1 << 5) + (1 << 18),/* Courier-Bold */
+ 1 + 2 + (1 << 5) + (1 << 6), /* Courier-Oblique */
+ 1 + 2 + (1 << 5) + (1 << 6) + (1 << 18),/* Courier-BoldOblique */
+ (1 << 5), /* Helvetica */
+ (1 << 5) + (1 << 18),/* Helvetica-Bold */
+ (1 << 5) + (1 << 6), /* Helvetica-Oblique */
+ (1 << 5) + (1 << 6) + (1 << 18),/* Helvetica-BoldOblique */
+ 4, /* Symbol */
+ 2 + (1 << 5), /* Times-Roman */
+ 2 + (1 << 5) + (1 << 18),/* Times-Bold */
+ 2 + (1 << 5) + (1 << 6), /* Times-Italic */
+ 2 + (1 << 5) + (1 << 6) + (1 << 18),/* Times-BoldItalic */
+ 4 /* ZapfDingbats */
+ /* *INDENT-ON* */
+ };
char *glyph;
struct avl_traverser t;
+ int fd_flags;
assert(fd != NULL && fd->fm != NULL);
if (is_fontfile(fd->fm))
@@ -426,10 +470,21 @@ static void write_fontdescriptor(fd_entry * fd)
pdfbegindict(fd->fd_objnum, 1);
pdf_puts("/Type /FontDescriptor\n");
write_fontname(fd, "FontName");
- if (!fd->ff_found && fd->fm->fd_flags == 4)
- pdf_puts("/Flags 34\n"); /* assumes a roman sans serif font */
- else
- pdf_printf("/Flags %i\n", (int) fd->fm->fd_flags);
+ if (fd->fm->fd_flags != FD_FLAGS_NOT_SET_IN_MAPLINE)
+ fd_flags = (int) fd->fm->fd_flags;
+ else if (fd->ff_found)
+ fd_flags = FD_FLAGS_DEFAULT_EMBED;
+ else {
+ fd_flags = is_std_t1font(fd->fm)
+ ? std_flags[check_std_t1font(fd->fm->ps_name)]
+ : FD_FLAGS_DEFAULT_NON_EMBED;
+ pdftex_warn
+ ("No flags specified for non-embedded font `%s' (%s) (I'm using %i): "
+ "fix your map entry.",
+ fd->fm->ps_name != NULL ? fd->fm->ps_name : "No name given",
+ fd->fm->tfm_name, fd_flags);
+ }
+ pdf_printf("/Flags %i\n", fd_flags);
write_fontmetrics(fd);
if (fd->ff_found) {
if (is_subsetted(fd->fm) && is_type1(fd->fm)) {
@@ -617,3 +672,4 @@ void dopdffont(integer font_objnum, internalfontnumber f)
}
/**********************************************************************/
+// vim: ts=4
diff --git a/Build/source/texk/web2c/pdftexdir/writeimg.c b/Build/source/texk/web2c/pdftexdir/writeimg.c
index 1af5abec8a7..8bd1227c6df 100644
--- a/Build/source/texk/web2c/pdftexdir/writeimg.c
+++ b/Build/source/texk/web2c/pdftexdir/writeimg.c
@@ -13,11 +13,11 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
-You should have received a copy of the GNU General Public License
-along with pdfTeX; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+You should have received a copy of the GNU General Public License along
+with pdfTeX; if not, write to the Free Software Foundation, Inc., 51
+Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/writeimg.c#17 $
+$Id: writeimg.c 200 2007-07-11 13:11:12Z oneiros $
*/
#include "ptexlib.h"
@@ -283,6 +283,7 @@ integer readimage(strnumber s, integer page_num, strnumber page_name,
pdftex_fail("cannot find image file");
/* kpse_find_file perhaps changed the file name */
cur_file_name = img_name(img);
+ recorder_record_input(cur_file_name);
/* type checks */
checktypebyheader(img);
checktypebyextension(img);
@@ -314,7 +315,7 @@ integer readimage(strnumber s, integer page_num, strnumber page_name,
if (pdfversion < 4) {
pdftex_fail
("JBIG2 images only possible with at least PDF 1.4; you are generating PDF 1.%i",
- (int)pdfversion);
+ (int) pdfversion);
}
jbig2_ptr(img) = xtalloc(1, JBIG2_IMAGE_INFO);
img_type(img) = IMAGE_TYPE_JBIG2;
@@ -358,6 +359,8 @@ void writeimage(integer img)
void deleteimage(integer img)
{
+ if (iniversion)
+ return; // The image may be \dump{}ed to a format
switch (img_type(img)) {
case IMAGE_TYPE_PDF:
epdf_doc = pdf_ptr(img)->doc;
@@ -383,3 +386,162 @@ void img_free()
{
xfree(image_array);
}
+
+
+/* To allow the use of \pdfrefximage inside saved boxes in -ini mode,
+ * the information in the array has to be (un)dumped with the format.
+ * The next two routines take care of that.
+ *
+ * Most of the work involved in setting up the images is simply
+ * executed again. This solves the many possible errors resulting from
+ * the split in two separate runs.
+
+ * There was only one problem remaining: The pdfversion and
+ * pdfinclusionerrorlevel can have changed inbetween the call to
+ * readimage() and dump time. That is why they are passed as arguments
+ * to undumpimagemeta once more.
+ */
+
+/* some of the dumped values are really type int, not integer,
+ * but since the macro falls back to generic_dump anyway, that
+ * does not matter.
+ */
+
+#define dumpsizet generic_dump
+#define dumpinteger generic_dump
+
+#define undumpsizet generic_undump
+#define undumpinteger generic_undump
+
+/* (un)dumping a string means dumping the allocation size, followed
+ * by the bytes. The trailing \0 is dumped as well, because that
+ * makes the code simpler.
+ */
+
+#define dumpcharptr(a) \
+ do { \
+ integer x; \
+ if (a!=NULL) { \
+ x = strlen(a)+1; \
+ dumpinteger(x); dumpthings(*a, x); \
+ } else { \
+ x = 0; dumpinteger(x); \
+ } \
+ } while (0)
+
+#define undumpcharptr(s) \
+ do { \
+ integer x; \
+ char *a; \
+ undumpinteger (x); \
+ if (x>0) { \
+ a = malloc(x); \
+ undumpthings(*a,x); \
+ s = a ; \
+ } else { s = NULL; } \
+ } while (0)
+
+
+
+void dumpimagemeta()
+{
+ int cur_image, img;
+
+ dumpsizet(image_limit);
+ cur_image = (image_ptr - image_array);
+ dumpinteger(cur_image);
+
+ for (img = 0; img < cur_image; img++) {
+
+ dumpcharptr(img_name(img));
+ dumpinteger(img_type(img));
+ dumpinteger(img_color(img));
+ dumpinteger(img_width(img));
+ dumpinteger(img_height(img));
+ dumpinteger(img_xres(img));
+ dumpinteger(img_yres(img));
+ dumpinteger(img_pages(img));
+ dumpinteger(img_colorspace_ref(img));
+
+ /* the image_struct is not dumped at all, except for a few
+ variables that are needed to restore the contents */
+
+ if (img_type(img) == IMAGE_TYPE_PDF) {
+ dumpinteger(pdf_ptr(img)->page_box);
+ dumpinteger(pdf_ptr(img)->selected_page);
+ } else if (img_type(img) == IMAGE_TYPE_JBIG2) {
+ dumpinteger(jbig2_ptr(img)->selected_page);
+ }
+
+ }
+}
+
+void undumpimagemeta(integer pdfversion, integer pdfinclusionerrorlevel)
+{
+ int cur_image, img;
+
+ undumpsizet(image_limit);
+
+ image_array = xtalloc(image_limit, image_entry);
+ undumpinteger(cur_image);
+ image_ptr = image_array + cur_image;
+
+ for (img = 0; img < cur_image; img++) {
+ undumpcharptr(img_name(img));
+ undumpinteger(img_type(img));
+ undumpinteger(img_color(img));
+ undumpinteger(img_width(img));
+ undumpinteger(img_height(img));
+ undumpinteger(img_xres(img));
+ undumpinteger(img_yres(img));
+ undumpinteger(img_pages(img));
+ undumpinteger(img_colorspace_ref(img));
+
+ /* if img_name(img)==NULL -- which it shouldn't be -- the next line
+ will trigger an assertion failure. */
+ if (kpse_find_file(img_name(img), kpse_tex_format, true) == NULL)
+ pdftex_fail("cannot find image file %s", img_name(img));
+
+ switch (img_type(img)) {
+ case IMAGE_TYPE_PDF:
+ pdf_ptr(img) = xtalloc(1, pdf_image_struct);
+
+ undumpinteger(pdf_ptr(img)->page_box);
+ undumpinteger(pdf_ptr(img)->selected_page);
+
+ read_pdf_info(img_name(img), NULL, pdf_ptr(img)->selected_page,
+ pdf_ptr(img)->page_box, 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)->doc = epdf_doc;
+ break;
+ case IMAGE_TYPE_PNG:
+ 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);
+ break;
+ case IMAGE_TYPE_JBIG2:
+ if (pdfversion < 4) {
+ pdftex_fail
+ ("JBIG2 images only possible with at least PDF 1.4; you are generating PDF 1.%i",
+ (int) pdfversion);
+ }
+ jbig2_ptr(img) = xtalloc(1, JBIG2_IMAGE_INFO);
+ img_type(img) = IMAGE_TYPE_JBIG2;
+ undumpinteger(jbig2_ptr(img)->selected_page);
+ read_jbig2_info(img);
+ break;
+ default:
+ pdftex_fail("unknown type of image");
+ }
+ }
+}
diff --git a/Build/source/texk/web2c/pdftexdir/writejbig2.c b/Build/source/texk/web2c/pdftexdir/writejbig2.c
index 15de6e101df..2f21e320771 100644
--- a/Build/source/texk/web2c/pdftexdir/writejbig2.c
+++ b/Build/source/texk/web2c/pdftexdir/writejbig2.c
@@ -1,5 +1,5 @@
/***********************************************************************
-Copyright (c) 2002-2006 Han The Thanh, <thanh@pdftex.org>
+Copyright (c) 2002-2007 Han The Thanh, <thanh@pdftex.org>
This file is part of pdfTeX.
@@ -14,8 +14,8 @@ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License along
-with pdfTeX; if not, write to the Free Software Foundation, Inc., 59
-Temple Place, Suite 330, Boston, MA 02111-1307 USA
+with pdfTeX; if not, write to the Free Software Foundation, Inc., 51
+Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
This is experimental JBIG2 image support to pdfTeX. JBIG2 image decoding
is part of Adobe PDF-1.4, and requires Acroread 5.0 or later.
@@ -75,7 +75,7 @@ object exists, reference it. Else create fresh one.
09 Dec. 2002: JBIG2 seg. page numbers > 0 are now set to 1, see PDF Ref.
-$Id: writejbig2.c,v 1.347 2006/05/31 19:18:32 hahe Exp hahe $
+$Id: writejbig2.c 200 2007-07-11 13:11:12Z oneiros $
***********************************************************************/
#include "writejbig2.h"
diff --git a/Build/source/texk/web2c/pdftexdir/writejbig2.h b/Build/source/texk/web2c/pdftexdir/writejbig2.h
index 90a211e1995..91ebe759d3e 100644
--- a/Build/source/texk/web2c/pdftexdir/writejbig2.h
+++ b/Build/source/texk/web2c/pdftexdir/writejbig2.h
@@ -1,5 +1,5 @@
/***********************************************************************
-Copyright (c) 2002-2006 Han The Thanh, <thanh@pdftex.org>
+Copyright (c) 2002-2007 Han The Thanh, <thanh@pdftex.org>
This file is part of pdfTeX.
@@ -14,13 +14,13 @@ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License along
-with pdfTeX; if not, write to the Free Software Foundation, Inc., 59
-Temple Place, Suite 330, Boston, MA 02111-1307 USA
+with pdfTeX; if not, write to the Free Software Foundation, Inc., 51
+Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
This is experimental JBIG2 image support to pdfTeX. JBIG2 image decoding
is part of Adobe PDF-1.4, and requires Acroread 5.0 or later.
-$Id: writejbig2.h,v 1.40 2006/05/31 19:18:51 hahe Exp hahe $
+$Id: writejbig2.h 200 2007-07-11 13:11:12Z oneiros $
***********************************************************************/
#include <stdlib.h>
diff --git a/Build/source/texk/web2c/pdftexdir/writejpg.c b/Build/source/texk/web2c/pdftexdir/writejpg.c
index 32778bb4eca..e7d5a9ee0a3 100644
--- a/Build/source/texk/web2c/pdftexdir/writejpg.c
+++ b/Build/source/texk/web2c/pdftexdir/writejpg.c
@@ -1,5 +1,5 @@
/*
-Copyright (c) 1996-2006 Han The Thanh, <thanh@pdftex.org>
+Copyright (c) 1996-2007 Han The Thanh, <thanh@pdftex.org>
This file is part of pdfTeX.
@@ -13,11 +13,11 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
-You should have received a copy of the GNU General Public License
-along with pdfTeX; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+You should have received a copy of the GNU General Public License along
+with pdfTeX; if not, write to the Free Software Foundation, Inc., 51
+Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/writejpg.c#10 $
+$Id: writejpg.c 200 2007-07-11 13:11:12Z oneiros $
*/
#include "ptexlib.h"
diff --git a/Build/source/texk/web2c/pdftexdir/writepng.c b/Build/source/texk/web2c/pdftexdir/writepng.c
index 54bd3ca4d57..85b93003271 100644
--- a/Build/source/texk/web2c/pdftexdir/writepng.c
+++ b/Build/source/texk/web2c/pdftexdir/writepng.c
@@ -1,5 +1,5 @@
/*
-Copyright (c) 1996-2004 Han The Thanh, <thanh@pdftex.org>
+Copyright (c) 1996-2007 Han The Thanh, <thanh@pdftex.org>
This file is part of pdfTeX.
@@ -13,11 +13,11 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
-You should have received a copy of the GNU General Public License
-along with pdfTeX; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+You should have received a copy of the GNU General Public License along
+with pdfTeX; if not, write to the Free Software Foundation, Inc., 51
+Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-$Id: writepng.c,v 1.2 2006/01/06 22:35:43 hahe Exp hahe $
+$Id: writepng.c 200 2007-07-11 13:11:12Z oneiros $
*/
#include "ptexlib.h"
@@ -427,14 +427,15 @@ void copy_png(integer img)
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");
+ pdf_printf("/Length %d\n"
+ "/Filter/FlateDecode\n"
+ "/DecodeParms<<"
+ "/Colors %d"
+ "/Columns %d"
+ "/BitsPerComponent %i"
+ "/Predictor 10>>\n>>\nstream\n", streamlength,
+ png_info(img)->color_type == 2 ? 3 : 1,
+ (int) png_info(img)->width, (int) png_info(img)->bit_depth);
/* 2nd pass to copy data */
endflag = false;
if (fseek(fp, 8, SEEK_SET) != 0)
diff --git a/Build/source/texk/web2c/pdftexdir/writet1.c b/Build/source/texk/web2c/pdftexdir/writet1.c
index 9d2bffb6276..923a0ca4ed2 100644
--- a/Build/source/texk/web2c/pdftexdir/writet1.c
+++ b/Build/source/texk/web2c/pdftexdir/writet1.c
@@ -1,5 +1,5 @@
/*
-Copyright (c) 1996-2006 Han The Thanh, <thanh@pdftex.org>
+Copyright (c) 1996-2007 Han The Thanh, <thanh@pdftex.org>
This file is part of pdfTeX.
@@ -13,11 +13,11 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
-You should have received a copy of the GNU General Public License
-along with pdfTeX; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+You should have received a copy of the GNU General Public License along
+with pdfTeX; if not, write to the Free Software Foundation, Inc., 51
+Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-$Id: writet1.c,v 1.6 2006/12/12 20:38:11 hahe Exp hahe $
+$Id: writet1.c 200 2007-07-11 13:11:12Z oneiros $
*/
#include "ptexlib.h"
@@ -25,7 +25,7 @@ $Id: writet1.c,v 1.6 2006/12/12 20:38:11 hahe Exp hahe $
#include <kpathsea/c-proto.h>
#include <string.h>
-#define t1_log(s) tex_printf(s)
+#define t1_log(s) tex_printf("%s",s)
#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
@@ -245,7 +245,7 @@ char **load_enc_file(char *enc_name)
char **glyph_names;
set_cur_file_name(enc_name);
if (!enc_open()) {
- pdftex_warn("cannot open encoding file for reading");
+ pdftex_fail("cannot open encoding file for reading");
cur_file_name = NULL;
return NULL;
}
@@ -539,9 +539,7 @@ static void t1_check_block_len(boolean 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);
- while (l-- > 0)
- t1_getbyte();
+ pdftex_fail("%i bytes more than expected", l + 1);
}
}
@@ -576,7 +574,7 @@ static void t1_stop_eexec(void)
if (last_hexbyte == 0)
t1_puts("00");
else
- pdftex_warn("unexpected data after eexec");
+ pdftex_fail("unexpected data after eexec");
}
}
t1_cs = false;
@@ -922,11 +920,12 @@ static boolean t1_open_fontfile(const char *open_name_prefix)
{
ff_entry *ff;
ff = check_ff_exist(fd_cur->fm->ff_name, is_truetype(fd_cur->fm));
- if (ff->ff_path != NULL)
+ if (ff->ff_path != NULL) {
t1_file = xfopen(cur_file_name = ff->ff_path, FOPEN_RBIN_MODE);
- else {
+ recorder_record_input(ff->ff_path);
+ } else {
set_cur_file_name(fd_cur->fm->ff_name);
- pdftex_warn("cannot open Type 1 font file for reading");
+ pdftex_fail("cannot open Type 1 font file for reading");
return false;
}
t1_init_params(open_name_prefix);
@@ -1032,8 +1031,8 @@ static boolean is_cc_init = false;
stack_ptr -= N
#define stack_error(N) { \
- pdftex_warn("CharString: invalid access (%i) to stack (%i entries)", \
- (int) N, (int)(stack_ptr - cc_stack)); \
+ pdftex_fail("CharString: invalid access (%i) to stack (%i entries)", \
+ (int) N, (int)(stack_ptr - cc_stack)); \
goto cs_error; \
}
@@ -1106,7 +1105,7 @@ static void cc_init(void)
#define mark_cs(s) cs_mark(s, 0)
__attribute__ ((format(printf, 3, 4)))
-static void cs_warn(const char *cs_name, int subr, const char *fmt, ...)
+static void cs_fail(const char *cs_name, int subr, const char *fmt, ...)
{
char buf[SMALL_BUF_SIZE];
va_list args;
@@ -1114,9 +1113,9 @@ static void cs_warn(const char *cs_name, int subr, const char *fmt, ...)
vsprintf(buf, fmt, args);
va_end(args);
if (cs_name == NULL)
- pdftex_warn("Subr (%i): %s", (int) subr, buf);
+ pdftex_fail("Subr (%i): %s", (int) subr, buf);
else
- pdftex_warn("CharString (/%s): %s", cs_name, buf);
+ pdftex_fail("CharString (/%s): %s", cs_name, buf);
}
static void cs_mark(const char *cs_name, int subr)
@@ -1188,22 +1187,22 @@ static void cs_mark(const char *cs_name, int subr)
cs_len--;
}
if (b >= CS_MAX) {
- cs_warn(cs_name, subr, "command value out of range: %i",
+ cs_fail(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_fail(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,
+ cs_fail(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,
+ cs_fail(cs_name, subr,
"more arguments on stack (%i) than required (%i)",
(int) (stack_ptr - cc_stack), (int) cc->nargs);
}
@@ -1213,7 +1212,7 @@ static void cs_mark(const char *cs_name, int subr)
cc_pop(1);
mark_subr(a1);
if (!subr_tab[a1].valid) {
- cs_warn(cs_name, subr, "cannot call subr (%i)", (int) a1);
+ cs_fail(cs_name, subr, "cannot call subr (%i)", (int) a1);
goto cs_error;
}
break;
@@ -1384,7 +1383,8 @@ static void t1_read_subrs()
t1_getline();
while (!(t1_charstrings() || t1_subrs())) {
t1_scan_param();
- t1_putline();
+ if (!t1_prefix("/UniqueID")) /* ignore UniqueID for subsetted fonts */
+ t1_putline();
t1_getline();
}
found:
diff --git a/Build/source/texk/web2c/pdftexdir/writet3.c b/Build/source/texk/web2c/pdftexdir/writet3.c
index d50de0bb52f..b5ad919c709 100644
--- a/Build/source/texk/web2c/pdftexdir/writet3.c
+++ b/Build/source/texk/web2c/pdftexdir/writet3.c
@@ -1,5 +1,5 @@
/*
-Copyright (c) 1996-2006 Han The Thanh, <thanh@pdftex.org>
+Copyright (c) 1996-2007 Han The Thanh, <thanh@pdftex.org>
This file is part of pdfTeX.
@@ -13,11 +13,11 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
-You should have received a copy of the GNU General Public License
-along with pdfTeX; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+You should have received a copy of the GNU General Public License along
+with pdfTeX; if not, write to the Free Software Foundation, Inc., 51
+Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-$Id: writet3.c,v 1.10 2005/12/26 14:26:18 hahe Exp hahe $
+$Id: writet3.c 200 2007-07-11 13:11:12Z oneiros $
*/
#include "ptexlib.h"
@@ -113,8 +113,7 @@ static void t3_write_glyph(internalfontnumber f)
"%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;
+ pdftex_fail("invalid glyph preamble: `%s'", t3_line_array);
}
if (glyph_index < fontbc[f] || glyph_index > fontec[f])
return;
@@ -193,11 +192,10 @@ static boolean writepk(internalfontnumber f)
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);
- cur_file_name = NULL;
- return false;
+ pdftex_fail("Font %s at %i not found", cur_file_name, (int) dpi);
}
t3_file = xfopen(name, FOPEN_RBIN_MODE);
+ recorder_record_input(name);
t3_image_used = true;
is_pk_font = true;
tex_printf(" <%s", (char *) name);
@@ -290,10 +288,7 @@ void writet3(int objnum, internalfontnumber f)
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;
+ pdftex_fail("missing or invalid font scale");
}
while (!t3_eof())
t3_write_glyph(f);
diff --git a/Build/source/texk/web2c/pdftexdir/writettf.c b/Build/source/texk/web2c/pdftexdir/writettf.c
index 9de6fd54c6c..971b0b1c7e7 100644
--- a/Build/source/texk/web2c/pdftexdir/writettf.c
+++ b/Build/source/texk/web2c/pdftexdir/writettf.c
@@ -1,5 +1,5 @@
/*
-Copyright (c) 1996-2006 Han The Thanh, <thanh@pdftex.org>
+Copyright (c) 1996-2007 Han The Thanh, <thanh@pdftex.org>
This file is part of pdfTeX.
@@ -13,11 +13,11 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
-You should have received a copy of the GNU General Public License
-along with pdfTeX; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+You should have received a copy of the GNU General Public License along
+with pdfTeX; if not, write to the Free Software Foundation, Inc., 51
+Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/writettf.c#16 $
+$Id: writettf.c 200 2007-07-11 13:11:12Z oneiros $
*/
#include "ptexlib.h"
@@ -302,7 +302,9 @@ static void ttf_copy_encoding(void)
e = ttfenc_tab + *q;
e->code = charcodes[*q];
if (e->code == -1)
- pdftex_warn("character %i is not mapped to any charcode", *q);
+ pdftex_warn
+ ("character %i in subfont %s is not mapped to any charcode",
+ *q, fd_cur->fm->tfm_name);
else {
assert(e->code < 0x10000);
sprintf(buf, "/c%4.4X", (int) e->code);
@@ -1335,9 +1337,7 @@ void writettf(fd_entry * fd)
set_cur_file_name(fd_cur->fm->ff_name);
if (is_subsetted(fd_cur->fm) && (fd_cur->fe == NULL)
&& !is_subfont(fd_cur->fm)) {
- pdftex_warn("Subset TrueType must be a reencoded or a subfont");
- cur_file_name = NULL;
- return;
+ pdftex_fail("Subset TrueType must be a reencoded or a subfont");
}
if (!ttf_open()) {
pdftex_fail("cannot open TrueType font file for reading");
diff --git a/Build/source/texk/web2c/pdftexdir/writettf.h b/Build/source/texk/web2c/pdftexdir/writettf.h
index e80ae7c3e7d..33a0a215806 100644
--- a/Build/source/texk/web2c/pdftexdir/writettf.h
+++ b/Build/source/texk/web2c/pdftexdir/writettf.h
@@ -1,5 +1,5 @@
/*
-Copyright (c) 1996-2006 Han The Thanh, <thanh@pdftex.org>
+Copyright (c) 1996-2007 Han The Thanh, <thanh@pdftex.org>
This file is part of pdfTeX.
@@ -13,11 +13,11 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
-You should have received a copy of the GNU General Public License
-along with pdfTeX; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+You should have received a copy of the GNU General Public License along
+with pdfTeX; if not, write to the Free Software Foundation, Inc., 51
+Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-$Id: //depot/Build/source.development/TeX/texk/web2c/pdftexdir/writettf.h#1 $
+$Id: writettf.h 200 2007-07-11 13:11:12Z oneiros $
*/
typedef signed char TTF_CHAR;
diff --git a/Build/source/texk/web2c/pdftexdir/writezip.c b/Build/source/texk/web2c/pdftexdir/writezip.c
index a24d7fffdd1..0ae328dd316 100644
--- a/Build/source/texk/web2c/pdftexdir/writezip.c
+++ b/Build/source/texk/web2c/pdftexdir/writezip.c
@@ -1,5 +1,5 @@
/*
-Copyright (c) 1996-2002 Han The Thanh, <thanh@pdftex.org>
+Copyright (c) 1996-2007 Han The Thanh, <thanh@pdftex.org>
This file is part of pdfTeX.
@@ -13,11 +13,11 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
-You should have received a copy of the GNU General Public License
-along with pdfTeX; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+You should have received a copy of the GNU General Public License along
+with pdfTeX; if not, write to the Free Software Foundation, Inc., 51
+Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-$Id: writezip.c,v 1.2 2006/01/14 20:35:43 hahe Exp $
+$Id: writezip.c 200 2007-07-11 13:11:12Z oneiros $
*/
#include "ptexlib.h"
@@ -26,26 +26,42 @@ $Id: writezip.c,v 1.2 2006/01/14 20:35:43 hahe Exp $
#define ZIP_BUF_SIZE 32768
-#define check_err(f, fn) \
- if (f != Z_OK) \
- pdftex_fail("zlib: %s() failed", fn)
+#define check_err(f, fn) \
+ if (f != Z_OK) \
+ pdftex_fail("zlib: %s() failed (error code %d)", fn, f)
-static char zipbuf[ZIP_BUF_SIZE];
+static char *zipbuf = NULL;
static z_stream c_stream; /* compression stream */
void writezip(boolean finish)
{
int err;
- assert(getpdfcompresslevel() > 0);
+ static int level_old = 0;
+ int level = getpdfcompresslevel();
+ assert(level > 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, getpdfcompresslevel()), "deflateInit");
+ if (zipbuf == NULL) {
+ zipbuf = xtalloc(ZIP_BUF_SIZE, char);
+ c_stream.zalloc = (alloc_func) 0;
+ c_stream.zfree = (free_func) 0;
+ c_stream.opaque = (voidpf) 0;
+ check_err(deflateInit(&c_stream, level), "deflateInit");
+ } else {
+ if (level != level_old) { /* \pdfcompresslevel change in mid document */
+ check_err(deflateEnd(&c_stream), "deflateEnd");
+ c_stream.zalloc = (alloc_func) 0; /* these 3 lines no need, just to be safe */
+ c_stream.zfree = (free_func) 0;
+ c_stream.opaque = (voidpf) 0;
+ check_err(deflateInit(&c_stream, level), "deflateInit");
+ } else
+ check_err(deflateReset(&c_stream), "deflateReset");
+ }
+ level_old = level;
c_stream.next_out = (Bytef *) zipbuf;
c_stream.avail_out = ZIP_BUF_SIZE;
}
+ assert(zipbuf != NULL);
c_stream.next_in = pdfbuf;
c_stream.avail_in = pdfptr;
for (;;) {
@@ -68,8 +84,15 @@ void writezip(boolean finish)
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;
}
+
+void zip_free(void)
+{
+ if (zipbuf != NULL) {
+ check_err(deflateEnd(&c_stream), "deflateEnd");
+ free(zipbuf);
+ }
+}
diff --git a/Build/source/texk/web2c/tex.ch b/Build/source/texk/web2c/tex.ch
index 01239a904c9..49610dc95cb 100644
--- a/Build/source/texk/web2c/tex.ch
+++ b/Build/source/texk/web2c/tex.ch
@@ -2210,12 +2210,20 @@ var k:0..buf_size; {index into |buffer|}
@y
var k:0..buf_size; {index into |buffer|}
@!saved_cur_name:str_number; {to catch empty terminal input}
+@!saved_cur_ext:str_number; {to catch empty terminal input}
+@!saved_cur_area:str_number; {to catch empty terminal input}
@z
@x [29.530] l.10252 - prompt_file_name: No default extension is TeX input file.
if e=".tex" then show_context;
@y
if (e=".tex") or (e="") then show_context;
+print_ln; print("(Enter the null string to re-try, or <eof> to exit");
+if (e<>"") then
+ begin
+ print(" Default file extension is `"); print(e); print("'");
+ end;
+print(")"); print_ln;
@z
@x [29.530] l.10258 - prompt_file_name: prevent empty filenames.
@@ -2223,9 +2231,17 @@ clear_terminal; prompt_input(": "); @<Scan file name in the buffer@>;
if cur_ext="" then cur_ext:=e;
@y
saved_cur_name:=cur_name;
+saved_cur_ext:=cur_ext;
+saved_cur_area:=cur_area;
clear_terminal; prompt_input(": "); @<Scan file name in the buffer@>;
-if cur_ext="" then cur_ext:=e;
-if length(cur_name)=0 then cur_name:=saved_cur_name;
+if (length(cur_name)=0) and (cur_ext="") and (cur_area="") then
+ begin
+ cur_name:=saved_cur_name;
+ cur_ext:=saved_cur_ext;
+ cur_area:=saved_cur_area;
+ end
+else
+ if cur_ext="" then cur_ext:=e;
@z
@x [29.532] l.10263 - avoid conflict, `logname' in <unistd.h> on some systems.