poppler/GlobalParams.cc | 27 ++++++++++++++++++++------- poppler/GlobalParams.h | 5 ++++- 2 files changed, 24 insertions(+), 8 deletions(-)
New commits: commit 869584a84eed507775ff1c3183fe484c14b6f77b Author: Jonathan Kew <[email protected]> Date: Sat Jan 10 18:28:47 2009 +0100 Add the possibility of setting the datadir on runtime diff --git a/poppler/GlobalParams.cc b/poppler/GlobalParams.cc index ee7bb12..9c42f36 100644 --- a/poppler/GlobalParams.cc +++ b/poppler/GlobalParams.cc @@ -18,7 +18,7 @@ // Copyright (C) 2006 Takashi Iwai <[email protected]> // Copyright (C) 2006 Ed Catmur <[email protected]> // Copyright (C) 2007 Krzysztof Kowalczyk <[email protected]> -// Copyright (C) 2007 Jonathan Kew <[email protected]> +// Copyright (C) 2007, 2009 Jonathan Kew <[email protected]> // // To see a description of the changes please see the Changelog file that // came with your tarball or type make ChangeLog if you are building from git @@ -548,7 +548,9 @@ Plugin::~Plugin() { // parsing //------------------------------------------------------------------------ -GlobalParams::GlobalParams() { +GlobalParams::GlobalParams(const char *customPopplerDataDir) + : popplerDataDir(customPopplerDataDir) +{ UnicodeMap *map; int i; @@ -673,8 +675,14 @@ GlobalParams::GlobalParams() { void GlobalParams::scanEncodingDirs() { GDir *dir; GDirEntry *entry; - - dir = new GDir(POPPLER_DATADIR "/nameToUnicode", gTrue); + const char *dataRoot = popplerDataDir ? popplerDataDir : POPPLER_DATADIR; + + // allocate buffer large enough to append "/nameToUnicode" + size_t bufSize = strlen(dataRoot) + strlen("/nameToUnicode") + 1; + char *dataPathBuffer = new char[bufSize]; + + snprintf(dataPathBuffer, bufSize, "%s/nameToUnicode", dataRoot); + dir = new GDir(dataPathBuffer, gTrue); while (entry = dir->getNextEntry(), entry != NULL) { if (!entry->isDir()) { parseNameToUnicode(entry->getFullPath()); @@ -683,27 +691,32 @@ void GlobalParams::scanEncodingDirs() { } delete dir; - dir = new GDir(POPPLER_DATADIR "/cidToUnicode", gFalse); + snprintf(dataPathBuffer, bufSize, "%s/cidToUnicode", dataRoot); + dir = new GDir(dataPathBuffer, gFalse); while (entry = dir->getNextEntry(), entry != NULL) { addCIDToUnicode(entry->getName(), entry->getFullPath()); delete entry; } delete dir; - dir = new GDir(POPPLER_DATADIR "/unicodeMap", gFalse); + snprintf(dataPathBuffer, bufSize, "%s/unicodeMap", dataRoot); + dir = new GDir(dataPathBuffer, gFalse); while (entry = dir->getNextEntry(), entry != NULL) { addUnicodeMap(entry->getName(), entry->getFullPath()); delete entry; } delete dir; - dir = new GDir(POPPLER_DATADIR "/cMap", gFalse); + snprintf(dataPathBuffer, bufSize, "%s/cMap", dataRoot); + dir = new GDir(dataPathBuffer, gFalse); while (entry = dir->getNextEntry(), entry != NULL) { addCMapDir(entry->getName(), entry->getFullPath()); toUnicodeDirs->append(entry->getFullPath()->copy()); delete entry; } delete dir; + + delete[] dataPathBuffer; } void GlobalParams::parseNameToUnicode(GooString *name) { diff --git a/poppler/GlobalParams.h b/poppler/GlobalParams.h index 80c30f5..a0e4ff0 100644 --- a/poppler/GlobalParams.h +++ b/poppler/GlobalParams.h @@ -18,6 +18,7 @@ // Copyright (C) 2006 Takashi Iwai <[email protected]> // Copyright (C) 2006 Kristian Høgsberg <[email protected]> // Copyright (C) 2007 Krzysztof Kowalczyk <[email protected]> +// Copyright (C) 2009 Jonathan Kew <[email protected]> // // To see a description of the changes please see the Changelog file that // came with your tarball or type make ChangeLog if you are building from git @@ -159,7 +160,7 @@ public: // Initialize the global parameters by attempting to read a config // file. - GlobalParams(); + GlobalParams(const char *customPopplerDataDir = NULL); ~GlobalParams(); @@ -359,6 +360,8 @@ private: GooMutex unicodeMapCacheMutex; GooMutex cMapCacheMutex; #endif + + const char *popplerDataDir; }; #endif
_______________________________________________ poppler mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/poppler
