Commit 9830f0ea authored by Albert Astals Cid's avatar Albert Astals Cid

GfxFont merges from xpdf 3.01

parent 62b5ba22
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
* poppler/PSOutputDev.cc: Changes needed due to Annot changes * poppler/PSOutputDev.cc: Changes needed due to Annot changes
* poppler/Function.[cc|h]: Merge from xpdf 3.01 * poppler/Function.[cc|h]: Merge from xpdf 3.01
* poppler/Stream.[cc|h]: Merge from xpdf 3.01 * poppler/Stream.[cc|h]: Merge from xpdf 3.01
* poppler/GfxFont.cc: Merge from xpdf 3.01
2005-10-05 Kristian Høgsberg <krh@redhat.com> 2005-10-05 Kristian Høgsberg <krh@redhat.com>
......
...@@ -55,8 +55,8 @@ static StdFontMapEntry stdFontMap[] = { ...@@ -55,8 +55,8 @@ static StdFontMapEntry stdFontMap[] = {
{ "Arial-ItalicMT", "Helvetica-Oblique" }, { "Arial-ItalicMT", "Helvetica-Oblique" },
{ "ArialMT", "Helvetica" }, { "ArialMT", "Helvetica" },
{ "Courier,Bold", "Courier-Bold" }, { "Courier,Bold", "Courier-Bold" },
{ "Courier,Italic", "Courier-Oblique" },
{ "Courier,BoldItalic", "Courier-BoldOblique" }, { "Courier,BoldItalic", "Courier-BoldOblique" },
{ "Courier,Italic", "Courier-Oblique" },
{ "CourierNew", "Courier" }, { "CourierNew", "Courier" },
{ "CourierNew,Bold", "Courier-Bold" }, { "CourierNew,Bold", "Courier-Bold" },
{ "CourierNew,BoldItalic", "Courier-BoldOblique" }, { "CourierNew,BoldItalic", "Courier-BoldOblique" },
...@@ -232,19 +232,19 @@ void GfxFont::readFontDescriptor(XRef *xref, Dict *fontDict) { ...@@ -232,19 +232,19 @@ void GfxFont::readFontDescriptor(XRef *xref, Dict *fontDict) {
// look for embedded font file // look for embedded font file
if (obj1.dictLookupNF("FontFile", &obj2)->isRef()) { if (obj1.dictLookupNF("FontFile", &obj2)->isRef()) {
if (type == fontType1) { embFontID = obj2.getRef();
embFontID = obj2.getRef(); if (type != fontType1) {
} else {
error(-1, "Mismatch between font type and embedded font file"); error(-1, "Mismatch between font type and embedded font file");
type = fontType1;
} }
} }
obj2.free(); obj2.free();
if (embFontID.num == -1 && if (embFontID.num == -1 &&
obj1.dictLookupNF("FontFile2", &obj2)->isRef()) { obj1.dictLookupNF("FontFile2", &obj2)->isRef()) {
if (type == fontTrueType || type == fontCIDType2) { embFontID = obj2.getRef();
embFontID = obj2.getRef(); if (type != fontTrueType && type != fontCIDType2) {
} else {
error(-1, "Mismatch between font type and embedded font file"); error(-1, "Mismatch between font type and embedded font file");
type = type == fontCIDType0 ? fontCIDType2 : fontTrueType;
} }
} }
obj2.free(); obj2.free();
...@@ -253,33 +253,29 @@ void GfxFont::readFontDescriptor(XRef *xref, Dict *fontDict) { ...@@ -253,33 +253,29 @@ void GfxFont::readFontDescriptor(XRef *xref, Dict *fontDict) {
if (obj2.fetch(xref, &obj3)->isStream()) { if (obj2.fetch(xref, &obj3)->isStream()) {
obj3.streamGetDict()->lookup("Subtype", &obj4); obj3.streamGetDict()->lookup("Subtype", &obj4);
if (obj4.isName("Type1")) { if (obj4.isName("Type1")) {
if (type == fontType1) {
embFontID = obj2.getRef(); embFontID = obj2.getRef();
} else { if (type != fontType1) {
error(-1, "Mismatch between font type and embedded font file"); error(-1, "Mismatch between font type and embedded font file");
type = fontType1;
} }
} else if (obj4.isName("Type1C")) { } else if (obj4.isName("Type1C")) {
if (type == fontType1) {
type = fontType1C;
embFontID = obj2.getRef(); embFontID = obj2.getRef();
} else if (type == fontType1C) { if (type != fontType1 && type != fontType1C) {
embFontID = obj2.getRef();
} else {
error(-1, "Mismatch between font type and embedded font file"); error(-1, "Mismatch between font type and embedded font file");
} }
type = fontType1C;
} else if (obj4.isName("TrueType")) { } else if (obj4.isName("TrueType")) {
if (type == fontTrueType) {
embFontID = obj2.getRef(); embFontID = obj2.getRef();
} else { if (type != fontTrueType) {
error(-1, "Mismatch between font type and embedded font file"); error(-1, "Mismatch between font type and embedded font file");
type = fontTrueType;
} }
} else if (obj4.isName("CIDFontType0C")) { } else if (obj4.isName("CIDFontType0C")) {
if (type == fontCIDType0) {
type = fontCIDType0C;
embFontID = obj2.getRef(); embFontID = obj2.getRef();
} else { if (type != fontCIDType0) {
error(-1, "Mismatch between font type and embedded font file"); error(-1, "Mismatch between font type and embedded font file");
} }
type = fontCIDType0C;
} else { } else {
error(-1, "Unknown embedded font type '%s'", error(-1, "Unknown embedded font type '%s'",
obj4.isName() ? obj4.getName() : "???"); obj4.isName() ? obj4.getName() : "???");
...@@ -440,6 +436,7 @@ Gfx8BitFont::Gfx8BitFont(XRef *xref, char *tagA, Ref idA, GooString *nameA, ...@@ -440,6 +436,7 @@ Gfx8BitFont::Gfx8BitFont(XRef *xref, char *tagA, Ref idA, GooString *nameA,
GfxFontType typeA, Dict *fontDict): GfxFontType typeA, Dict *fontDict):
GfxFont(tagA, idA, nameA) GfxFont(tagA, idA, nameA)
{ {
GooString *name2;
BuiltinFont *builtinFont; BuiltinFont *builtinFont;
char **baseEnc; char **baseEnc;
GBool baseEncFromFontFile; GBool baseEncFromFontFile;
...@@ -465,20 +462,30 @@ Gfx8BitFont::Gfx8BitFont(XRef *xref, char *tagA, Ref idA, GooString *nameA, ...@@ -465,20 +462,30 @@ Gfx8BitFont::Gfx8BitFont(XRef *xref, char *tagA, Ref idA, GooString *nameA,
// do font name substitution for various aliases of the Base 14 font // do font name substitution for various aliases of the Base 14 font
// names // names
if (name) { if (name) {
name2 = name->copy();
i = 0;
while (i < name2->getLength()) {
if (name2->getChar(i) == ' ') {
name2->del(i);
} else {
++i;
}
}
a = 0; a = 0;
b = sizeof(stdFontMap) / sizeof(StdFontMapEntry); b = sizeof(stdFontMap) / sizeof(StdFontMapEntry);
// invariant: stdFontMap[a].altName <= name < stdFontMap[b].altName // invariant: stdFontMap[a].altName <= name2 < stdFontMap[b].altName
while (b - a > 1) { while (b - a > 1) {
m = (a + b) / 2; m = (a + b) / 2;
if (name->cmp(stdFontMap[m].altName) >= 0) { if (name2->cmp(stdFontMap[m].altName) >= 0) {
a = m; a = m;
} else { } else {
b = m; b = m;
} }
} }
if (!name->cmp(stdFontMap[a].altName)) { if (!name2->cmp(stdFontMap[a].altName)) {
name = new GooString(stdFontMap[a].properName); name = new GooString(stdFontMap[a].properName);
} }
delete name2;
} }
// is it a built-in font? // is it a built-in font?
...@@ -509,6 +516,17 @@ Gfx8BitFont::Gfx8BitFont(XRef *xref, char *tagA, Ref idA, GooString *nameA, ...@@ -509,6 +516,17 @@ Gfx8BitFont::Gfx8BitFont(XRef *xref, char *tagA, Ref idA, GooString *nameA,
// get info from font descriptor // get info from font descriptor
readFontDescriptor(xref, fontDict); readFontDescriptor(xref, fontDict);
// for non-embedded fonts, don't trust the ascent/descent/bbox
// values from the font descriptor
if (builtinFont && embFontID.num < 0) {
ascent = 0.001 * builtinFont->ascent;
descent = 0.001 * builtinFont->descent;
fontBBox[0] = 0.001 * builtinFont->bbox[0];
fontBBox[1] = 0.001 * builtinFont->bbox[1];
fontBBox[2] = 0.001 * builtinFont->bbox[2];
fontBBox[3] = 0.001 * builtinFont->bbox[3];
}
// look for an external font file // look for an external font file
findExtFontFile(); findExtFontFile();
...@@ -554,7 +572,7 @@ Gfx8BitFont::Gfx8BitFont(XRef *xref, char *tagA, Ref idA, GooString *nameA, ...@@ -554,7 +572,7 @@ Gfx8BitFont::Gfx8BitFont(XRef *xref, char *tagA, Ref idA, GooString *nameA,
// 2. embedded or external font file // 2. embedded or external font file
// 3. default: // 3. default:
// - builtin --> builtin encoding // - builtin --> builtin encoding
// - TrueType --> MacRomanEncoding // - TrueType --> WinAnsiEncoding
// - others --> StandardEncoding // - others --> StandardEncoding
// and then add a list of differences (if any) from // and then add a list of differences (if any) from
// FontDict.Encoding.Differences. // FontDict.Encoding.Differences.
...@@ -577,9 +595,6 @@ Gfx8BitFont::Gfx8BitFont(XRef *xref, char *tagA, Ref idA, GooString *nameA, ...@@ -577,9 +595,6 @@ Gfx8BitFont::Gfx8BitFont(XRef *xref, char *tagA, Ref idA, GooString *nameA,
} else if (obj2.isName("WinAnsiEncoding")) { } else if (obj2.isName("WinAnsiEncoding")) {
hasEncoding = gTrue; hasEncoding = gTrue;
baseEnc = winAnsiEncoding; baseEnc = winAnsiEncoding;
} else if (obj2.isName("StandardEncoding")) {
hasEncoding = gTrue;
baseEnc = standardEncoding;
} }
obj2.free(); obj2.free();
} else if (obj1.isName("MacRomanEncoding")) { } else if (obj1.isName("MacRomanEncoding")) {
...@@ -592,9 +607,6 @@ Gfx8BitFont::Gfx8BitFont(XRef *xref, char *tagA, Ref idA, GooString *nameA, ...@@ -592,9 +607,6 @@ Gfx8BitFont::Gfx8BitFont(XRef *xref, char *tagA, Ref idA, GooString *nameA,
} else if (obj1.isName("WinAnsiEncoding")) { } else if (obj1.isName("WinAnsiEncoding")) {
hasEncoding = gTrue; hasEncoding = gTrue;
baseEnc = winAnsiEncoding; baseEnc = winAnsiEncoding;
} else if (obj1.isName("StandardEncoding")) {
hasEncoding = gTrue;
baseEnc = standardEncoding;
} }
// check embedded or external font file for base encoding // check embedded or external font file for base encoding
...@@ -648,7 +660,7 @@ Gfx8BitFont::Gfx8BitFont(XRef *xref, char *tagA, Ref idA, GooString *nameA, ...@@ -648,7 +660,7 @@ Gfx8BitFont::Gfx8BitFont(XRef *xref, char *tagA, Ref idA, GooString *nameA,
// get default base encoding // get default base encoding
if (!baseEnc) { if (!baseEnc) {
if (builtinFont) { if (builtinFont && embFontID.num < 0) {
baseEnc = builtinFont->defaultBaseEnc; baseEnc = builtinFont->defaultBaseEnc;
hasEncoding = gTrue; hasEncoding = gTrue;
} else if (type == fontTrueType) { } else if (type == fontTrueType) {
...@@ -960,7 +972,8 @@ Gushort *Gfx8BitFont::getCodeToGIDMap(FoFiTrueType *ff) { ...@@ -960,7 +972,8 @@ Gushort *Gfx8BitFont::getCodeToGIDMap(FoFiTrueType *ff) {
// directly (possibly with an offset of 0xf000). // directly (possibly with an offset of 0xf000).
// 1d. If the TrueType font has a Macintosh Roman cmap, use it, // 1d. If the TrueType font has a Macintosh Roman cmap, use it,
// as in case 1a. // as in case 1a.
// 2. If the PDF font does not have an encoding: // 2. If the PDF font does not have an encoding or the PDF font is
// symbolic:
// 2a. If the TrueType font has a Macintosh Roman cmap, use it, // 2a. If the TrueType font has a Macintosh Roman cmap, use it,
// and use char codes directly (possibly with an offset of // and use char codes directly (possibly with an offset of
// 0xf000). // 0xf000).
...@@ -994,8 +1007,11 @@ Gushort *Gfx8BitFont::getCodeToGIDMap(FoFiTrueType *ff) { ...@@ -994,8 +1007,11 @@ Gushort *Gfx8BitFont::getCodeToGIDMap(FoFiTrueType *ff) {
useUnicode = gTrue; useUnicode = gTrue;
} else if ((flags & fontSymbolic) && msSymbolCmap >= 0) { } else if ((flags & fontSymbolic) && msSymbolCmap >= 0) {
cmap = msSymbolCmap; cmap = msSymbolCmap;
} else if ((flags & fontSymbolic) && macRomanCmap >= 0) {
cmap = macRomanCmap;
} else if (macRomanCmap >= 0) { } else if (macRomanCmap >= 0) {
cmap = macRomanCmap; cmap = macRomanCmap;
useMacRoman = gTrue;
} }
} else { } else {
if (macRomanCmap >= 0) { if (macRomanCmap >= 0) {
...@@ -1019,7 +1035,9 @@ Gushort *Gfx8BitFont::getCodeToGIDMap(FoFiTrueType *ff) { ...@@ -1019,7 +1035,9 @@ Gushort *Gfx8BitFont::getCodeToGIDMap(FoFiTrueType *ff) {
// map Unicode through the cmap // map Unicode through the cmap
} else if (useUnicode) { } else if (useUnicode) {
for (i = 0; i < 256; ++i) { for (i = 0; i < 256; ++i) {
if ((n = ctu->mapToUnicode((CharCode)i, &u, 1))) { if (((charName = enc[i]) &&
(u = globalParams->mapNameToUnicode(charName))) ||
(n = ctu->mapToUnicode((CharCode)i, &u, 1))) {
map[i] = ff->mapCodeToGID(cmap, u); map[i] = ff->mapCodeToGID(cmap, u);
} }
} }
...@@ -1083,8 +1101,11 @@ GfxCIDFont::GfxCIDFont(XRef *xref, char *tagA, Ref idA, GooString *nameA, ...@@ -1083,8 +1101,11 @@ GfxCIDFont::GfxCIDFont(XRef *xref, char *tagA, Ref idA, GooString *nameA,
GooString *collection, *cMapName; GooString *collection, *cMapName;
Object desFontDictObj; Object desFontDictObj;
Object obj1, obj2, obj3, obj4, obj5, obj6; Object obj1, obj2, obj3, obj4, obj5, obj6;
CharCodeToUnicode *utu;
CharCode c;
Unicode uBuf[8];
int c1, c2; int c1, c2;
int excepsSize, i, j, k; int excepsSize, i, j, k, n;
ascent = 0.95; ascent = 0.95;
descent = -0.35; descent = -0.35;
...@@ -1166,12 +1187,30 @@ GfxCIDFont::GfxCIDFont(XRef *xref, char *tagA, Ref idA, GooString *nameA, ...@@ -1166,12 +1187,30 @@ GfxCIDFont::GfxCIDFont(XRef *xref, char *tagA, Ref idA, GooString *nameA,
if (!(ctu = globalParams->getCIDToUnicode(collection))) { if (!(ctu = globalParams->getCIDToUnicode(collection))) {
error(-1, "Unknown character collection '%s'", error(-1, "Unknown character collection '%s'",
collection->getCString()); collection->getCString());
delete collection; // fall-through, assuming the Identity mapping -- this appears
goto err2; // to match Adobe's behavior
} }
} }
} }
// look for a Unicode-to-Unicode mapping
if (name && (utu = globalParams->getUnicodeToUnicode(name))) {
if (ctu) {
for (c = 0; c < ctu->getLength(); ++c) {
n = ctu->mapToUnicode(c, uBuf, 8);
if (n >= 1) {
n = utu->mapToUnicode((CharCode)uBuf[0], uBuf, 8);
if (n >= 1) {
ctu->setMapping(c, uBuf, n);
}
}
}
utu->decRefCnt();
} else {
ctu = utu;
}
}
// encoding (i.e., CMap) // encoding (i.e., CMap)
//~ need to handle a CMap stream here //~ need to handle a CMap stream here
//~ also need to deal with the UseCMap entry in the stream dict //~ also need to deal with the UseCMap entry in the stream dict
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment