+--- xpdf/SplashFTFont.cc.orig 2010-05-18 11:22:18.000000000 -0700
++++ xpdf/SplashFTFont.cc 2010-05-18 11:22:18.000000000 -0700
+@@ -46,6 +46,7 @@
+ int x, y;
+
+ face = fontFileA->face;
++
+ if (FT_New_Size(face, &sizeObj)) {
+ return;
+ }
+@@ -54,6 +55,10 @@
+ if (FT_Set_Pixel_Sizes(face, 0, (int)size)) {
+ return;
+ }
++
++ this->ascender = face->ascender;
++ this->descender = face->descender;
++
+ // if the textMat values are too small, FreeType's fixed point
+ // arithmetic doesn't work so well
+ textScale = splashSqrt(textMat[2]*textMat[2] + textMat[3]*textMat[3]) / size;
+@@ -228,6 +233,12 @@
+ GBool needClose;
+ };
+
++int SplashFTFont::getNumChars()
++{
++ SplashFTFontFile* ff = (SplashFTFontFile *)fontFile;
++ return ff->face->num_glyphs;
++}
++
+ SplashPath *SplashFTFont::getGlyphPath(int c) {
+ static FT_Outline_Funcs outlineFuncs = {
+ #if FREETYPE_MINOR <= 1
+@@ -249,6 +260,8 @@
+ FT_UInt gid;
+ FT_Glyph glyph;
+
++ this->last_advance = -1;
++
+ ff = (SplashFTFontFile *)fontFile;
+ ff->face->size = sizeObj;
+ FT_Set_Transform(ff->face, &textMatrix, NULL);
+@@ -262,17 +275,24 @@
+ // skip the TrueType notdef glyph
+ return NULL;
+ }
+- if (FT_Load_Glyph(ff->face, gid, FT_LOAD_NO_BITMAP)) {
++ int error = 0;
++ if ((error=FT_Load_Glyph(ff->face, gid, FT_LOAD_NO_BITMAP|FT_LOAD_NO_HINTING))) {
++ fprintf(stderr, "Truetype wasn't able to load glyph %d, error %d\n", gid, error);
+ return NULL;
+ }
+ if (FT_Get_Glyph(slot, &glyph)) {
+ return NULL;
+ }
++ this->last_advance = glyph->advance.x/65536.0;
++
+ path.path = new SplashPath();
+ path.textScale = textScale;
+ path.needClose = gFalse;
+- FT_Outline_Decompose(&((FT_OutlineGlyph)glyph)->outline,
++ error = FT_Outline_Decompose(&((FT_OutlineGlyph)glyph)->outline,
+ &outlineFuncs, &path);
++ if(error) {
++ fprintf(stderr, "Truetype wasn't able to read glyph %d, error %d\n", gid, error);
++ }
+ if (path.needClose) {
+ path.path->close();
+ }
+--- xpdf/SplashFTFont.h.orig 2010-05-18 11:22:18.000000000 -0700
++++ xpdf/SplashFTFont.h 2010-05-18 11:22:18.000000000 -0700
+@@ -42,6 +42,9 @@
+ virtual GBool makeGlyph(int c, int xFrac, int yFrac,
+ SplashGlyphBitmap *bitmap);
+
++ // return the number of characters in this font
++ virtual int getNumChars();
++
+ // Return the path for a glyph.
+ virtual SplashPath *getGlyphPath(int c);
+
+--- xpdf/SplashFTFontEngine.cc.orig 2010-05-18 11:22:18.000000000 -0700
++++ xpdf/SplashFTFontEngine.cc 2010-05-18 11:22:18.000000000 -0700
+@@ -13,9 +13,7 @@
+ #endif
+
+ #include <stdio.h>
+-#ifndef WIN32
+ # include <unistd.h>
+-#endif
+ #include "gmem.h"
+ #include "GString.h"
+ #include "gfile.h"
+--- xpdf/SplashFont.cc.orig 2010-05-18 11:22:18.000000000 -0700
++++ xpdf/SplashFont.cc 2010-05-18 11:22:18.000000000 -0700
+@@ -48,6 +48,10 @@
+ cacheTags = NULL;
+
+ xMin = yMin = xMax = yMax = 0;
++
++ last_advance = -1;
++ ascender = -1;
++ descender = -1;
+ }
+
+ void SplashFont::initCache() {
+--- xpdf/SplashFont.h.orig 2010-05-18 11:22:18.000000000 -0700
++++ xpdf/SplashFont.h 2010-05-18 11:22:18.000000000 -0700
+@@ -73,6 +73,9 @@
+ virtual GBool makeGlyph(int c, int xFrac, int yFrac,
+ SplashGlyphBitmap *bitmap) = 0;
+
++ // return the number of characters in this font
++ virtual int getNumChars() = 0;
++
+ // Return the path for a glyph.
+ virtual SplashPath *getGlyphPath(int c) = 0;
+
+@@ -83,6 +86,9 @@
+ void getBBox(int *xMinA, int *yMinA, int *xMaxA, int *yMaxA)
+ { *xMinA = xMin; *yMinA = yMin; *xMaxA = xMax; *yMaxA = yMax; }
+
++ double ascender;
++ double descender;
++ double last_advance; //set after getGlyphPath()
+ protected:
+
+ SplashFontFile *fontFile;
+--- xpdf/SplashFontFile.cc.orig 2010-05-18 11:22:18.000000000 -0700
++++ xpdf/SplashFontFile.cc 2010-05-18 11:22:18.000000000 -0700
+@@ -11,9 +11,7 @@
+ #endif
+
+ #include <stdio.h>
+-#ifndef WIN32
+-# include <unistd.h>
+-#endif
++#include <unistd.h>
+ #include "GString.h"
+ #include "SplashFontFile.h"
+ #include "SplashFontFileID.h"
+--- xpdf/SplashOutputDev.cc.orig 2010-05-18 11:22:18.000000000 -0700
++++ xpdf/SplashOutputDev.cc 2010-05-18 11:22:18.000000000 -0700
+@@ -13,6 +13,7 @@
+ #endif
+
+ #include <string.h>
++#include <unistd.h>
+ #include <math.h>
+ #include "gfile.h"
+ #include "GlobalParams.h"
+@@ -702,7 +703,7 @@
+ nT3Fonts = 0;
+ }
+
+-void SplashOutputDev::startPage(int pageNum, GfxState *state) {
++void SplashOutputDev::startPage(int pageNum, GfxState *state, double x1,double y1,double x2,double y2) {
+ int w, h;
+ double *ctm;
+ SplashCoord mat[6];
+@@ -2646,9 +2647,9 @@
+
+ softMask = new SplashBitmap(bitmap->getWidth(), bitmap->getHeight(),
+ 1, splashModeMono8, gFalse);
+- memset(softMask->getDataPtr(), 0,
+- softMask->getRowSize() * softMask->getHeight());
++ memset(softMask->getDataPtr(), 0x00, softMask->getRowSize()*softMask->getHeight());
+ p = softMask->getDataPtr() + ty * softMask->getRowSize() + tx;
++ if (tx<softMask->getWidth() && ty<softMask->getHeight())
+ for (y = 0; y < tBitmap->getHeight(); ++y) {
+ for (x = 0; x < tBitmap->getWidth(); ++x) {
+ tBitmap->getPixel(x, y, color);
+--- xpdf/SplashOutputDev.h.orig 2010-05-18 11:22:18.000000000 -0700
++++ xpdf/SplashOutputDev.h 2010-05-18 11:22:18.000000000 -0700
+@@ -70,7 +70,7 @@
+ //----- initialization and control
+
+ // Start a page.
+- virtual void startPage(int pageNum, GfxState *state);
++ virtual void startPage(int pageNum, GfxState *state, double x1,double y1,double x2,double y2);
+
+ // End a page.
+ virtual void endPage();
+@@ -196,6 +196,9 @@
+ virtual void setVectorAntialias(GBool vaa);
+ #endif
+
++ void doUpdateFont(GfxState *state);
++
++ SplashPath *convertPath(GfxState *state, GfxPath *path);
+ private:
+
+ void setupScreenParams(double hDPI, double vDPI);
+@@ -204,8 +207,6 @@
+ #else
+ SplashPattern *getColor(GfxGray gray, GfxRGB *rgb);
+ #endif
+- SplashPath *convertPath(GfxState *state, GfxPath *path);
+- void doUpdateFont(GfxState *state);
+ void drawType3Glyph(T3FontCache *t3Font,
+ T3FontCacheTag *tag, Guchar *data);
+ static GBool imageMaskSrc(void *data, SplashColorPtr line);
+--- xpdf/SplashScreen.cc.orig 2010-05-18 11:22:18.000000000 -0700
++++ xpdf/SplashScreen.cc 2010-05-18 11:22:18.000000000 -0700
+@@ -363,6 +363,8 @@
+ int SplashScreen::test(int x, int y, Guchar value) {
+ int xx, yy;
+
++ return 1;
++
+ if (value < minVal) {
+ return 0;
+ }
+--- xpdf/SplashXPathScanner.cc.orig 2010-05-18 11:22:18.000000000 -0700
++++ xpdf/SplashXPathScanner.cc 2010-05-18 11:22:18.000000000 -0700
+@@ -394,10 +394,10 @@
+ *p++ &= mask;
+ xx = (xx & ~7) + 8;
+ }
+- for (; xx + 7 <= xx0; xx += 8) {
++ for (; xx + 7 < xx0; xx += 8) {
+ *p++ = 0x00;
+ }
+- if (xx <= xx0) {
++ if (xx < xx0) {
+ *p &= 0xff >> (xx0 & 7);
+ }
+ }
+@@ -417,10 +417,10 @@
+ *p++ &= mask;
+ xx = (xx & ~7) + 8;
+ }
+- for (; xx + 7 <= xx0; xx += 8) {
++ for (; xx + 7 < xx0; xx += 8) {
+ *p++ = 0x00;
+ }
+- if (xx <= xx0) {
++ if (xx < xx0) {
+ *p &= 0xff >> (xx0 & 7);
+ }
+ }
+--- xpdf/Stream.cc.orig 2010-05-18 11:22:18.000000000 -0700
++++ xpdf/Stream.cc 2010-05-18 11:22:18.000000000 -0700
+@@ -18,6 +18,8 @@
+ #include <limits.h>