X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;ds=sidebyside;f=pdf%2Fxpdf%2FGlobalParams.cc;h=9aa54e9e7ad32645176b6643933017711cf1939a;hb=ad63666daeeda50acc7630132d61fe044634fddd;hp=0bc908eada7a8c4d78f01fa65996887ac34ffbbb;hpb=2a393c134fe3fe8eb85bf818cb7ad6ae4396322a;p=evince.git diff --git a/pdf/xpdf/GlobalParams.cc b/pdf/xpdf/GlobalParams.cc index 0bc908ea..9aa54e9e 100644 --- a/pdf/xpdf/GlobalParams.cc +++ b/pdf/xpdf/GlobalParams.cc @@ -2,15 +2,16 @@ // // GlobalParams.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 #if HAVE_PAPER_H @@ -30,6 +31,22 @@ #include "FontEncodingTables.h" #include "GlobalParams.h" +#if MULTITHREADED +# define lockGlobalParams gLockMutex(&mutex) +# define lockUnicodeMapCache gLockMutex(&unicodeMapCacheMutex) +# define lockCMapCache gLockMutex(&cMapCacheMutex) +# define unlockGlobalParams gUnlockMutex(&mutex) +# define unlockUnicodeMapCache gUnlockMutex(&unicodeMapCacheMutex) +# define unlockCMapCache gUnlockMutex(&cMapCacheMutex) +#else +# define lockGlobalParams +# define lockUnicodeMapCache +# define lockCMapCache +# define unlockGlobalParams +# define unlockUnicodeMapCache +# define unlockCMapCache +#endif + #include "NameToUnicodeTable.h" #include "UnicodeMapTables.h" #include "DisplayFontTable.h" @@ -37,6 +54,11 @@ //------------------------------------------------------------------------ +#define cidToUnicodeCacheSize 4 +#define unicodeToUnicodeCacheSize 4 + +//------------------------------------------------------------------------ + GlobalParams *globalParams = NULL; //------------------------------------------------------------------------ @@ -123,6 +145,12 @@ GlobalParams::GlobalParams(char *cfgFileName) { FILE *f; int i; +#if MULTITHREADED + gInitMutex(&mutex); + gInitMutex(&unicodeMapCacheMutex); + gInitMutex(&cMapCacheMutex); +#endif + initBuiltinFontTables(); // scan the encoding in reverse because we want the lowest-numbered @@ -136,6 +164,7 @@ GlobalParams::GlobalParams(char *cfgFileName) { nameToUnicode = new NameToCharCode(); cidToUnicodes = new GHash(gTrue); + unicodeToUnicodes = new GHash(gTrue); residentUnicodeMaps = new GHash(); unicodeMaps = new GHash(gTrue); cMapDirs = new GHash(gTrue); @@ -144,11 +173,18 @@ GlobalParams::GlobalParams(char *cfgFileName) { displayCIDFonts = new GHash(); displayNamedCIDFonts = new GHash(); #if HAVE_PAPER_H + char *paperName; const struct paper *paperType; paperinit(); - paperType = paperinfo(systempapername()); - psPaperWidth = (int)paperpswidth(paperType); - psPaperHeight = (int)paperpsheight(paperType); + if ((paperName = systempapername())) { + paperType = paperinfo(paperName); + psPaperWidth = (int)paperpswidth(paperType); + psPaperHeight = (int)paperpsheight(paperType); + } else { + error(-1, "No paper information available - using defaults"); + psPaperWidth = defPaperWidth; + psPaperHeight = defPaperHeight; + } paperdone(); #else psPaperWidth = defPaperWidth; @@ -174,15 +210,21 @@ GlobalParams::GlobalParams(char *cfgFileName) { #else textEOL = eolUnix; #endif + textPageBreaks = gTrue; + textKeepTinyChars = gFalse; fontDirs = new GList(); - initialZoom = new GString("1"); + initialZoom = new GString("125"); t1libControl = fontRastAALow; freetypeControl = fontRastAALow; urlCommand = NULL; + movieCommand = NULL; mapNumericCharNames = gTrue; + printCommands = gFalse; errQuiet = gFalse; - cidToUnicodeCache = new CIDToUnicodeCache(); + cidToUnicodeCache = new CharCodeToUnicodeCache(cidToUnicodeCacheSize); + unicodeToUnicodeCache = + new CharCodeToUnicodeCache(unicodeToUnicodeCacheSize); unicodeMapCache = new UnicodeMapCache(); cMapCache = new CMapCache(); @@ -192,18 +234,21 @@ GlobalParams::GlobalParams(char *cfgFileName) { } // set up the residentUnicodeMaps table - map = new UnicodeMap("Latin1", latin1UnicodeMapRanges, latin1UnicodeMapLen); + map = new UnicodeMap("Latin1", gFalse, + latin1UnicodeMapRanges, latin1UnicodeMapLen); residentUnicodeMaps->add(map->getEncodingName(), map); - map = new UnicodeMap("ASCII7", ascii7UnicodeMapRanges, ascii7UnicodeMapLen); + map = new UnicodeMap("ASCII7", gFalse, + ascii7UnicodeMapRanges, ascii7UnicodeMapLen); residentUnicodeMaps->add(map->getEncodingName(), map); - map = new UnicodeMap("Symbol", symbolUnicodeMapRanges, symbolUnicodeMapLen); + map = new UnicodeMap("Symbol", gFalse, + symbolUnicodeMapRanges, symbolUnicodeMapLen); residentUnicodeMaps->add(map->getEncodingName(), map); - map = new UnicodeMap("ZapfDingbats", zapfDingbatsUnicodeMapRanges, + map = new UnicodeMap("ZapfDingbats", gFalse, zapfDingbatsUnicodeMapRanges, zapfDingbatsUnicodeMapLen); residentUnicodeMaps->add(map->getEncodingName(), map); - map = new UnicodeMap("UTF-8", &mapUTF8); + map = new UnicodeMap("UTF-8", gTrue, &mapUTF8); residentUnicodeMaps->add(map->getEncodingName(), map); - map = new UnicodeMap("UCS-2", &mapUCS2); + map = new UnicodeMap("UCS-2", gTrue, &mapUCS2); residentUnicodeMaps->add(map->getEncodingName(), map); // default displayFonts table @@ -235,7 +280,7 @@ GlobalParams::GlobalParams(char *cfgFileName) { i = GetModuleFileName(NULL, buf, sizeof(buf)); if (i <= 0 || i >= sizeof(buf)) { // error or path too long for buffer - just use the current dir - buf[i] = '\0'; + buf[0] = '\0'; } fileName = grabPath(buf); appendToPath(fileName, xpdfSysConfigFile); @@ -249,6 +294,7 @@ GlobalParams::GlobalParams(char *cfgFileName) { if (f) { parseFile(fileName, f); delete fileName; + fclose(f); } } @@ -261,7 +307,7 @@ void GlobalParams::parseFile(GString *fileName, FILE *f) { FILE *f2; line = 1; - while (fgets(buf, sizeof(buf) - 1, f)) { + while (getLine(buf, sizeof(buf) - 1, f)) { // break the line into tokens tokens = new GList(); @@ -278,7 +324,7 @@ void GlobalParams::parseFile(GString *fileName, FILE *f) { for (p2 = p1 + 1; *p2 && !isspace(*p2); ++p2) ; } tokens->append(new GString(p1, p2 - p1)); - p1 = p2 + 1; + p1 = *p2 ? p2 + 1 : p2; } if (tokens->getLength() > 0 && @@ -302,6 +348,8 @@ void GlobalParams::parseFile(GString *fileName, FILE *f) { parseNameToUnicode(tokens, fileName, line); } else if (!cmd->cmp("cidToUnicode")) { parseCIDToUnicode(tokens, fileName, line); + } else if (!cmd->cmp("unicodeToUnicode")) { + parseUnicodeToUnicode(tokens, fileName, line); } else if (!cmd->cmp("unicodeMap")) { parseUnicodeMap(tokens, fileName, line); } else if (!cmd->cmp("cMapDir")) { @@ -314,12 +362,24 @@ void GlobalParams::parseFile(GString *fileName, FILE *f) { parseDisplayFont(tokens, displayFonts, displayFontT1, fileName, line); } else if (!cmd->cmp("displayFontTT")) { parseDisplayFont(tokens, displayFonts, displayFontTT, fileName, line); + } else if (!cmd->cmp("displayNamedCIDFontX")) { + parseDisplayFont(tokens, displayNamedCIDFonts, + displayFontX, fileName, line); } else if (!cmd->cmp("displayCIDFontX")) { parseDisplayFont(tokens, displayCIDFonts, displayFontX, fileName, line); - } else if (!cmd->cmp("displayNamedCIDFontX")) { + } else if (!cmd->cmp("displayNamedCIDFontT1")) { parseDisplayFont(tokens, displayNamedCIDFonts, - displayFontX, fileName, line); + displayFontT1, fileName, line); + } else if (!cmd->cmp("displayCIDFontT1")) { + parseDisplayFont(tokens, displayCIDFonts, + displayFontT1, fileName, line); + } else if (!cmd->cmp("displayNamedCIDFontTT")) { + parseDisplayFont(tokens, displayNamedCIDFonts, + displayFontTT, fileName, line); + } else if (!cmd->cmp("displayCIDFontTT")) { + parseDisplayFont(tokens, displayCIDFonts, + displayFontTT, fileName, line); } else if (!cmd->cmp("psFile")) { parsePSFile(tokens, fileName, line); } else if (!cmd->cmp("psFont")) { @@ -354,6 +414,12 @@ void GlobalParams::parseFile(GString *fileName, FILE *f) { parseTextEncoding(tokens, fileName, line); } else if (!cmd->cmp("textEOL")) { parseTextEOL(tokens, fileName, line); + } else if (!cmd->cmp("textPageBreaks")) { + parseYesNo("textPageBreaks", &textPageBreaks, + tokens, fileName, line); + } else if (!cmd->cmp("textKeepTinyChars")) { + parseYesNo("textKeepTinyChars", &textKeepTinyChars, + tokens, fileName, line); } else if (!cmd->cmp("fontDir")) { parseFontDir(tokens, fileName, line); } else if (!cmd->cmp("initialZoom")) { @@ -365,10 +431,14 @@ void GlobalParams::parseFile(GString *fileName, FILE *f) { parseFontRastControl("freetypeControl", &freetypeControl, tokens, fileName, line); } else if (!cmd->cmp("urlCommand")) { - parseURLCommand(tokens, fileName, line); + parseCommand("urlCommand", &urlCommand, tokens, fileName, line); + } else if (!cmd->cmp("movieCommand")) { + parseCommand("movieCommand", &movieCommand, tokens, fileName, line); } else if (!cmd->cmp("mapNumericCharNames")) { parseYesNo("mapNumericCharNames", &mapNumericCharNames, tokens, fileName, line); + } else if (!cmd->cmp("printCommands")) { + parseYesNo("printCommands", &printCommands, tokens, fileName, line); } else if (!cmd->cmp("errQuiet")) { parseYesNo("errQuiet", &errQuiet, tokens, fileName, line); } else if (!cmd->cmp("fontpath") || !cmd->cmp("fontmap")) { @@ -406,7 +476,7 @@ void GlobalParams::parseNameToUnicode(GList *tokens, GString *fileName, return; } line2 = 1; - while (fgets(buf, sizeof(buf), f)) { + while (getLine(buf, sizeof(buf), f)) { tok1 = strtok(buf, " \t\r\n"); tok2 = strtok(NULL, " \t\r\n"); if (tok1 && tok2) { @@ -437,6 +507,23 @@ void GlobalParams::parseCIDToUnicode(GList *tokens, GString *fileName, cidToUnicodes->add(collection->copy(), name->copy()); } +void GlobalParams::parseUnicodeToUnicode(GList *tokens, GString *fileName, + int line) { + GString *font, *file, *old; + + if (tokens->getLength() != 3) { + error(-1, "Bad 'unicodeToUnicode' config file command (%s:%d)", + fileName->getCString(), line); + return; + } + font = (GString *)tokens->get(1); + file = (GString *)tokens->get(2); + if ((old = (GString *)unicodeToUnicodes->remove(font))) { + delete old; + } + unicodeToUnicodes->add(font->copy(), file->copy()); +} + void GlobalParams::parseUnicodeMap(GList *tokens, GString *fileName, int line) { GString *encodingName, *name, *old; @@ -697,17 +784,17 @@ void GlobalParams::parseFontRastControl(char *cmdName, FontRastControl *val, } } -void GlobalParams::parseURLCommand(GList *tokens, GString *fileName, - int line) { +void GlobalParams::parseCommand(char *cmdName, GString **val, + GList *tokens, GString *fileName, int line) { if (tokens->getLength() != 2) { - error(-1, "Bad 'urlCommand' config file command (%s:%d)", - fileName->getCString(), line); + error(-1, "Bad '%s' config file command (%s:%d)", + cmdName, fileName->getCString(), line); return; } - if (urlCommand) { - delete urlCommand; + if (*val) { + delete *val; } - urlCommand = ((GString *)tokens->get(1))->copy(); + *val = ((GString *)tokens->get(1))->copy(); } void GlobalParams::parseYesNo(char *cmdName, GBool *flag, @@ -741,6 +828,7 @@ GlobalParams::~GlobalParams() { delete nameToUnicode; deleteGHash(cidToUnicodes, GString); + deleteGHash(unicodeToUnicodes, GString); deleteGHash(residentUnicodeMaps, UnicodeMap); deleteGHash(unicodeMaps, GString); deleteGList(toUnicodeDirs, GString); @@ -759,6 +847,9 @@ GlobalParams::~GlobalParams() { if (urlCommand) { delete urlCommand; } + if (movieCommand) { + delete movieCommand; + } cMapDirs->startIter(&iter); while (cMapDirs->getNext(&iter, &key, (void **)&list)) { @@ -767,8 +858,15 @@ GlobalParams::~GlobalParams() { delete cMapDirs; delete cidToUnicodeCache; + delete unicodeToUnicodeCache; delete unicodeMapCache; delete cMapCache; + +#if MULTITHREADED + gDestroyMutex(&mutex); + gDestroyMutex(&unicodeMapCacheMutex); + gDestroyMutex(&cMapCacheMutex); +#endif } //------------------------------------------------------------------------ @@ -776,33 +874,39 @@ GlobalParams::~GlobalParams() { //------------------------------------------------------------------------ CharCode GlobalParams::getMacRomanCharCode(char *charName) { + // no need to lock - macRomanReverseMap is constant return macRomanReverseMap->lookup(charName); } Unicode GlobalParams::mapNameToUnicode(char *charName) { + // no need to lock - nameToUnicode is constant return nameToUnicode->lookup(charName); } -FILE *GlobalParams::getCIDToUnicodeFile(GString *collection) { - GString *fileName; +UnicodeMap *GlobalParams::getResidentUnicodeMap(GString *encodingName) { + UnicodeMap *map; - if (!(fileName = (GString *)cidToUnicodes->lookup(collection))) { - return NULL; + lockGlobalParams; + map = (UnicodeMap *)residentUnicodeMaps->lookup(encodingName); + unlockGlobalParams; + if (map) { + map->incRefCnt(); } - return fopen(fileName->getCString(), "r"); -} - -UnicodeMap *GlobalParams::getResidentUnicodeMap(GString *encodingName) { - return (UnicodeMap *)residentUnicodeMaps->lookup(encodingName); + return map; } FILE *GlobalParams::getUnicodeMapFile(GString *encodingName) { GString *fileName; + FILE *f; - if (!(fileName = (GString *)unicodeMaps->lookup(encodingName))) { - return NULL; + lockGlobalParams; + if ((fileName = (GString *)unicodeMaps->lookup(encodingName))) { + f = fopen(fileName->getCString(), "r"); + } else { + f = NULL; } - return fopen(fileName->getCString(), "r"); + unlockGlobalParams; + return f; } FILE *GlobalParams::findCMapFile(GString *collection, GString *cMapName) { @@ -812,7 +916,9 @@ FILE *GlobalParams::findCMapFile(GString *collection, GString *cMapName) { FILE *f; int i; + lockGlobalParams; if (!(list = (GList *)cMapDirs->lookup(collection))) { + unlockGlobalParams; return NULL; } for (i = 0; i < list->getLength(); ++i) { @@ -821,9 +927,11 @@ FILE *GlobalParams::findCMapFile(GString *collection, GString *cMapName) { f = fopen(fileName->getCString(), "r"); delete fileName; if (f) { + unlockGlobalParams; return f; } } + unlockGlobalParams; return NULL; } @@ -832,35 +940,95 @@ FILE *GlobalParams::findToUnicodeFile(GString *name) { FILE *f; int i; + lockGlobalParams; for (i = 0; i < toUnicodeDirs->getLength(); ++i) { dir = (GString *)toUnicodeDirs->get(i); fileName = appendToPath(dir->copy(), name->getCString()); f = fopen(fileName->getCString(), "r"); delete fileName; if (f) { + unlockGlobalParams; return f; } } + unlockGlobalParams; return NULL; } DisplayFontParam *GlobalParams::getDisplayFont(GString *fontName) { - return (DisplayFontParam *)displayFonts->lookup(fontName); + DisplayFontParam *dfp; + + lockGlobalParams; + dfp = (DisplayFontParam *)displayFonts->lookup(fontName); + unlockGlobalParams; + return dfp; } DisplayFontParam *GlobalParams::getDisplayCIDFont(GString *fontName, GString *collection) { DisplayFontParam *dfp; + lockGlobalParams; if (!fontName || !(dfp = (DisplayFontParam *)displayNamedCIDFonts->lookup(fontName))) { dfp = (DisplayFontParam *)displayCIDFonts->lookup(collection); } + unlockGlobalParams; return dfp; } +GString *GlobalParams::getPSFile() { + GString *s; + + lockGlobalParams; + s = psFile ? psFile->copy() : (GString *)NULL; + unlockGlobalParams; + return s; +} + +int GlobalParams::getPSPaperWidth() { + int w; + + lockGlobalParams; + w = psPaperWidth; + unlockGlobalParams; + return w; +} + +int GlobalParams::getPSPaperHeight() { + int h; + + lockGlobalParams; + h = psPaperHeight; + unlockGlobalParams; + return h; +} + +GBool GlobalParams::getPSDuplex() { + GBool d; + + lockGlobalParams; + d = psDuplex; + unlockGlobalParams; + return d; +} + +PSLevel GlobalParams::getPSLevel() { + PSLevel level; + + lockGlobalParams; + level = psLevel; + unlockGlobalParams; + return level; +} + PSFontParam *GlobalParams::getPSFont(GString *fontName) { - return (PSFontParam *)psFonts->lookup(fontName); + PSFontParam *p; + + lockGlobalParams; + p = (PSFontParam *)psFonts->lookup(fontName); + unlockGlobalParams; + return p; } PSFontParam *GlobalParams::getPSFont16(GString *fontName, @@ -868,6 +1036,7 @@ PSFontParam *GlobalParams::getPSFont16(GString *fontName, PSFontParam *p; int i; + lockGlobalParams; p = NULL; if (fontName) { for (i = 0; i < psNamedFonts16->getLength(); ++i) { @@ -889,74 +1058,278 @@ PSFontParam *GlobalParams::getPSFont16(GString *fontName, p = NULL; } } + unlockGlobalParams; return p; } -GString *GlobalParams::findFontFile(GString *fontName, - char *ext1, char *ext2) { +GBool GlobalParams::getPSEmbedType1() { + GBool e; + + lockGlobalParams; + e = psEmbedType1; + unlockGlobalParams; + return e; +} + +GBool GlobalParams::getPSEmbedTrueType() { + GBool e; + + lockGlobalParams; + e = psEmbedTrueType; + unlockGlobalParams; + return e; +} + +GBool GlobalParams::getPSEmbedCIDPostScript() { + GBool e; + + lockGlobalParams; + e = psEmbedCIDPostScript; + unlockGlobalParams; + return e; +} + +GBool GlobalParams::getPSEmbedCIDTrueType() { + GBool e; + + lockGlobalParams; + e = psEmbedCIDTrueType; + unlockGlobalParams; + return e; +} + +GBool GlobalParams::getPSOPI() { + GBool opi; + + lockGlobalParams; + opi = psOPI; + unlockGlobalParams; + return opi; +} + +GBool GlobalParams::getPSASCIIHex() { + GBool ah; + + lockGlobalParams; + ah = psASCIIHex; + unlockGlobalParams; + return ah; +} + +GString *GlobalParams::getTextEncodingName() { + GString *s; + + lockGlobalParams; + s = textEncoding->copy(); + unlockGlobalParams; + return s; +} + +EndOfLineKind GlobalParams::getTextEOL() { + EndOfLineKind eol; + + lockGlobalParams; + eol = textEOL; + unlockGlobalParams; + return eol; +} + +GBool GlobalParams::getTextPageBreaks() { + GBool pageBreaks; + + lockGlobalParams; + pageBreaks = textPageBreaks; + unlockGlobalParams; + return pageBreaks; +} + +GBool GlobalParams::getTextKeepTinyChars() { + GBool tiny; + + lockGlobalParams; + tiny = textKeepTinyChars; + unlockGlobalParams; + return tiny; +} + +GString *GlobalParams::findFontFile(GString *fontName, char **exts) { GString *dir, *fileName; + char **ext; FILE *f; int i; + lockGlobalParams; for (i = 0; i < fontDirs->getLength(); ++i) { dir = (GString *)fontDirs->get(i); - if (ext1) { - fileName = appendToPath(dir->copy(), fontName->getCString()); - fileName->append(ext1); - if ((f = fopen(fileName->getCString(), "r"))) { - fclose(f); - return fileName; - } - delete fileName; - } - if (ext2) { + for (ext = exts; *ext; ++ext) { fileName = appendToPath(dir->copy(), fontName->getCString()); - fileName->append(ext2); - if ((f = fopen(fileName->getCString(), "r"))) { + fileName->append(*ext); + if ((f = fopen(fileName->getCString(), "rb"))) { fclose(f); + unlockGlobalParams; return fileName; } delete fileName; } } + unlockGlobalParams; return NULL; } +GString *GlobalParams::getInitialZoom() { + GString *s; + + lockGlobalParams; + s = initialZoom->copy(); + unlockGlobalParams; + return s; +} + +FontRastControl GlobalParams::getT1libControl() { + FontRastControl c; + + lockGlobalParams; + c = t1libControl; + unlockGlobalParams; + return c; +} + +FontRastControl GlobalParams::getFreeTypeControl() { + FontRastControl c; + + lockGlobalParams; + c = freetypeControl; + unlockGlobalParams; + return c; +} + +GBool GlobalParams::getMapNumericCharNames() { + GBool map; + + lockGlobalParams; + map = mapNumericCharNames; + unlockGlobalParams; + return map; +} + +GBool GlobalParams::getPrintCommands() { + GBool p; + + lockGlobalParams; + p = printCommands; + unlockGlobalParams; + return p; +} + +GBool GlobalParams::getErrQuiet() { + GBool q; + + lockGlobalParams; + q = errQuiet; + unlockGlobalParams; + return q; +} + CharCodeToUnicode *GlobalParams::getCIDToUnicode(GString *collection) { - return cidToUnicodeCache->getCIDToUnicode(collection); + GString *fileName; + CharCodeToUnicode *ctu; + + lockGlobalParams; + if (!(ctu = cidToUnicodeCache->getCharCodeToUnicode(collection))) { + if ((fileName = (GString *)cidToUnicodes->lookup(collection)) && + (ctu = CharCodeToUnicode::parseCIDToUnicode(fileName, collection))) { + cidToUnicodeCache->add(ctu); + } + } + unlockGlobalParams; + return ctu; +} + +CharCodeToUnicode *GlobalParams::getUnicodeToUnicode(GString *fontName) { + CharCodeToUnicode *ctu; + GHashIter *iter; + GString *fontPattern, *fileName; + + lockGlobalParams; + fileName = NULL; + unicodeToUnicodes->startIter(&iter); + while (unicodeToUnicodes->getNext(&iter, &fontPattern, (void **)&fileName)) { + if (strstr(fontName->getCString(), fontPattern->getCString())) { + unicodeToUnicodes->killIter(&iter); + break; + } + fileName = NULL; + } + if (fileName) { + if (!(ctu = unicodeToUnicodeCache->getCharCodeToUnicode(fileName))) { + if ((ctu = CharCodeToUnicode::parseUnicodeToUnicode(fileName))) { + unicodeToUnicodeCache->add(ctu); + } + } + } else { + ctu = NULL; + } + unlockGlobalParams; + return ctu; } UnicodeMap *GlobalParams::getUnicodeMap(GString *encodingName) { + return getUnicodeMap2(encodingName); +} + +UnicodeMap *GlobalParams::getUnicodeMap2(GString *encodingName) { UnicodeMap *map; - if ((map = getResidentUnicodeMap(encodingName))) { - map->incRefCnt(); - return map; + if (!(map = getResidentUnicodeMap(encodingName))) { + lockUnicodeMapCache; + map = unicodeMapCache->getUnicodeMap(encodingName); + unlockUnicodeMapCache; } - return unicodeMapCache->getUnicodeMap(encodingName); + return map; } CMap *GlobalParams::getCMap(GString *collection, GString *cMapName) { - return cMapCache->getCMap(collection, cMapName); + CMap *cMap; + + lockCMapCache; + cMap = cMapCache->getCMap(collection, cMapName); + unlockCMapCache; + return cMap; } UnicodeMap *GlobalParams::getTextEncoding() { - return getUnicodeMap(textEncoding); + return getUnicodeMap2(textEncoding); } //------------------------------------------------------------------------ // functions to set parameters //------------------------------------------------------------------------ +void GlobalParams::addDisplayFont(DisplayFontParam *param) { + DisplayFontParam *old; + + lockGlobalParams; + if ((old = (DisplayFontParam *)displayFonts->remove(param->name))) { + delete old; + } + displayFonts->add(param->name, param); + unlockGlobalParams; +} + void GlobalParams::setPSFile(char *file) { + lockGlobalParams; if (psFile) { delete psFile; } psFile = new GString(file); + unlockGlobalParams; } GBool GlobalParams::setPSPaperSize(char *size) { - if (!strcmp(size, "letter")) { + lockGlobalParams; + if (!strcmp(size, "match")) { + psPaperWidth = psPaperHeight = -1; + } else if (!strcmp(size, "letter")) { psPaperWidth = 612; psPaperHeight = 792; } else if (!strcmp(size, "legal")) { @@ -969,57 +1342,82 @@ GBool GlobalParams::setPSPaperSize(char *size) { psPaperWidth = 842; psPaperHeight = 1190; } else { + unlockGlobalParams; return gFalse; } + unlockGlobalParams; return gTrue; } void GlobalParams::setPSPaperWidth(int width) { + lockGlobalParams; psPaperWidth = width; + unlockGlobalParams; } void GlobalParams::setPSPaperHeight(int height) { + lockGlobalParams; psPaperHeight = height; + unlockGlobalParams; } void GlobalParams::setPSDuplex(GBool duplex) { + lockGlobalParams; psDuplex = duplex; + unlockGlobalParams; } void GlobalParams::setPSLevel(PSLevel level) { + lockGlobalParams; psLevel = level; + unlockGlobalParams; } void GlobalParams::setPSEmbedType1(GBool embed) { + lockGlobalParams; psEmbedType1 = embed; + unlockGlobalParams; } void GlobalParams::setPSEmbedTrueType(GBool embed) { + lockGlobalParams; psEmbedTrueType = embed; + unlockGlobalParams; } void GlobalParams::setPSEmbedCIDPostScript(GBool embed) { + lockGlobalParams; psEmbedCIDPostScript = embed; + unlockGlobalParams; } void GlobalParams::setPSEmbedCIDTrueType(GBool embed) { + lockGlobalParams; psEmbedCIDTrueType = embed; + unlockGlobalParams; } void GlobalParams::setPSOPI(GBool opi) { + lockGlobalParams; psOPI = opi; + unlockGlobalParams; } void GlobalParams::setPSASCIIHex(GBool hex) { + lockGlobalParams; psASCIIHex = hex; + unlockGlobalParams; } void GlobalParams::setTextEncoding(char *encodingName) { + lockGlobalParams; delete textEncoding; textEncoding = new GString(encodingName); + unlockGlobalParams; } GBool GlobalParams::setTextEOL(char *s) { + lockGlobalParams; if (!strcmp(s, "unix")) { textEOL = eolUnix; } else if (!strcmp(s, "dos")) { @@ -1027,25 +1425,52 @@ GBool GlobalParams::setTextEOL(char *s) { } else if (!strcmp(s, "mac")) { textEOL = eolMac; } else { + unlockGlobalParams; return gFalse; } + unlockGlobalParams; return gTrue; } +void GlobalParams::setTextPageBreaks(GBool pageBreaks) { + lockGlobalParams; + textPageBreaks = pageBreaks; + unlockGlobalParams; +} + +void GlobalParams::setTextKeepTinyChars(GBool keep) { + lockGlobalParams; + textKeepTinyChars = keep; + unlockGlobalParams; +} + void GlobalParams::setInitialZoom(char *s) { + lockGlobalParams; delete initialZoom; initialZoom = new GString(s); + unlockGlobalParams; } GBool GlobalParams::setT1libControl(char *s) { - return setFontRastControl(&t1libControl, s); + GBool ok; + + lockGlobalParams; + ok = setFontRastControl(&t1libControl, s); + unlockGlobalParams; + return ok; } GBool GlobalParams::setFreeTypeControl(char *s) { - return setFontRastControl(&freetypeControl, s); + GBool ok; + + lockGlobalParams; + ok = setFontRastControl(&freetypeControl, s); + unlockGlobalParams; + return ok; } GBool GlobalParams::setFontRastControl(FontRastControl *val, char *s) { + lockGlobalParams; if (!strcmp(s, "none")) { *val = fontRastNone; } else if (!strcmp(s, "plain")) { @@ -1055,11 +1480,27 @@ GBool GlobalParams::setFontRastControl(FontRastControl *val, char *s) { } else if (!strcmp(s, "high")) { *val = fontRastAAHigh; } else { + unlockGlobalParams; return gFalse; } + unlockGlobalParams; return gTrue; } +void GlobalParams::setMapNumericCharNames(GBool map) { + lockGlobalParams; + mapNumericCharNames = map; + unlockGlobalParams; +} + +void GlobalParams::setPrintCommands(GBool printCommandsA) { + lockGlobalParams; + printCommands = printCommandsA; + unlockGlobalParams; +} + void GlobalParams::setErrQuiet(GBool errQuietA) { + lockGlobalParams; errQuiet = errQuietA; + unlockGlobalParams; }