X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;f=pdf2swf%2Fxpdf%2FUnicodeMap.cc;h=300d802aa555ee01d706f3acd97fabdcbcd94dc6;hb=c7432833fe3a6469d63fad135151a92e12877b94;hp=75f23d2b7bcb28a888c77ae816615060e327fee4;hpb=b9ddd4a2ed601bc01ddacc69d2522687a93a94ce;p=swftools.git diff --git a/pdf2swf/xpdf/UnicodeMap.cc b/pdf2swf/xpdf/UnicodeMap.cc index 75f23d2..300d802 100644 --- a/pdf2swf/xpdf/UnicodeMap.cc +++ b/pdf2swf/xpdf/UnicodeMap.cc @@ -2,15 +2,16 @@ // // UnicodeMap.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 "gmem.h" @@ -101,37 +102,52 @@ UnicodeMap *UnicodeMap::parse(GString *encodingNameA) { ++line; } + fclose(f); + return map; } UnicodeMap::UnicodeMap(GString *encodingNameA) { encodingName = encodingNameA; + unicodeOut = gFalse; kind = unicodeMapUser; ranges = NULL; len = 0; eMaps = NULL; eMapsLen = 0; refCnt = 1; +#if MULTITHREADED + gInitMutex(&mutex); +#endif } -UnicodeMap::UnicodeMap(char *encodingNameA, +UnicodeMap::UnicodeMap(char *encodingNameA, GBool unicodeOutA, UnicodeMapRange *rangesA, int lenA) { encodingName = new GString(encodingNameA); + unicodeOut = unicodeOutA; kind = unicodeMapResident; ranges = rangesA; len = lenA; eMaps = NULL; eMapsLen = 0; refCnt = 1; +#if MULTITHREADED + gInitMutex(&mutex); +#endif } -UnicodeMap::UnicodeMap(char *encodingNameA, UnicodeMapFunc funcA) { +UnicodeMap::UnicodeMap(char *encodingNameA, GBool unicodeOutA, + UnicodeMapFunc funcA) { encodingName = new GString(encodingNameA); + unicodeOut = unicodeOutA; kind = unicodeMapFunc; func = funcA; eMaps = NULL; eMapsLen = 0; refCnt = 1; +#if MULTITHREADED + gInitMutex(&mutex); +#endif } UnicodeMap::~UnicodeMap() { @@ -142,14 +158,32 @@ UnicodeMap::~UnicodeMap() { if (eMaps) { gfree(eMaps); } +#if MULTITHREADED + gDestroyMutex(&mutex); +#endif } void UnicodeMap::incRefCnt() { +#if MULTITHREADED + gLockMutex(&mutex); +#endif ++refCnt; +#if MULTITHREADED + gUnlockMutex(&mutex); +#endif } void UnicodeMap::decRefCnt() { - if (--refCnt == 0) { + GBool done; + +#if MULTITHREADED + gLockMutex(&mutex); +#endif + done = --refCnt == 0; +#if MULTITHREADED + gUnlockMutex(&mutex); +#endif + if (done) { delete this; } } @@ -168,29 +202,28 @@ int UnicodeMap::mapUnicode(Unicode u, char *buf, int bufSize) { a = 0; b = len; - if (u < ranges[a].start) { - return 0; - } - // invariant: ranges[a].start <= u < ranges[b].start - while (b - a > 1) { - m = (a + b) / 2; - if (u >= ranges[m].start) { - a = m; - } else if (u < ranges[m].start) { - b = m; - } - } - if (u <= ranges[a].end) { - n = ranges[a].nBytes; - if (n > bufSize) { - return 0; + if (u >= ranges[a].start) { + // invariant: ranges[a].start <= u < ranges[b].start + while (b - a > 1) { + m = (a + b) / 2; + if (u >= ranges[m].start) { + a = m; + } else if (u < ranges[m].start) { + b = m; + } } - code = ranges[a].code + (u - ranges[a].start); - for (i = n - 1; i >= 0; --i) { - buf[i] = (char)(code & 0xff); - code >>= 8; + if (u <= ranges[a].end) { + n = ranges[a].nBytes; + if (n > bufSize) { + return 0; + } + code = ranges[a].code + (u - ranges[a].start); + for (i = n - 1; i >= 0; --i) { + buf[i] = (char)(code & 0xff); + code >>= 8; + } + return n; } - return n; } for (i = 0; i < eMapsLen; ++i) {