[poppler] poppler/poppler: CairoFontEngine.cc, 1.22, 1.23 CairoFontEngine.h, 1.9, 1.10 CairoOutputDev.cc, 1.37, 1.38

Jeff Muizelaar jrmuizel at kemper.freedesktop.org
Mon May 29 11:44:19 PDT 2006


Update of /cvs/poppler/poppler/poppler
In directory kemper:/tmp/cvs-serv26363/poppler

Modified Files:
	CairoFontEngine.cc CairoFontEngine.h CairoOutputDev.cc 
Log Message:
2006-05-29  Jeff Muizelaar  <jeff at infidigm.net>

	* poppler/CairoFontEngine.cc:
	* poppler/CairoFontEngine.h:
	* poppler/CairoOutputDev.cc: Allow CairoFont creation to fail more
	gracefully. Fixes #4030.


Index: CairoFontEngine.cc
===================================================================
RCS file: /cvs/poppler/poppler/poppler/CairoFontEngine.cc,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- CairoFontEngine.cc	21 May 2006 23:26:45 -0000	1.22
+++ CairoFontEngine.cc	29 May 2006 18:44:17 -0000	1.23
@@ -38,7 +38,7 @@
   delete font;
 }
 
-CairoFont::CairoFont(GfxFont *gfxFont, XRef *xref, FT_Library lib, GBool useCIDs) {
+CairoFont *CairoFont::create(GfxFont *gfxFont, XRef *xref, FT_Library lib, GBool useCIDs) {
   Ref embRef;
   Object refObj, strObj;
   GooString *tmpFileName, *fileName, *substName,*tmpFileName2;
@@ -52,7 +52,13 @@
   FoFiType1C *ff1c;
   CharCodeToUnicode *ctu;
   Unicode uBuf[8];
+  Ref ref;
   static cairo_user_data_key_t cairo_font_face_key;
+  cairo_font_face_t *cairo_font_face;
+  FT_Face face;
+
+  Gushort *codeToGID;
+  int codeToGIDLen;
   
   dfp = NULL;
   codeToGID = NULL;
@@ -160,6 +166,7 @@
         error(-1, "Couldn't find a mapping to Unicode for font '%s'",
               gfxFont->getName() ? gfxFont->getName()->getCString()
                         : "(unnamed)");
+	goto err2;
       }
     } else {
       if (((GfxCIDFont *)gfxFont)->getCIDToGID()) {
@@ -241,19 +248,26 @@
     error(-1, "could not create cairo font\n");
     goto err2; /* this doesn't do anything, but it looks like we're
 		* handling the error */
-  }
-
+  } {
+  CairoFont *ret = new CairoFont(ref, cairo_font_face, face, codeToGID, codeToGIDLen);
   cairo_font_face_set_user_data (cairo_font_face, 
 				 &cairo_font_face_key,
-				 this,
+				 ret,
 				 cairo_font_face_destroy);
 
-  return;
+  return ret;
+  }
  err2:
   /* hmm? */
   printf ("some font thing failed\n");
+  return NULL;
 }
 
+CairoFont::CairoFont(Ref ref, cairo_font_face_t *cairo_font_face, FT_Face face,
+    Gushort *codeToGID, int codeToGIDLen) : ref(ref), cairo_font_face(cairo_font_face),
+					    face(face), codeToGID(codeToGID),
+					    codeToGIDLen(codeToGIDLen) { }
+
 CairoFont::~CairoFont() {
   FT_Done_Face (face);
   gfree(codeToGID);
@@ -336,7 +350,8 @@
     }
   }
   
-  font = new CairoFont (gfxFont, xref, lib, useCIDs);
+  font = CairoFont::create (gfxFont, xref, lib, useCIDs);
+  //XXX: if font is null should we still insert it into the cache?
   if (fontCache[cairoFontCacheSize - 1]) {
     delete fontCache[cairoFontCacheSize - 1];
   }

Index: CairoFontEngine.h
===================================================================
RCS file: /cvs/poppler/poppler/poppler/CairoFontEngine.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- CairoFontEngine.h	21 May 2006 23:26:45 -0000	1.9
+++ CairoFontEngine.h	29 May 2006 18:44:17 -0000	1.10
@@ -18,13 +18,15 @@
 
 class CairoFont {
 public:
-  CairoFont(GfxFont *gfxFont, XRef *xref, FT_Library lib, GBool useCIDs);
+  static CairoFont *create(GfxFont *gfxFont, XRef *xref, FT_Library lib, GBool useCIDs);
   ~CairoFont();
 
   GBool matches(Ref &other);
   cairo_font_face_t *getFontFace(void);
   unsigned long getGlyph(CharCode code, Unicode *u, int uLen);
 private:
+  CairoFont(Ref ref, cairo_font_face_t *cairo_font_face, FT_Face face,
+      Gushort *codeToGID, int codeToGIDLen);
   Ref ref;
   cairo_font_face_t *cairo_font_face;
   FT_Face face;

Index: CairoOutputDev.cc
===================================================================
RCS file: /cvs/poppler/poppler/poppler/CairoOutputDev.cc,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -d -r1.37 -r1.38
--- CairoOutputDev.cc	27 May 2006 17:27:37 -0000	1.37
+++ CairoOutputDev.cc	29 May 2006 18:44:17 -0000	1.38
@@ -263,6 +263,8 @@
 
   currentFont = fontEngine->getFont (state->getFont(), xref);
 
+  if (!currentFont)
+    return;
   state->getFontTransMat(&m11, &m12, &m21, &m22);
   m11 *= state->getHorizScaling();
   m12 *= state->getHorizScaling();
@@ -374,6 +376,9 @@
 {
   double tx, ty;
 
+  if (!currentFont)
+    return;
+  
   glyphs[glyphCount].index = currentFont->getGlyph (code, u, uLen);
   state->transform(x - originX, y - originY, &tx, &ty);
   glyphs[glyphCount].x = tx;



More information about the poppler mailing list