	Patches for pdfTeX / luaTeX / XeTeX

	from:
		Han The Thanh <thanh@pdftex.org>
		Martin Schroeder <martin@pdftex.org>

diff -ur -N xpdf-3.02.orig/goo/gfile.cc xpdf-3.02/goo/gfile.cc
--- xpdf-3.02.orig/goo/gfile.cc	2009-03-05 23:36:46.000000000 +0100
+++ xpdf-3.02/goo/gfile.cc	2009-04-30 21:29:39.000000000 +0200
@@ -443,6 +443,7 @@
 #endif
 }
 
+#ifndef PDF_PARSER_ONLY
 GBool openTempFile(GString **name, FILE **f, char *mode, char *ext) {
 #if defined(WIN32)
   //---------- Win32 ----------
@@ -551,6 +552,7 @@
   return gTrue;
 #endif
 }
+#endif
 
 GBool executeCommand(char *cmd) {
 #ifdef VMS
diff -ur -N xpdf-3.02.orig/xpdf/GlobalParams.cc xpdf-3.02/xpdf/GlobalParams.cc
--- xpdf-3.02.orig/xpdf/GlobalParams.cc	2009-04-02 10:22:18.000000000 +0200
+++ xpdf-3.02/xpdf/GlobalParams.cc	2009-04-30 21:35:00.000000000 +0200
@@ -429,6 +429,7 @@
   }
 }
 
+#ifndef PDF_PARSER_ONLY
 //------------------------------------------------------------------------
 // KeyBinding
 //------------------------------------------------------------------------
@@ -461,6 +462,7 @@
 KeyBinding::~KeyBinding() {
   deleteGList(cmds, GString);
 }
+#endif
 
 #ifdef ENABLE_PLUGINS
 //------------------------------------------------------------------------
@@ -608,6 +610,138 @@
 // parsing
 //------------------------------------------------------------------------
 
