X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;ds=inline;f=pdf%2Fxpdf%2FUnicodeMap.cc;h=300d802aa555ee01d706f3acd97fabdcbcd94dc6;hb=3318b01eed1dbe76201682b34da16d9e02d998d5;hp=bfa5eccb9c605224dde4fe0b02c390db8bade250;hpb=28c37dbcf87665a4ccec58bef9ef8ff0697022dd;p=evince.git diff --git a/pdf/xpdf/UnicodeMap.cc b/pdf/xpdf/UnicodeMap.cc index bfa5eccb..300d802a 100644 --- a/pdf/xpdf/UnicodeMap.cc +++ b/pdf/xpdf/UnicodeMap.cc @@ -2,7 +2,7 @@ // // UnicodeMap.cc // -// Copyright 2001-2002 Glyph & Cog, LLC +// Copyright 2001-2003 Glyph & Cog, LLC // //======================================================================== @@ -116,6 +116,9 @@ UnicodeMap::UnicodeMap(GString *encodingNameA) { eMaps = NULL; eMapsLen = 0; refCnt = 1; +#if MULTITHREADED + gInitMutex(&mutex); +#endif } UnicodeMap::UnicodeMap(char *encodingNameA, GBool unicodeOutA, @@ -128,6 +131,9 @@ UnicodeMap::UnicodeMap(char *encodingNameA, GBool unicodeOutA, eMaps = NULL; eMapsLen = 0; refCnt = 1; +#if MULTITHREADED + gInitMutex(&mutex); +#endif } UnicodeMap::UnicodeMap(char *encodingNameA, GBool unicodeOutA, @@ -139,6 +145,9 @@ UnicodeMap::UnicodeMap(char *encodingNameA, GBool unicodeOutA, eMaps = NULL; eMapsLen = 0; refCnt = 1; +#if MULTITHREADED + gInitMutex(&mutex); +#endif } UnicodeMap::~UnicodeMap() { @@ -149,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; } } @@ -175,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) {