summaryrefslogtreecommitdiff
path: root/poppler
diff options
context:
space:
mode:
authorJeff Muizelaar <jeff@infidigm.net>2006-05-29 18:44:17 +0000
committerJeff Muizelaar <jeff@infidigm.net>2006-05-29 18:44:17 +0000
commitf7c1d519b9695ad8adfdcf3af696de746cdcf375 (patch)
tree372b23a74924570356878aa5fb790fc0c0ade210 /poppler
parent84861800dad3649d4757d5c5539b9e86e2b2c644 (diff)
2006-05-29 Jeff Muizelaar <jeff@infidigm.net>
* poppler/CairoFontEngine.cc: * poppler/CairoFontEngine.h: * poppler/CairoOutputDev.cc: Allow CairoFont creation to fail more gracefully. Fixes #4030.
Diffstat (limited to 'poppler')
-rw-r--r--poppler/CairoFontEngine.cc27
-rw-r--r--poppler/CairoFontEngine.h4
-rw-r--r--poppler/CairoOutputDev.cc5
3 files changed, 29 insertions, 7 deletions
diff --git a/poppler/CairoFontEngine.cc b/poppler/CairoFontEngine.cc
index f5ab8cb0..0ec0a005 100644
--- a/poppler/CairoFontEngine.cc
+++ b/poppler/CairoFontEngine.cc
@@ -38,7 +38,7 @@ static void cairo_font_face_destroy (void *data)
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 @@ CairoFont::CairoFont(GfxFont *gfxFont, XRef *xref, FT_Library lib, GBool useCIDs
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 @@ CairoFont::CairoFont(GfxFont *gfxFont, XRef *xref, FT_Library lib, GBool useCIDs
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 @@ CairoFont::CairoFont(GfxFont *gfxFont, XRef *xref, FT_Library lib, GBool useCIDs
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 @@ CairoFontEngine::getFont(GfxFont *gfxFont, XRef *xref) {
}
}
- 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];
}
diff --git a/poppler/CairoFontEngine.h b/poppler/CairoFontEngine.h
index 2df4e02f..f32b6a99 100644
--- a/poppler/CairoFontEngine.h
+++ b/poppler/CairoFontEngine.h
@@ -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;
diff --git a/poppler/CairoOutputDev.cc b/poppler/CairoOutputDev.cc
index 8348fb16..08c4603d 100644
--- a/poppler/CairoOutputDev.cc
+++ b/poppler/CairoOutputDev.cc
@@ -263,6 +263,8 @@ void CairoOutputDev::updateFont(GfxState *state) {
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 @@ void CairoOutputDev::drawChar(GfxState *state, double x, double y,
{
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;