+GlobalParams::GlobalParams() {
+  UnicodeMap *map;
+  int i;
+
+#if MULTITHREADED
+  gInitMutex(&mutex);
+  gInitMutex(&unicodeMapCacheMutex);
+  gInitMutex(&cMapCacheMutex);
+#endif
+
+  initBuiltinFontTables();
+
+  // scan the encoding in reverse because we want the lowest-numbered
+  // index for each char name ('space' is encoded twice)
+  macRomanReverseMap = new NameToCharCode();
+  for (i = 255; i >= 0; --i) {
+    if (macRomanEncoding[i]) {
+      macRomanReverseMap->add(macRomanEncoding[i], (CharCode)i);
+    }
+  }
+
+#ifdef WIN32
+  // baseDir will be set by a call to setBaseDir
+  baseDir = new GString();
+#else
+  baseDir = appendToPath(getHomeDir(), ".xpdf");
+#endif
+  nameToUnicode = new NameToCharCode();
+  cidToUnicodes = new GHash(gTrue);
+  unicodeToUnicodes = new GHash(gTrue);
+  residentUnicodeMaps = new GHash();
+  unicodeMaps = new GHash(gTrue);
+  cMapDirs = new GHash(gTrue);
+  toUnicodeDirs = new GList();
+  displayFonts = new GHash();
+  displayCIDFonts = new GHash();
+  displayNamedCIDFonts = new GHash();
+#if HAVE_PAPER_H
+  char *paperName;
+  const struct paper *paperType;
+  paperinit();
+  if ((paperName = systempapername())) {
+    paperType = paperinfo(paperName);
+    psPaperWidth = (int)paperpswidth(paperType);
+    psPaperHeight = (int)paperpsheight(paperType);
+  } else {
+    error(-1, "No paper information available - using defaults");
+    psPaperWidth = defPaperWidth;
+    psPaperHeight = defPaperHeight;
+  }
+  paperdone();
+#else
+  psPaperWidth = defPaperWidth;
+  psPaperHeight = defPaperHeight;
+#endif
+  psImageableLLX = psImageableLLY = 0;
+  psImageableURX = psPaperWidth;
+  psImageableURY = psPaperHeight;
+  psCrop = gTrue;
+  psExpandSmaller = gFalse;
+  psShrinkLarger = gTrue;
+  psCenter = gTrue;
+  psDuplex = gFalse;
+  psLevel = psLevel2;
+  psFile = NULL;
+  psFonts = new GHash();
+  psNamedFonts16 = new GList();
+  psFonts16 = new GList();
+  psEmbedType1 = gTrue;
+  psEmbedTrueType = gTrue;
+  psEmbedCIDPostScript = gTrue;
+  psEmbedCIDTrueType = gTrue;
+  psOPI = gFalse;
+  psASCIIHex = gFalse;
+  textEncoding = new GString("Latin1");
+#if defined(WIN32)
+  textEOL = eolDOS;
+#elif defined(MACOS)
+  textEOL = eolMac;
+#else
+  textEOL = eolUnix;
+#endif
+  textPageBreaks = gTrue;
+  textKeepTinyChars = gFalse;
+  fontDirs = new GList();
+  initialZoom = new GString("125");
+  continuousView = gFalse;
+  enableT1lib = gTrue;
+  enableFreeType = gTrue;
+  antialias = gTrue;
+  urlCommand = NULL;
+  movieCommand = NULL;
+  mapNumericCharNames = gTrue;
+  printCommands = gFalse;
+  errQuiet = gFalse;
+
+  cidToUnicodeCache = new CharCodeToUnicodeCache(cidToUnicodeCacheSize);
+  unicodeToUnicodeCache =
+      new CharCodeToUnicodeCache(unicodeToUnicodeCacheSize);
+  unicodeMapCache = new UnicodeMapCache();
+  cMapCache = new CMapCache();
+
+#ifdef ENABLE_PLUGINS
+  plugins = new GList();
+  securityHandlers = new GList();
+#endif
+
+  // set up the initial nameToUnicode table
+  for (i = 0; nameToUnicodeTab[i].name; ++i) {
+    nameToUnicode->add(nameToUnicodeTab[i].name, nameToUnicodeTab[i].u);
+  }
+
+  // set up the residentUnicodeMaps table
+  map = new UnicodeMap("Latin1", gFalse,
+		       latin1UnicodeMapRanges, latin1UnicodeMapLen);
+  residentUnicodeMaps->add(map->getEncodingName(), map);
+  map = new UnicodeMap("ASCII7", gFalse,
+		       ascii7UnicodeMapRanges, ascii7UnicodeMapLen);
+  residentUnicodeMaps->add(map->getEncodingName(), map);
+  map = new UnicodeMap("Symbol", gFalse,
+		       symbolUnicodeMapRanges, symbolUnicodeMapLen);
+  residentUnicodeMaps->add(map->getEncodingName(), map);
+  map = new UnicodeMap("ZapfDingbats", gFalse, zapfDingbatsUnicodeMapRanges,
+		       zapfDingbatsUnicodeMapLen);
+  residentUnicodeMaps->add(map->getEncodingName(), map);
+  map = new UnicodeMap("UTF-8", gTrue, &mapUTF8);
+  residentUnicodeMaps->add(map->getEncodingName(), map);
+  map = new UnicodeMap("UCS-2", gTrue, &mapUCS2);
+  residentUnicodeMaps->add(map->getEncodingName(), map);
+
+}
+
 GlobalParams::GlobalParams(char *cfgFileName) {
   UnicodeMap *map;
   GString *fileName;
@@ -713,7 +847,9 @@
   movieCommand = NULL;
   mapNumericCharNames = gTrue;
   mapUnknownCharNames = gFalse;
+#ifndef PDF_PARSER_ONLY
   createDefaultKeyBindings();
+#endif
   printCommands = gFalse;
   errQuiet = gFalse;
 
@@ -788,12 +924,15 @@
     }
   }
   if (f) {
+#ifndef PDF_PARSER_ONLY
     parseFile(fileName, f);
+#endif
     delete fileName;
     fclose(f);
   }
 }
 
+#ifndef PDF_PARSER_ONLY
 void GlobalParams::createDefaultKeyBindings() {
   keyBindings = new GList();
 
@@ -1120,6 +1259,7 @@
 
   deleteGList(tokens, GString);
 }
+#endif
 
 void GlobalParams::parseNameToUnicode(GList *tokens, GString *fileName,
 					 int line) {
@@ -1464,6 +1604,7 @@
   }
 }
 
+#ifndef PDF_PARSER_ONLY
 void GlobalParams::parseBind(GList *tokens, GString *fileName, int line) {
   KeyBinding *binding;
   GList *cmds;
@@ -1649,6 +1790,7 @@
 
   return gTrue;
 }
