diff -ur pdf2swf/SWFOutputDev.cc pdf2swf/SWFOutputDev.cc --- pdf2swf/SWFOutputDev.cc Wed Oct 27 00:24:25 2004 +++ pdf2swf/SWFOutputDev.cc Sun Oct 31 11:52:27 2004 @@ -1952,14 +1952,14 @@ int l; FILE*fi = 0; - char* config_file = (char*)malloc(strlen(dir)+256); + char* config_file = (char*)malloc(strlen(dir) + 1 + sizeof("pdf2swfrc")); strcpy(config_file, dir); strcat(config_file, dirseparator()); - strcat(config_file, "add-to-xpdfrc"); + strcat(config_file, "pdf2swfrc"); - fi = fopen(config_file, "rb"); + fi = fopen(config_file, "r"); if(!fi) { - msg(" Could not open %s"); + msg(" Could not open %s", config_file); return; } globalParams->parseFile(new GString(config_file), fi); @@ -2005,7 +2005,7 @@ } closedir(dir); #else - msg(" No dirent.h- unable to add font dir %s"); + msg(" No dirent.h- unable to add font dir %s", dir); #endif } diff -ur pdf2swf/xpdf/GString.cc pdf2swf/xpdf/GString.cc --- pdf2swf/xpdf/GString.cc Sat Sep 18 05:05:29 2004 +++ pdf2swf/xpdf/GString.cc Sun Oct 31 11:15:53 2004 @@ -234,3 +234,105 @@ } return this; } + +int GString::indexOf(char c) { + int i; + + for (i = 0; i < length; i++) { + if (s[i] == c) { + return 0; + } + } + + return -1; +} + +int GString::indexOfAny(const char* c) { + int i, j; + char x = 0, y = 0xff; + + for (i = 0; c[i] != '\0'; i++) { + x |= c[i]; + y &= c[i]; + } + + x = ~x; + + switch (i) { + case 0: + for (i = 0; i < length; i++) { + if ((s[i] & x)) continue; + if ((s[i] & y) != y) continue; + + for (j = 0; c[j] != '\0'; j++) { + if (s[i] == c[j]) { + return i; + } + } + } + return -1; + + case 1: + for (i = 0; i < length; i++) { + if (s[i] == c[0]) { + return i; + } + } + break; + + case 2: + for (i = 0; i < length; i++) { + if (s[i] == c[0] || s[i] == c[1]) { + return i; + } + } + break; + } + + return -1; +} + +int GString::lastIndexOfAny(const char* c) { + int i, j; + char x = 0, y = 0xff; + + for (i = 0; c[i] != '\0'; i++) { + x |= c[i]; + y &= c[i]; + } + + x = ~x; + + switch (i) { + case 0: + for (i = length; --i >= 0;) { + if ((s[i] & x)) continue; + if ((s[i] & y) != y) continue; + + for (j = 0; c[j] != '\0'; j++) { + if (s[i] == c[j]) { + return i; + } + } + } + return -1; + + case 1: + for (i = length; --i >= 0;) { + if (s[i] == c[0]) { + return i; + } + } + break; + + case 2: + for (i = length; --i >= 0;) { + if (s[i] == c[0] || s[i] == c[1]) { + return i; + } + } + break; + } + + return -1; +} diff -ur pdf2swf/xpdf/GString.h pdf2swf/xpdf/GString.h --- pdf2swf/xpdf/GString.h Sat Sep 18 05:05:29 2004 +++ pdf2swf/xpdf/GString.h Sun Oct 31 11:19:28 2004 @@ -89,6 +89,12 @@ int cmp(const char *sA) { return strcmp(s, sA); } int cmpN(const char *sA, int n) { return strncmp(s, sA, n); } + int indexOf(char c); + int lastIndexOf(char c); + + int indexOfAny(const char* c); + int lastIndexOfAny(const char* c); + private: int length; diff -ur pdf2swf/xpdf/GlobalParams.cc pdf2swf/xpdf/GlobalParams.cc --- pdf2swf/xpdf/GlobalParams.cc Sun Oct 24 03:11:43 2004 +++ pdf2swf/xpdf/GlobalParams.cc Sun Oct 31 11:20:32 2004 @@ -512,7 +512,7 @@ void GlobalParams::parseCIDToUnicode(GList *tokens, GString *fileName, int line) { - GString *collection, *name, *old; + GString *collection, *name, *namedup, *old; if (tokens->getLength() != 3) { error(-1, "Bad 'cidToUnicode' config file command (%s:%d)", @@ -521,15 +521,26 @@ } collection = (GString *)tokens->get(1); name = (GString *)tokens->get(2); + if ((old = (GString *)cidToUnicodes->remove(collection))) { delete old; } - cidToUnicodes->add(collection->copy(), name->copy()); + + if (name->getChar(0) != '\\' && name->getChar(0) != '/') { + int pos = fileName->lastIndexOfAny("\\/"); + namedup = new GString(fileName, 0, (pos < 0 ? fileName->getLength(): pos)); + namedup->append('/'); + namedup->append(name); + } else { + namedup = name->copy(); + } + + cidToUnicodes->add(collection->copy(), namedup); } void GlobalParams::parseUnicodeToUnicode(GList *tokens, GString *fileName, int line) { - GString *font, *file, *old; + GString *font, *file, *filedup, *old; if (tokens->getLength() != 3) { error(-1, "Bad 'unicodeToUnicode' config file command (%s:%d)", @@ -541,12 +552,22 @@ if ((old = (GString *)unicodeToUnicodes->remove(font))) { delete old; } - unicodeToUnicodes->add(font->copy(), file->copy()); + + if (file->getChar(0) != '\\' && file->getChar(0) != '/') { + int pos = fileName->lastIndexOfAny("\\/"); + filedup = new GString(fileName, 0, (pos < 0 ? fileName->getLength(): pos)); + filedup->append('/'); + filedup->append(file); + } else { + filedup = file->copy(); + } + + unicodeToUnicodes->add(font->copy(), filedup); } void GlobalParams::parseUnicodeMap(GList *tokens, GString *fileName, int line) { - GString *encodingName, *name, *old; + GString *encodingName, *name, *namedup, *old; if (tokens->getLength() != 3) { error(-1, "Bad 'unicodeMap' config file command (%s:%d)", @@ -558,11 +579,21 @@ if ((old = (GString *)unicodeMaps->remove(encodingName))) { delete old; } - unicodeMaps->add(encodingName->copy(), name->copy()); + + if (name->getChar(0) != '\\' && name->getChar(0) != '/') { + int pos = fileName->lastIndexOfAny("\\/"); + namedup = new GString(fileName, 0, (pos < 0 ? fileName->getLength(): pos)); + namedup->append('/'); + namedup->append(name); + } else { + namedup = name->copy(); + } + + unicodeMaps->add(encodingName->copy(), namedup); } void GlobalParams::parseCMapDir(GList *tokens, GString *fileName, int line) { - GString *collection, *dir; + GString *collection, *dir, *dirdup; GList *list; if (tokens->getLength() != 3) { @@ -576,23 +607,48 @@ list = new GList(); cMapDirs->add(collection->copy(), list); } - list->append(dir->copy()); + + if (dir->getChar(0) != '\\' && dir->getChar(0) != '/') { + int pos = fileName->lastIndexOfAny("\\/"); + dirdup = new GString(fileName, 0, (pos < 0 ? fileName->getLength(): pos)); + dirdup->append('/'); + dirdup->append(dir); + } else { + dirdup = dir->copy(); + } + + list->append(dirdup); } void GlobalParams::parseToUnicodeDir(GList *tokens, GString *fileName, int line) { + GString *dir, *dirdup; + if (tokens->getLength() != 2) { error(-1, "Bad 'toUnicodeDir' config file command (%s:%d)", fileName->getCString(), line); return; } - toUnicodeDirs->append(((GString *)tokens->get(1))->copy()); + + dir = (GString *)tokens->get(1); + + if (dir->getChar(0) != '\\' && dir->getChar(0) != '/') { + int pos = fileName->lastIndexOfAny("\\/"); + dirdup = new GString(fileName, 0, (pos < 0 ? fileName->getLength(): pos)); + dirdup->append('/'); + dirdup->append(dir); + } else { + dirdup = dir->copy(); + } + + toUnicodeDirs->append(dirdup); } void GlobalParams::parseDisplayFont(GList *tokens, GHash *fontHash, DisplayFontParamKind kind, GString *fileName, int line) { DisplayFontParam *param, *old; + GString *file, *filedup = NULL; if (tokens->getLength() < 2) { goto err1; @@ -601,16 +657,29 @@ switch (kind) { case displayFontT1: - if (tokens->getLength() != 3) { - goto err2; - } - param->t1.fileName = ((GString *)tokens->get(2))->copy(); - break; case displayFontTT: if (tokens->getLength() != 3) { goto err2; } - param->tt.fileName = ((GString *)tokens->get(2))->copy(); + file = (GString *)tokens->get(2); + + if (file->getChar(0) != '\\' && file->getChar(0) != '/') { + int pos = fileName->lastIndexOfAny("\\/"); + filedup = new GString(fileName, 0, (pos < 0 ? fileName->getLength(): pos)); + filedup->append('/'); + filedup->append(file); + } else { + filedup = file->copy(); + } + + switch (kind) { + case displayFontT1: + param->t1.fileName = filedup; + break; + case displayFontTT: + param->tt.fileName = filedup; + break; + } break; }