author | sandman <sandman> | 2002-05-23 23:51:52 (UTC) |
---|---|---|
committer | sandman <sandman> | 2002-05-23 23:51:52 (UTC) |
commit | 2f3bb7b07f833273d966d41813e68bfe8b9d8d76 (patch) (side-by-side diff) | |
tree | 00beb1bd9e7f4ba79e22334a0d258269b28f4564 /noncore/unsupported/qpdf/xpdf/GlobalParams.cc | |
parent | 6e82b45dd416ceeba78765717b700e853c96a137 (diff) | |
download | opie-2f3bb7b07f833273d966d41813e68bfe8b9d8d76.zip opie-2f3bb7b07f833273d966d41813e68bfe8b9d8d76.tar.gz opie-2f3bb7b07f833273d966d41813e68bfe8b9d8d76.tar.bz2 |
Port to xpdf 1.01
Diffstat (limited to 'noncore/unsupported/qpdf/xpdf/GlobalParams.cc') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/unsupported/qpdf/xpdf/GlobalParams.cc | 229 |
1 files changed, 189 insertions, 40 deletions
diff --git a/noncore/unsupported/qpdf/xpdf/GlobalParams.cc b/noncore/unsupported/qpdf/xpdf/GlobalParams.cc index 8be58a3..0bc908e 100644 --- a/noncore/unsupported/qpdf/xpdf/GlobalParams.cc +++ b/noncore/unsupported/qpdf/xpdf/GlobalParams.cc @@ -3,5 +3,5 @@ // GlobalParams.cc // -// Copyright 2001 Derek B. Noonburg +// Copyright 2001-2002 Glyph & Cog, LLC // //======================================================================== @@ -97,7 +97,10 @@ DisplayFontParam::~DisplayFontParam() { //------------------------------------------------------------------------ -PSFontParam::PSFontParam(GString *pdfFontNameA, GString *psFontNameA) { +PSFontParam::PSFontParam(GString *pdfFontNameA, int wModeA, + GString *psFontNameA, GString *encodingA) { pdfFontName = pdfFontNameA; + wMode = wModeA; psFontName = psFontNameA; + encoding = encodingA; } @@ -105,4 +108,7 @@ PSFontParam::~PSFontParam() { delete pdfFontName; delete psFontName; + if (encoding) { + delete encoding; + } } @@ -116,15 +122,12 @@ GlobalParams::GlobalParams(char *cfgFileName) { GString *fileName; FILE *f; - char buf[512]; - int line; - GList *tokens; - GString *cmd; - char *p1, *p2; int i; initBuiltinFontTables(); + // scan the encoding in reverse because we want the lowest-numbered + // index for each char name ('space' is encoded twice) macRomanReverseMap = new NameToCharCode(); - for (i = 0; i < 256; ++i) { + for (i = 255; i >= 0; --i) { if (macRomanEncoding[i]) { macRomanReverseMap->add(macRomanEncoding[i], (CharCode)i); @@ -140,4 +143,5 @@ GlobalParams::GlobalParams(char *cfgFileName) { displayFonts = new GHash(); displayCIDFonts = new GHash(); + displayNamedCIDFonts = new GHash(); #if HAVE_PAPER_H const struct paper *paperType; @@ -155,7 +159,12 @@ GlobalParams::GlobalParams(char *cfgFileName) { psFile = NULL; psFonts = new GHash(); + psNamedFonts16 = new GList(); + psFonts16 = new GList(); psEmbedType1 = gTrue; psEmbedTrueType = gTrue; + psEmbedCIDPostScript = gTrue; + psEmbedCIDTrueType = gTrue; psOPI = gFalse; + psASCIIHex = gFalse; textEncoding = new GString("Latin1"); #if defined(WIN32) @@ -167,4 +176,5 @@ GlobalParams::GlobalParams(char *cfgFileName) { #endif fontDirs = new GList(); + initialZoom = new GString("1"); t1libControl = fontRastAALow; freetypeControl = fontRastAALow; @@ -194,4 +204,6 @@ GlobalParams::GlobalParams(char *cfgFileName) { map = new UnicodeMap("UTF-8", &mapUTF8); residentUnicodeMaps->add(map->getEncodingName(), map); + map = new UnicodeMap("UCS-2", &mapUCS2); + residentUnicodeMaps->add(map->getEncodingName(), map); // default displayFonts table @@ -220,4 +232,5 @@ GlobalParams::GlobalParams(char *cfgFileName) { if (!f) { #if defined(WIN32) && !defined(__CYGWIN32__) + char buf[512]; i = GetModuleFileName(NULL, buf, sizeof(buf)); if (i <= 0 || i >= sizeof(buf)) { @@ -235,4 +248,17 @@ GlobalParams::GlobalParams(char *cfgFileName) { } if (f) { + parseFile(fileName, f); + delete fileName; + } +} + +void GlobalParams::parseFile(GString *fileName, FILE *f) { + int line; + GList *tokens; + GString *cmd, *incFile; + char *p1, *p2; + char buf[512]; + FILE *f2; + line = 1; while (fgets(buf, sizeof(buf) - 1, f)) { @@ -259,5 +285,19 @@ GlobalParams::GlobalParams(char *cfgFileName) { ((GString *)tokens->get(0))->getChar(0) != '#') { cmd = (GString *)tokens->get(0); - if (!cmd->cmp("nameToUnicode")) { + if (!cmd->cmp("include")) { + if (tokens->getLength() == 2) { + incFile = (GString *)tokens->get(1); + if ((f2 = fopen(incFile->getCString(), "r"))) { + parseFile(incFile, f2); + fclose(f2); + } else { + error(-1, "Couldn't find included config file: '%s' (%s:%d)", + incFile->getCString(), fileName->getCString(), line); + } + } else { + error(-1, "Bad 'include' config file command (%s:%d)", + fileName->getCString(), line); + } + } else if (!cmd->cmp("nameToUnicode")) { parseNameToUnicode(tokens, fileName, line); } else if (!cmd->cmp("cidToUnicode")) { @@ -270,15 +310,24 @@ GlobalParams::GlobalParams(char *cfgFileName) { parseToUnicodeDir(tokens, fileName, line); } else if (!cmd->cmp("displayFontX")) { - parseDisplayFont(tokens, gFalse, displayFontX, fileName, line); + parseDisplayFont(tokens, displayFonts, displayFontX, fileName, line); } else if (!cmd->cmp("displayFontT1")) { - parseDisplayFont(tokens, gFalse, displayFontT1, fileName, line); + parseDisplayFont(tokens, displayFonts, displayFontT1, fileName, line); } else if (!cmd->cmp("displayFontTT")) { - parseDisplayFont(tokens, gFalse, displayFontTT, fileName, line); + parseDisplayFont(tokens, displayFonts, displayFontTT, fileName, line); } else if (!cmd->cmp("displayCIDFontX")) { - parseDisplayFont(tokens, gTrue, displayFontX, fileName, line); + parseDisplayFont(tokens, displayCIDFonts, + displayFontX, fileName, line); + } else if (!cmd->cmp("displayNamedCIDFontX")) { + parseDisplayFont(tokens, displayNamedCIDFonts, + displayFontX, fileName, line); } else if (!cmd->cmp("psFile")) { parsePSFile(tokens, fileName, line); } else if (!cmd->cmp("psFont")) { parsePSFont(tokens, fileName, line); + } else if (!cmd->cmp("psNamedFont16")) { + parsePSFont16("psNamedFont16", psNamedFonts16, + tokens, fileName, line); + } else if (!cmd->cmp("psFont16")) { + parsePSFont16("psFont16", psFonts16, tokens, fileName, line); } else if (!cmd->cmp("psPaperSize")) { parsePSPaperSize(tokens, fileName, line); @@ -287,11 +336,19 @@ GlobalParams::GlobalParams(char *cfgFileName) { } else if (!cmd->cmp("psLevel")) { parsePSLevel(tokens, fileName, line); - } else if (!cmd->cmp("psEmbedType1")) { + } else if (!cmd->cmp("psEmbedType1Fonts")) { parseYesNo("psEmbedType1", &psEmbedType1, tokens, fileName, line); - } else if (!cmd->cmp("psEmbedTrueType")) { + } else if (!cmd->cmp("psEmbedTrueTypeFonts")) { parseYesNo("psEmbedTrueType", &psEmbedTrueType, tokens, fileName, line); + } else if (!cmd->cmp("psEmbedCIDPostScriptFonts")) { + parseYesNo("psEmbedCIDPostScript", &psEmbedCIDPostScript, + tokens, fileName, line); + } else if (!cmd->cmp("psEmbedCIDTrueTypeFonts")) { + parseYesNo("psEmbedCIDTrueType", &psEmbedCIDTrueType, + tokens, fileName, line); } else if (!cmd->cmp("psOPI")) { parseYesNo("psOPI", &psOPI, tokens, fileName, line); + } else if (!cmd->cmp("psASCIIHex")) { + parseYesNo("psASCIIHex", &psASCIIHex, tokens, fileName, line); } else if (!cmd->cmp("textEncoding")) { parseTextEncoding(tokens, fileName, line); @@ -300,4 +357,6 @@ GlobalParams::GlobalParams(char *cfgFileName) { } else if (!cmd->cmp("fontDir")) { parseFontDir(tokens, fileName, line); + } else if (!cmd->cmp("initialZoom")) { + parseInitialZoom(tokens, fileName, line); } else if (!cmd->cmp("t1libControl")) { parseFontRastControl("t1libControl", &t1libControl, @@ -325,7 +384,4 @@ GlobalParams::GlobalParams(char *cfgFileName) { ++line; } - - delete fileName; - } } @@ -427,5 +483,5 @@ void GlobalParams::parseToUnicodeDir(GList *tokens, GString *fileName, } -void GlobalParams::parseDisplayFont(GList *tokens, GBool isCID, +void GlobalParams::parseDisplayFont(GList *tokens, GHash *fontHash, DisplayFontParamKind kind, GString *fileName, int line) { @@ -459,15 +515,8 @@ void GlobalParams::parseDisplayFont(GList *tokens, GBool isCID, } - if (isCID) { - if ((old = (DisplayFontParam *)displayCIDFonts->remove(param->name))) { - delete old; - } - displayCIDFonts->add(param->name, param); - } else { - if ((old = (DisplayFontParam *)displayFonts->remove(param->name))) { + if ((old = (DisplayFontParam *)fontHash->remove(param->name))) { delete old; } - displayFonts->add(param->name, param); - } + fontHash->add(param->name, param); return; @@ -475,5 +524,5 @@ void GlobalParams::parseDisplayFont(GList *tokens, GBool isCID, delete param; err1: - error(-1, "Bad 'displayFont...' config file command (%s:%d)", + error(-1, "Bad 'display*Font*' config file command (%s:%d)", fileName->getCString(), line); } @@ -517,4 +566,8 @@ void GlobalParams::parsePSLevel(GList *tokens, GString *fileName, int line) { } else if (!tok->cmp("level2sep")) { psLevel = psLevel2Sep; + } else if (!tok->cmp("level3")) { + psLevel = psLevel3; + } else if (!tok->cmp("level3Sep")) { + psLevel = psLevel3Sep; } else { error(-1, "Bad 'psLevel' config file command (%s:%d)", @@ -543,9 +596,37 @@ void GlobalParams::parsePSFont(GList *tokens, GString *fileName, int line) { return; } - param = new PSFontParam(((GString *)tokens->get(1))->copy(), - ((GString *)tokens->get(2))->copy()); + param = new PSFontParam(((GString *)tokens->get(1))->copy(), 0, + ((GString *)tokens->get(2))->copy(), NULL); psFonts->add(param->pdfFontName, param); } +void GlobalParams::parsePSFont16(char *cmdName, GList *fontList, + GList *tokens, GString *fileName, int line) { + PSFontParam *param; + int wMode; + GString *tok; + + if (tokens->getLength() != 5) { + error(-1, "Bad '%s' config file command (%s:%d)", + cmdName, fileName->getCString(), line); + return; + } + tok = (GString *)tokens->get(2); + if (!tok->cmp("H")) { + wMode = 0; + } else if (!tok->cmp("V")) { + wMode = 1; + } else { + error(-1, "Bad '%s' config file command (%s:%d)", + cmdName, fileName->getCString(), line); + return; + } + param = new PSFontParam(((GString *)tokens->get(1))->copy(), + wMode, + ((GString *)tokens->get(3))->copy(), + ((GString *)tokens->get(4))->copy()); + fontList->append(param); +} + void GlobalParams::parseTextEncoding(GList *tokens, GString *fileName, int line) { @@ -589,15 +670,13 @@ void GlobalParams::parseFontDir(GList *tokens, GString *fileName, int line) { } -void GlobalParams::parseURLCommand(GList *tokens, GString *fileName, - int line) { +void GlobalParams::parseInitialZoom(GList *tokens, + GString *fileName, int line) { if (tokens->getLength() != 2) { - error(-1, "Bad 'urlCommand' config file command (%s:%d)", + error(-1, "Bad 'initialZoom' config file command (%s:%d)", fileName->getCString(), line); return; } - if (urlCommand) { - delete urlCommand; - } - urlCommand = ((GString *)tokens->get(1))->copy(); + delete initialZoom; + initialZoom = ((GString *)tokens->get(1))->copy(); } @@ -619,4 +698,17 @@ void GlobalParams::parseFontRastControl(char *cmdName, FontRastControl *val, } +void GlobalParams::parseURLCommand(GList *tokens, GString *fileName, + int line) { + if (tokens->getLength() != 2) { + error(-1, "Bad 'urlCommand' config file command (%s:%d)", + fileName->getCString(), line); + return; + } + if (urlCommand) { + delete urlCommand; + } + urlCommand = ((GString *)tokens->get(1))->copy(); +} + void GlobalParams::parseYesNo(char *cmdName, GBool *flag, GList *tokens, GString *fileName, int line) { @@ -655,10 +747,14 @@ GlobalParams::~GlobalParams() { deleteGHash(displayFonts, DisplayFontParam); deleteGHash(displayCIDFonts, DisplayFontParam); + deleteGHash(displayNamedCIDFonts, DisplayFontParam); if (psFile) { delete psFile; } deleteGHash(psFonts, PSFontParam); + deleteGList(psNamedFonts16, PSFontParam); + deleteGList(psFonts16, PSFontParam); delete textEncoding; deleteGList(fontDirs, GString); + delete initialZoom; if (urlCommand) { delete urlCommand; @@ -753,6 +849,13 @@ DisplayFontParam *GlobalParams::getDisplayFont(GString *fontName) { } -DisplayFontParam *GlobalParams::getDisplayCIDFont(GString *collection) { - return (DisplayFontParam *)displayCIDFonts->lookup(collection); +DisplayFontParam *GlobalParams::getDisplayCIDFont(GString *fontName, + GString *collection) { + DisplayFontParam *dfp; + + if (!fontName || + !(dfp = (DisplayFontParam *)displayNamedCIDFonts->lookup(fontName))) { + dfp = (DisplayFontParam *)displayCIDFonts->lookup(collection); + } + return dfp; } @@ -761,4 +864,33 @@ PSFontParam *GlobalParams::getPSFont(GString *fontName) { } +PSFontParam *GlobalParams::getPSFont16(GString *fontName, + GString *collection, int wMode) { + PSFontParam *p; + int i; + + p = NULL; + if (fontName) { + for (i = 0; i < psNamedFonts16->getLength(); ++i) { + p = (PSFontParam *)psNamedFonts16->get(i); + if (!p->pdfFontName->cmp(fontName) && + p->wMode == wMode) { + break; + } + p = NULL; + } + } + if (!p && collection) { + for (i = 0; i < psFonts16->getLength(); ++i) { + p = (PSFontParam *)psFonts16->get(i); + if (!p->pdfFontName->cmp(collection) && + p->wMode == wMode) { + break; + } + p = NULL; + } + } + return p; +} + GString *GlobalParams::findFontFile(GString *fontName, char *ext1, char *ext2) { @@ -867,8 +999,20 @@ void GlobalParams::setPSEmbedTrueType(GBool embed) { } +void GlobalParams::setPSEmbedCIDPostScript(GBool embed) { + psEmbedCIDPostScript = embed; +} + +void GlobalParams::setPSEmbedCIDTrueType(GBool embed) { + psEmbedCIDTrueType = embed; +} + void GlobalParams::setPSOPI(GBool opi) { psOPI = opi; } +void GlobalParams::setPSASCIIHex(GBool hex) { + psASCIIHex = hex; +} + void GlobalParams::setTextEncoding(char *encodingName) { delete textEncoding; @@ -889,4 +1033,9 @@ GBool GlobalParams::setTextEOL(char *s) { } +void GlobalParams::setInitialZoom(char *s) { + delete initialZoom; + initialZoom = new GString(s); +} + GBool GlobalParams::setT1libControl(char *s) { return setFontRastControl(&t1libControl, s); |