Diffstat (limited to 'noncore/unsupported/qpdf/xpdf/CMap.cc') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/unsupported/qpdf/xpdf/CMap.cc | 94 |
1 files changed, 57 insertions, 37 deletions
diff --git a/noncore/unsupported/qpdf/xpdf/CMap.cc b/noncore/unsupported/qpdf/xpdf/CMap.cc index 57809f0..b49cffd 100644 --- a/noncore/unsupported/qpdf/xpdf/CMap.cc +++ b/noncore/unsupported/qpdf/xpdf/CMap.cc @@ -1,11 +1,11 @@ //======================================================================== // // CMap.cc // -// Copyright 2001 Derek B. Noonburg +// Copyright 2001-2002 Glyph & Cog, LLC // //======================================================================== #ifdef __GNUC__ #pragma implementation #endif @@ -17,12 +17,13 @@ #include <ctype.h> #include "gmem.h" #include "gfile.h" #include "GString.h" #include "Error.h" #include "GlobalParams.h" +#include "PSTokenizer.h" #include "CMap.h" //------------------------------------------------------------------------ struct CMapVectorEntry { GBool isVector; @@ -31,21 +32,26 @@ struct CMapVectorEntry { CID cid; }; }; //------------------------------------------------------------------------ +static int getCharFromFile(void *data) { + return fgetc((FILE *)data); +} + +//------------------------------------------------------------------------ + CMap *CMap::parse(CMapCache *cache, GString *collectionA, GString *cMapNameA) { FILE *f; CMap *cmap; - char buf[256]; - GBool inCodeSpace, inCIDRange; - char *tok1, *tok2, *tok3; + PSTokenizer *pst; + char tok1[256], tok2[256], tok3[256]; + int n1, n2, n3; Guint start, end; - Guint n; if (!(f = globalParams->findCMapFile(collectionA, cMapNameA))) { // Check for an identity CMap. if (!cMapNameA->cmp("Identity") || !cMapNameA->cmp("Identity-H")) { return new CMap(collectionA->copy(), cMapNameA->copy(), 0); @@ -58,56 +64,70 @@ CMap *CMap::parse(CMapCache *cache, GString *collectionA, cMapNameA->getCString(), collectionA->getCString()); return NULL; } cmap = new CMap(collectionA->copy(), cMapNameA->copy()); - inCodeSpace = inCIDRange = gFalse; - while (getLine(buf, sizeof(buf), f)) { - tok1 = strtok(buf, " \t\r\n"); - if (!tok1 || tok1[0] == '%') { - continue; + pst = new PSTokenizer(&getCharFromFile, f); + pst->getToken(tok1, sizeof(tok1), &n1); + while (pst->getToken(tok2, sizeof(tok2), &n2)) { + if (!strcmp(tok2, "usecmap")) { + if (tok1[0] == '/') { + cmap->useCMap(cache, tok1 + 1); } - tok2 = strtok(NULL, " \t\r\n"); - tok3 = strtok(NULL, " \t\r\n"); - if (inCodeSpace) { + pst->getToken(tok1, sizeof(tok1), &n1); + } else if (!strcmp(tok1, "/WMode")) { + cmap->wMode = atoi(tok2); + pst->getToken(tok1, sizeof(tok1), &n1); + } else if (!strcmp(tok2, "begincodespacerange")) { + while (pst->getToken(tok1, sizeof(tok1), &n1)) { if (!strcmp(tok1, "endcodespacerange")) { - inCodeSpace = gFalse; - } else if (tok2 && tok1[0] == '<' && tok2[0] == '<' && - (n = strlen(tok1)) == strlen(tok2) && - n >= 4 && (n & 1) == 0) { - tok1[n - 1] = tok2[n - 1] = '\0'; + break; + } + if (!pst->getToken(tok2, sizeof(tok2), &n2) || + !strcmp(tok2, "endcodespacerange")) { + error(-1, "Illegal entry in codespacerange block in CMap"); + break; + } + if (tok1[0] == '<' && tok2[0] == '<' && + n1 == n2 && n1 >= 4 && (n1 & 1) == 0) { + tok1[n1 - 1] = tok2[n1 - 1] = '\0'; sscanf(tok1 + 1, "%x", &start); sscanf(tok2 + 1, "%x", &end); - n = (n - 2) / 2; - cmap->addCodeSpace(cmap->vector, start, end, n); + n1 = (n1 - 2) / 2; + cmap->addCodeSpace(cmap->vector, start, end, n1); } - } else if (inCIDRange) { + } + pst->getToken(tok1, sizeof(tok1), &n1); + } else if (!strcmp(tok2, "begincidrange")) { + while (pst->getToken(tok1, sizeof(tok1), &n1)) { if (!strcmp(tok1, "endcidrange")) { - inCIDRange = gFalse; - } else if (tok2 && tok3 && tok1[0] == '<' && tok2[0] == '<' && - (n = strlen(tok1)) == strlen(tok2) && - n >= 4 && (n & 1) == 0) { - tok1[n - 1] = tok2[n - 1] = '\0'; + break; + } + if (!pst->getToken(tok2, sizeof(tok2), &n2) || + !strcmp(tok2, "endcidrange") || + !pst->getToken(tok3, sizeof(tok3), &n3) || + !strcmp(tok3, "endcidrange")) { + error(-1, "Illegal entry in cidrange block in CMap"); + break; + } + if (tok1[0] == '<' && tok2[0] == '<' && + n1 == n2 && n1 >= 4 && (n1 & 1) == 0) { + tok1[n1 - 1] = tok2[n1 - 1] = '\0'; sscanf(tok1 + 1, "%x", &start); sscanf(tok2 + 1, "%x", &end); - n = (n - 2) / 2; - cmap->addCIDs(start, end, n, (CID)atoi(tok3)); + n1 = (n1 - 2) / 2; + cmap->addCIDs(start, end, n1, (CID)atoi(tok3)); } - } else if (tok2 && !strcmp(tok2, "usecmap")) { - if (tok1[0] == '/') { - cmap->useCMap(cache, tok1 + 1); } - } else if (!strcmp(tok1, "/WMode")) { - cmap->wMode = atoi(tok2); - } else if (tok2 && !strcmp(tok2, "begincodespacerange")) { - inCodeSpace = gTrue; - } else if (tok2 && !strcmp(tok2, "begincidrange")) { - inCIDRange = gTrue; + pst->getToken(tok1, sizeof(tok1), &n1); + } else { + strcpy(tok1, tok2); } } + delete pst; fclose(f); return cmap; } |