//
// GfxFont.cc
//
-// Copyright 1996-2002 Glyph & Cog, LLC
+// Copyright 1996-2003 Glyph & Cog, LLC
//
//========================================================================
-#ifdef __GNUC__
+#include <aconf.h>
+
+#ifdef USE_GCC_PRAGMAS
#pragma implementation
#endif
-#include <aconf.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char *properName;
};
+// Acrobat 4.0 and earlier substituted Base14-compatible fonts without
+// providing Widths and a FontDescriptor, so we munge the names into
+// the proper Base14 names. This table is from implementation note 44
+// in the PDF 1.4 spec, with some additions based on empirical
+// evidence.
static StdFontMapEntry stdFontMap[] = {
{ "Arial", "Helvetica" },
{ "Arial,Bold", "Helvetica-Bold" },
{ "Helvetica,Italic", "Helvetica-Oblique" },
{ "Helvetica-BoldItalic", "Helvetica-BoldOblique" },
{ "Helvetica-Italic", "Helvetica-Oblique" },
+ { "Symbol,Bold", "Symbol" },
+ { "Symbol,BoldItalic", "Symbol" },
+ { "Symbol,Italic", "Symbol" },
{ "TimesNewRoman", "Times-Roman" },
{ "TimesNewRoman,Bold", "Times-Bold" },
{ "TimesNewRoman,BoldItalic", "Times-BoldItalic" },
if (t != 0) {
descent = t;
}
+ // some broken font descriptors specify a positive descent
+ if (descent > 0) {
+ descent = -descent;
+ }
}
obj2.free();
}
void GfxFont::findExtFontFile() {
+ static char *type1Exts[] = { ".pfa", ".pfb", ".ps", "", NULL };
+ static char *ttExts[] = { ".ttf", NULL };
+
if (name) {
if (type == fontType1) {
- extFontFile = globalParams->findFontFile(name, ".pfa", ".pfb");
+ extFontFile = globalParams->findFontFile(name, type1Exts);
} else if (type == fontTrueType) {
- extFontFile = globalParams->findFontFile(name, ".ttf", NULL);
+ extFontFile = globalParams->findFontFile(name, ttExts);
}
}
}
type = typeA;
ctu = NULL;
- // Acrobat 4.0 and earlier substituted Base14-compatible fonts
- // without providing Widths and a FontDescriptor, so we munge the
- // names into the proper Base14 names. (This table is from
- // implementation note 44 in the PDF 1.4 spec.)
+ // do font name substitution for various aliases of the Base 14 font
+ // names
if (name) {
a = 0;
b = sizeof(stdFontMap) / sizeof(StdFontMapEntry);
fontFile = new Type1FontFile(buf, len);
} else {
fontFile = new Type1CFontFile(buf, len);
+ if (!((Type1CFontFile *)fontFile)->isOk()) {
+ delete fontFile;
+ fontFile = NULL;
+ }
}
- if (fontFile->getName()) {
+ if (fontFile && fontFile->getName()) {
if (embFontName) {
delete embFontName;
}
embFontName = new GString(fontFile->getName());
}
- if (!baseEnc) {
+ if (fontFile && !baseEnc) {
baseEnc = fontFile->getEncoding();
baseEncFromFontFile = gTrue;
}
if (!baseEnc) {
if (builtinFont) {
baseEnc = builtinFont->defaultBaseEnc;
+ hasEncoding = gTrue;
} else if (type == fontTrueType) {
- baseEnc = macRomanEncoding;
+ baseEnc = winAnsiEncoding;
} else {
baseEnc = standardEncoding;
}
fontDict->lookup("Widths", &obj1);
if (obj1.isArray()) {
flags |= fontFixedWidth;
+ if (obj1.arrayGetLength() < lastChar - firstChar + 1) {
+ lastChar = firstChar + obj1.arrayGetLength() - 1;
+ }
for (code = firstChar; code <= lastChar; ++code) {
obj1.arrayGet(code - firstChar, &obj2);
if (obj2.isNum()) {
// GfxCIDFont
//------------------------------------------------------------------------
-static int cmpWidthExcep(const void *w1, const void *w2) {
+static int CDECL cmpWidthExcep(const void *w1, const void *w2) {
return ((GfxFontCIDWidthExcep *)w1)->first -
((GfxFontCIDWidthExcep *)w2)->first;
}
-static int cmpWidthExcepV(const void *w1, const void *w2) {
+static int CDECL cmpWidthExcepV(const void *w1, const void *w2) {
return ((GfxFontCIDWidthExcepV *)w1)->first -
((GfxFontCIDWidthExcepV *)w2)->first;
}
// CIDToGIDMap (for embedded TrueType fonts)
if (type == fontCIDType2) {
- fontDict->lookup("CIDToGIDMap", &obj1);
+ desFontDict->lookup("CIDToGIDMap", &obj1);
if (obj1.isStream()) {
cidToGIDLen = 0;
i = 64;
GfxFontDict::GfxFontDict(XRef *xref, Dict *fontDict) {
int i;
Object obj1, obj2;
+ Ref r;
numFonts = fontDict->getLength();
fonts = (GfxFont **)gmalloc(numFonts * sizeof(GfxFont *));
for (i = 0; i < numFonts; ++i) {
fontDict->getValNF(i, &obj1);
obj1.fetch(xref, &obj2);
- if (obj1.isRef() && obj2.isDict()) {
+ if (obj2.isDict()) {
+ if (obj1.isRef()) {
+ r = obj1.getRef();
+ } else {
+ // no indirect reference for this font, so invent a unique one
+ // (legal generation numbers are five digits, so any 6-digit
+ // number would be safe)
+ r.num = i;
+ r.gen = 999999;
+ }
fonts[i] = GfxFont::makeFont(xref, fontDict->getKey(i),
- obj1.getRef(), obj2.getDict());
+ r, obj2.getDict());
if (fonts[i] && !fonts[i]->isOk()) {
delete fonts[i];
fonts[i] = NULL;
}
} else {
- error(-1, "font resource is not a dictionary reference");
+ error(-1, "font resource is not a dictionary");
fonts[i] = NULL;
}
obj1.free();