X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=pdf2swf%2Fxpdf%2FCMap.cc;h=303cf095224c04e81036c3d6cb6d3fc72442279d;hb=4d50e9ccf474061088318da8e7a67789fd488a2a;hp=b49cffdc2bbe5f9782927e3970ac1c2a9b45d524;hpb=3df3a8d12d7a516579a4eae276b077c015df0f70;p=swftools.git diff --git a/pdf2swf/xpdf/CMap.cc b/pdf2swf/xpdf/CMap.cc index b49cffd..303cf09 100644 --- a/pdf2swf/xpdf/CMap.cc +++ b/pdf2swf/xpdf/CMap.cc @@ -2,15 +2,16 @@ // // CMap.cc // -// Copyright 2001-2002 Glyph & Cog, LLC +// Copyright 2001-2003 Glyph & Cog, LLC // //======================================================================== -#ifdef __GNUC__ +#include + +#ifdef USE_GCC_PRAGMAS #pragma implementation #endif -#include #include #include #include @@ -48,7 +49,7 @@ CMap *CMap::parse(CMapCache *cache, GString *collectionA, PSTokenizer *pst; char tok1[256], tok2[256], tok3[256]; int n1, n2, n3; - Guint start, end; + Guint start, end, code; if (!(f = globalParams->findCMapFile(collectionA, cMapNameA))) { @@ -98,6 +99,30 @@ CMap *CMap::parse(CMapCache *cache, GString *collectionA, } } pst->getToken(tok1, sizeof(tok1), &n1); + } else if (!strcmp(tok2, "begincidchar")) { + while (pst->getToken(tok1, sizeof(tok1), &n1)) { + if (!strcmp(tok1, "endcidchar")) { + break; + } + if (!pst->getToken(tok2, sizeof(tok2), &n2) || + !strcmp(tok2, "endcidchar")) { + error(-1, "Illegal entry in cidchar block in CMap"); + break; + } + if (!(tok1[0] == '<' && tok1[n1 - 1] == '>' && + n1 >= 4 && (n1 & 1) == 0)) { + error(-1, "Illegal entry in cidchar block in CMap"); + continue; + } + tok1[n1 - 1] = '\0'; + if (sscanf(tok1 + 1, "%x", &code) != 1) { + error(-1, "Illegal entry in cidchar block in CMap"); + continue; + } + n1 = (n1 - 2) / 2; + cmap->addCIDs(code, code, n1, (CID)atoi(tok2)); + } + pst->getToken(tok1, sizeof(tok1), &n1); } else if (!strcmp(tok2, "begincidrange")) { while (pst->getToken(tok1, sizeof(tok1), &n1)) { if (!strcmp(tok1, "endcidrange")) { @@ -137,12 +162,15 @@ CMap::CMap(GString *collectionA, GString *cMapNameA) { collection = collectionA; cMapName = cMapNameA; wMode = 0; - vector = (CMapVectorEntry *)gmalloc(256 * sizeof(CMapVectorEntry)); + vector = (CMapVectorEntry *)gmallocn(256, sizeof(CMapVectorEntry)); for (i = 0; i < 256; ++i) { vector[i].isVector = gFalse; vector[i].cid = 0; } refCnt = 1; +#if MULTITHREADED + gInitMutex(&mutex); +#endif } CMap::CMap(GString *collectionA, GString *cMapNameA, int wModeA) { @@ -151,6 +179,9 @@ CMap::CMap(GString *collectionA, GString *cMapNameA, int wModeA) { wMode = wModeA; vector = NULL; refCnt = 1; +#if MULTITHREADED + gInitMutex(&mutex); +#endif } void CMap::useCMap(CMapCache *cache, char *useName) { @@ -175,7 +206,7 @@ void CMap::copyVector(CMapVectorEntry *dest, CMapVectorEntry *src) { if (!dest[i].isVector) { dest[i].isVector = gTrue; dest[i].vector = - (CMapVectorEntry *)gmalloc(256 * sizeof(CMapVectorEntry)); + (CMapVectorEntry *)gmallocn(256, sizeof(CMapVectorEntry)); for (j = 0; j < 256; ++j) { dest[i].vector[j].isVector = gFalse; dest[i].vector[j].cid = 0; @@ -206,7 +237,7 @@ void CMap::addCodeSpace(CMapVectorEntry *vec, Guint start, Guint end, if (!vec[i].isVector) { vec[i].isVector = gTrue; vec[i].vector = - (CMapVectorEntry *)gmalloc(256 * sizeof(CMapVectorEntry)); + (CMapVectorEntry *)gmallocn(256, sizeof(CMapVectorEntry)); for (j = 0; j < 256; ++j) { vec[i].vector[j].isVector = gFalse; vec[i].vector[j].cid = 0; @@ -227,7 +258,7 @@ void CMap::addCIDs(Guint start, Guint end, Guint nBytes, CID firstCID) { for (i = nBytes - 1; i >= 1; --i) { byte = (start >> (8 * i)) & 0xff; if (!vec[byte].isVector) { - error(-1, "Invalid CID (%*x - %*x) in CMap", + error(-1, "Invalid CID (%0*x - %0*x) in CMap", 2*nBytes, start, 2*nBytes, end); return; } @@ -236,7 +267,7 @@ void CMap::addCIDs(Guint start, Guint end, Guint nBytes, CID firstCID) { cid = firstCID; for (byte = (int)(start & 0xff); byte <= (int)(end & 0xff); ++byte) { if (vec[byte].isVector) { - error(-1, "Invalid CID (%*x - %*x) in CMap", + error(-1, "Invalid CID (%0*x - %0*x) in CMap", 2*nBytes, start, 2*nBytes, end); } else { vec[byte].cid = cid; @@ -251,6 +282,9 @@ CMap::~CMap() { if (vector) { freeCMapVector(vector); } +#if MULTITHREADED + gDestroyMutex(&mutex); +#endif } void CMap::freeCMapVector(CMapVectorEntry *vec) { @@ -265,11 +299,26 @@ void CMap::freeCMapVector(CMapVectorEntry *vec) { } void CMap::incRefCnt() { +#if MULTITHREADED + gLockMutex(&mutex); +#endif ++refCnt; +#if MULTITHREADED + gUnlockMutex(&mutex); +#endif } void CMap::decRefCnt() { - if (--refCnt == 0) { + GBool done; + +#if MULTITHREADED + gLockMutex(&mutex); +#endif + done = --refCnt == 0; +#if MULTITHREADED + gUnlockMutex(&mutex); +#endif + if (done) { delete this; } }