From ac2a0eb0c40a6704d614f309a5d7a363eae4f401 Mon Sep 17 00:00:00 2001 From: Jason Crain Date: Sun, 12 Jan 2014 12:19:01 -0600 Subject: [PATCH] Don't parse hex/decimal from character names Remove parsing of character names as hex or decimal Unicode code points. Use the character code as fallback if the character name can't be parsed. --- poppler/GfxFont.cc | 75 +++++++++---------------------------------------- poppler/GlobalParams.cc | 2 +- 2 files changed, 15 insertions(+), 62 deletions(-) diff --git a/poppler/GfxFont.cc b/poppler/GfxFont.cc index c54181b..6e00c5d 100644 --- a/poppler/GfxFont.cc +++ b/poppler/GfxFont.cc @@ -167,7 +167,7 @@ static const char *base14SubstFonts[14] = { static int parseCharName(char *charName, Unicode *uBuf, int uLen, GBool names, GBool ligatures, - GBool numeric, GBool hex, GBool variants); + GBool numeric, GBool variants); //------------------------------------------------------------------------ @@ -929,7 +929,7 @@ Gfx8BitFont::Gfx8BitFont(XRef *xref, const char *tagA, Ref idA, GooString *nameA FoFiType1C *ffT1C; int code; char *charName; - GBool missing, hex; + GBool missing; Unicode toUnicode[256]; CharCodeToUnicode *utu, *ctu2; Unicode uBuf[8]; @@ -1221,7 +1221,7 @@ Gfx8BitFont::Gfx8BitFont(XRef *xref, const char *tagA, Ref idA, GooString *nameA //----- build the mapping to Unicode ----- // pass 1: use the name-to-Unicode mapping table - missing = hex = gFalse; + missing = gFalse; GBool isZapfDingbats = name && name->endsWith("ZapfDingbats"); for (code = 0; code < 256; ++code) { if ((charName = enc[code])) { @@ -1232,24 +1232,6 @@ Gfx8BitFont::Gfx8BitFont(XRef *xref, const char *tagA, Ref idA, GooString *nameA toUnicode[code] = globalParams->mapNameToUnicodeText(charName); } if (!toUnicode[code] && strcmp(charName, ".notdef")) { - // if it wasn't in the name-to-Unicode table, check for a - // name that looks like 'Axx' or 'xx', where 'A' is any letter - // and 'xx' is two hex digits - if ((strlen(charName) == 3 && - isalpha(charName[0]) && - isxdigit(charName[1]) && isxdigit(charName[2]) && - ((charName[1] >= 'a' && charName[1] <= 'f') || - (charName[1] >= 'A' && charName[1] <= 'F') || - (charName[2] >= 'a' && charName[2] <= 'f') || - (charName[2] >= 'A' && charName[2] <= 'F'))) || - (strlen(charName) == 2 && - isxdigit(charName[0]) && isxdigit(charName[1]) && - ((charName[0] >= 'a' && charName[0] <= 'f') || - (charName[0] >= 'A' && charName[0] <= 'F') || - (charName[1] >= 'a' && charName[1] <= 'f') || - (charName[1] >= 'A' && charName[1] <= 'F')))) { - hex = gTrue; - } missing = gTrue; } } else { @@ -1281,21 +1263,16 @@ Gfx8BitFont::Gfx8BitFont(XRef *xref, const char *tagA, Ref idA, GooString *nameA gFalse, // don't check simple names (pass 1) gTrue, // do check ligatures globalParams->getMapNumericCharNames(), - hex, gTrue))) { // do check variants ctu->setMapping((CharCode)code, uBuf, n); - } else if (globalParams->getMapUnknownCharNames()) { - // if the 'mapUnknownCharNames' flag is set, do a simple pass-through - // mapping for unknown character names - if (charName && charName[0]) { - for (n = 0; n < (int)(sizeof(uBuf)/sizeof(*uBuf)); ++n) - if (!(uBuf[n] = charName[n])) - break; - ctu->setMapping((CharCode)code, uBuf, n); - } else { - uBuf[0] = code; - ctu->setMapping((CharCode)code, uBuf, 1); - } + continue; + } + + // if the 'mapUnknownCharNames' flag is set, do a simple pass-through + // mapping for unknown character names + if (globalParams->getMapUnknownCharNames()) { + uBuf[0] = code; + ctu->setMapping((CharCode)code, uBuf, 1); } } } @@ -1437,7 +1414,7 @@ Gfx8BitFont::~Gfx8BitFont() { // maintainability. static int parseCharName(char *charName, Unicode *uBuf, int uLen, GBool names, GBool ligatures, - GBool numeric, GBool hex, GBool variants) + GBool numeric, GBool variants) { if (uLen <= 0) { error(errInternal, -1, "Zero-length output buffer (recursion overflow?) in " @@ -1455,7 +1432,7 @@ static int parseCharName(char *charName, Unicode *uBuf, int uLen, char *main_part = gstrndup(charName, var_part - charName); GBool namesRecurse = gTrue, variantsRecurse = gFalse; int n = parseCharName(main_part, uBuf, uLen, namesRecurse, ligatures, - numeric, hex, variantsRecurse); + numeric, variantsRecurse); gfree(main_part); return n; } @@ -1473,7 +1450,7 @@ static int parseCharName(char *charName, Unicode *uBuf, int uLen, if (lig_part[0] != '\0') { GBool namesRecurse = gTrue, ligaturesRecurse = gFalse; if ((m = parseCharName(lig_part, uBuf + n, uLen - n, namesRecurse, - ligaturesRecurse, numeric, hex, variants))) + ligaturesRecurse, numeric, variants))) n += m; else error(errSyntaxWarning, -1, "Could not parse ligature component \"{0:s}\" of \"{1:s}\" in " @@ -1538,30 +1515,6 @@ static int parseCharName(char *charName, Unicode *uBuf, int uLen, return 1; } } - // Not in Adobe Glyph Mapping convention: look for names of the form 'Axx', - // 'xx', 'Ann', 'ABnn', or 'nn', where 'A' and 'B' are any letters, 'xx' is - // two hex digits, and 'nn' is 2-4 decimal digits - if (hex && n == 3 && isalpha(charName[0]) && - isxdigit(charName[1]) && isxdigit(charName[2])) { - sscanf(charName+1, "%x", (unsigned int *)uBuf); - return 1; - } else if (hex && n == 2 && - isxdigit(charName[0]) && isxdigit(charName[1])) { - sscanf(charName, "%x", (unsigned int *)uBuf); - return 1; - } else if (!hex && n >= 2 && n <= 4 && - isdigit(charName[0]) && isdigit(charName[1])) { - uBuf[0] = (Unicode)atoi(charName); - return 1; - } else if (n >= 3 && n <= 5 && - isdigit(charName[1]) && isdigit(charName[2])) { - uBuf[0] = (Unicode)atoi(charName+1); - return 1; - } else if (n >= 4 && n <= 6 && - isdigit(charName[2]) && isdigit(charName[3])) { - uBuf[0] = (Unicode)atoi(charName+2); - return 1; - } } // 3.5. otherwise, map the component to the empty string return 0; diff --git a/poppler/GlobalParams.cc b/poppler/GlobalParams.cc index 01a3157..e92889c 100644 --- a/poppler/GlobalParams.cc +++ b/poppler/GlobalParams.cc @@ -633,7 +633,7 @@ GlobalParams::GlobalParams(const char *customPopplerDataDir) minLineWidth = 0.0; overprintPreview = gFalse; mapNumericCharNames = gTrue; - mapUnknownCharNames = gFalse; + mapUnknownCharNames = gTrue; printCommands = gFalse; profileCommands = gFalse; errQuiet = gFalse; -- 1.8.5.2