+#endif
 
 void GlobalParams::parseCommand(char *cmdName, GString **val,
 				GList *tokens, GString *fileName, int line) {
@@ -1792,7 +1934,9 @@
   if (movieCommand) {
     delete movieCommand;
   }
+#ifndef PDF_PARSER_ONLY
   deleteGList(keyBindings, KeyBinding);
+#endif
 
   cMapDirs->startIter(&iter);
   while (cMapDirs->getNext(&iter, &key, (void **)&list)) {
@@ -2443,6 +2587,7 @@
   return map;
 }
 
+#ifndef PDF_PARSER_ONLY
 GList *GlobalParams::getKeyBinding(int code, int mods, int context) {
   KeyBinding *binding;
   GList *cmds;
@@ -2468,6 +2613,7 @@
   unlockGlobalParams;
   return cmds;
 }
+#endif
 
 GBool GlobalParams::getPrintCommands() {
   GBool p;
diff -ur -N xpdf-3.02.orig/xpdf/GlobalParams.h xpdf-3.02/xpdf/GlobalParams.h
--- xpdf-3.02.orig/xpdf/GlobalParams.h	2007-02-27 23:05:52.000000000 +0100
+++ xpdf-3.02/xpdf/GlobalParams.h	2008-05-08 15:40:41.000000000 +0200
@@ -5,6 +5,9 @@
 // Copyright 2001-2003 Glyph & Cog, LLC
 //
 //========================================================================
+//  Modified for TeX Live by Peter Breitenlohner <tex-live@tug.org>
+//  See top-level ChangeLog for a list of all modifications
+//========================================================================
 
 #ifndef GLOBALPARAMS_H
 #define GLOBALPARAMS_H
@@ -123,6 +126,7 @@
 
 //------------------------------------------------------------------------
 
+#ifndef PDF_PARSER_ONLY
 class KeyBinding {
 public:
 
@@ -186,6 +190,7 @@
 #define xpdfKeyContextMainWin     (2 << 6)
 #define xpdfKeyContextScrLockOn   (1 << 8)
 #define xpdfKeyContextScrLockOff  (2 << 8)
+#endif
 
 //------------------------------------------------------------------------
 
@@ -196,12 +201,17 @@
   // file.
   GlobalParams(char *cfgFileName);
 
+  // Initialize it without reading the config
+  GlobalParams();
+
   ~GlobalParams();
 
   void setBaseDir(char *dir);
   void setupBaseFonts(char *dir);
 
+#ifndef PDF_PARSER_ONLY
   void parseLine(char *buf, GString *fileName, int line);
+#endif
 
   //----- accessors
 
@@ -256,7 +266,9 @@
   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();
 
@@ -315,7 +327,9 @@
 
 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);
@@ -338,12 +352,14 @@
   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,
@@ -438,7 +454,9 @@
   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 -ur -N xpdf-3.02.orig/xpdf/Page.h xpdf-3.02/xpdf/Page.h
--- xpdf-3.02.orig/xpdf/Page.h	2007-02-27 23:05:52.000000000 +0100
+++ xpdf-3.02/xpdf/Page.h	2008-05-08 15:40:41.000000000 +0200
@@ -5,6 +5,9 @@
 // Copyright 1996-2003 Glyph & Cog, LLC
 //
 //========================================================================
+//  Modified for TeX Live by Peter Breitenlohner <tex-live@tug.org>
+//  See top-level ChangeLog for a list of all modifications
+//========================================================================
 
 #ifndef PAGE_H
 #define PAGE_H
@@ -170,9 +173,11 @@
 
   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 useMediaBox, GBool upsideDown);
+#endif
 
 private:
 
diff -ur -N xpdf-3.02.orig/xpdf/XRef.cc xpdf-3.02/xpdf/XRef.cc
--- xpdf-3.02.orig/xpdf/XRef.cc	2007-02-27 23:05:52.000000000 +0100
+++ xpdf-3.02/xpdf/XRef.cc	2008-05-08 15:40:41.000000000 +0200
@@ -5,6 +5,9 @@
 // Copyright 1996-2003 Glyph & Cog, LLC
 //
 //========================================================================
+//  Modified for TeX Live by Peter Breitenlohner <tex-live@tug.org>
+//  See top-level ChangeLog for a list of all modifications
+//========================================================================
 
 #include <aconf.h>
 
@@ -45,34 +48,9 @@
 // ObjectStream
 //------------------------------------------------------------------------
 
-class ObjectStream {
-public:
-
-  // Create an object stream, using object number <objStrNum>,
-  // generation 0.
-  ObjectStream(XRef *xref, int objStrNumA);
-
-  ~ObjectStream();
-
-  // Return the object number of this object stream.
-  int getObjStrNum() { return objStrNum; }
-
-  // Get the <objIdx>th object from this stream, which should be
-  // object number <objNum>, generation 0.
-  Object *getObject(int objIdx, int objNum, Object *obj);
-
-private:
-
-  int objStrNum;		// object number of the object stream
-  int nObjects;			// number of objects in the stream
-  Object *objs;			// the objects (length = nObjects)
-  int *objNums;			// the object numbers (length = nObjects)
-};
-
 ObjectStream::ObjectStream(XRef *xref, int objStrNumA) {
   Stream *str;
   Parser *parser;
-  int *offsets;
   Object objStr, obj1, obj2;
   int first, i;
 
@@ -80,6 +58,7 @@
   nObjects = 0;
   objs = NULL;
   objNums = NULL;
+  offsets = NULL;
 
   if (!xref->fetch(objStrNum, 0, &objStr)->isStream()) {
     goto err1;
@@ -100,6 +79,7 @@
     goto err1;
   }
   first = obj1.getInt();
+  firstOffset = objStr.getStream()->getBaseStream()->getStart() + first;
   obj1.free();
   if (first < 0) {
     goto err1;
@@ -121,7 +101,7 @@
       obj1.free();
       obj2.free();
       delete parser;
-      gfree(offsets);
+//       gfree(offsets);
       goto err1;
     }
     objNums[i] = obj1.getInt();
@@ -131,7 +111,7 @@
     if (objNums[i] < 0 || offsets[i] < 0 ||
 	(i > 0 && offsets[i] < offsets[i-1])) {
       delete parser;
-      gfree(offsets);
+//       gfree(offsets);
       goto err1;
     }
   }
@@ -160,7 +140,7 @@
     delete parser;
   }
 
-  gfree(offsets);
+//   gfree(offsets);
 
  err1:
   objStr.free();
@@ -177,6 +157,7 @@
     delete[] objs;
   }
   gfree(objNums);
+  gfree(offsets);
 }
 
 Object *ObjectStream::getObject(int objIdx, int objNum, Object *obj) {
diff -ur -N xpdf-3.02.orig/xpdf/XRef.h xpdf-3.02/xpdf/XRef.h
--- xpdf-3.02.orig/xpdf/XRef.h	2007-02-27 23:05:52.000000000 +0100
+++ xpdf-3.02/xpdf/XRef.h	2008-05-08 15:40:41.000000000 +0200
@@ -5,6 +5,9 @@
 // Copyright 1996-2003 Glyph & Cog, LLC
 //
 //========================================================================
+//  Modified for TeX Live by Peter Breitenlohner <tex-live@tug.org>
+//  See top-level ChangeLog for a list of all modifications
+//========================================================================
 
 #ifndef XREF_H
 #define XREF_H
@@ -21,7 +24,36 @@
 class Dict;
 class Stream;
 class Parser;
-class ObjectStream;
+
+class ObjectStream {
+public:
+
+  // Create an object stream, using object number <objStrNum>,
+  // generation 0.
+  ObjectStream(XRef *xref, int objStrNumA);
+
+  ~ObjectStream();
+
+  // Return the object number of this object stream.
+  int getObjStrNum() { return objStrNum; }
+
+  // Get the <objIdx>th object from this stream, which should be
+  // object number <objNum>, generation 0.
+  Object *getObject(int objIdx, int objNum, Object *obj);
+
+  int *getOffsets() { return offsets; }
+  Guint getFirstOffset() { return firstOffset; }
+
+private:
+
+  int objStrNum;		// object number of the object stream
+  int nObjects;			// number of objects in the stream
+  Object *objs;			// the objects (length = nObjects)
+  int *objNums;			// the object numbers (length = nObjects)
+  int *offsets;			// the object offsets (length = nObjects)
+  Guint firstOffset;
+};
+
 
 //------------------------------------------------------------------------
 // XRef
@@ -96,6 +128,7 @@
   int getSize() { return size; }
   XRefEntry *getEntry(int i) { return &entries[i]; }
   Object *getTrailerDict() { return &trailerDict; }
+  ObjectStream *getObjStr() { return objStr; }
 
 private:
 
