📄 globalparams.cc
字号:
if (tokens->getLength() < 4) { error(-1, "Bad 'bind' config file command (%s:%d)", fileName->getCString(), line); return; } if (!parseKey((GString *)tokens->get(1), (GString *)tokens->get(2), &code, &mods, &context, "bind", tokens, fileName, line)) { return; } for (i = 0; i < keyBindings->getLength(); ++i) { binding = (KeyBinding *)keyBindings->get(i); if (binding->code == code && binding->mods == mods && binding->context == context) { delete (KeyBinding *)keyBindings->del(i); break; } } cmds = new GList(); for (i = 3; i < tokens->getLength(); ++i) { cmds->append(((GString *)tokens->get(i))->copy()); } keyBindings->append(new KeyBinding(code, mods, context, cmds));}void GlobalParams::parseUnbind(GList *tokens, GString *fileName, int line) { KeyBinding *binding; int code, mods, context, i; if (tokens->getLength() != 3) { error(-1, "Bad 'unbind' config file command (%s:%d)", fileName->getCString(), line); return; } if (!parseKey((GString *)tokens->get(1), (GString *)tokens->get(2), &code, &mods, &context, "unbind", tokens, fileName, line)) { return; } for (i = 0; i < keyBindings->getLength(); ++i) { binding = (KeyBinding *)keyBindings->get(i); if (binding->code == code && binding->mods == mods && binding->context == context) { delete (KeyBinding *)keyBindings->del(i); break; } }}GBool GlobalParams::parseKey(GString *modKeyStr, GString *contextStr, int *code, int *mods, int *context, char *cmdName, GList *tokens, GString *fileName, int line) { char *p0; *mods = xpdfKeyModNone; p0 = modKeyStr->getCString(); while (1) { if (!strncmp(p0, "shift-", 6)) { *mods |= xpdfKeyModShift; p0 += 6; } else if (!strncmp(p0, "ctrl-", 5)) { *mods |= xpdfKeyModCtrl; p0 += 5; } else if (!strncmp(p0, "alt-", 4)) { *mods |= xpdfKeyModAlt; p0 += 4; } else { break; } } if (!strcmp(p0, "space")) { *code = ' '; } else if (!strcmp(p0, "tab")) { *code = xpdfKeyCodeTab; } else if (!strcmp(p0, "return")) { *code = xpdfKeyCodeReturn; } else if (!strcmp(p0, "enter")) { *code = xpdfKeyCodeEnter; } else if (!strcmp(p0, "backspace")) { *code = xpdfKeyCodeBackspace; } else if (!strcmp(p0, "insert")) { *code = xpdfKeyCodeInsert; } else if (!strcmp(p0, "delete")) { *code = xpdfKeyCodeDelete; } else if (!strcmp(p0, "home")) { *code = xpdfKeyCodeHome; } else if (!strcmp(p0, "end")) { *code = xpdfKeyCodeEnd; } else if (!strcmp(p0, "pgup")) { *code = xpdfKeyCodePgUp; } else if (!strcmp(p0, "pgdn")) { *code = xpdfKeyCodePgDn; } else if (!strcmp(p0, "left")) { *code = xpdfKeyCodeLeft; } else if (!strcmp(p0, "right")) { *code = xpdfKeyCodeRight; } else if (!strcmp(p0, "up")) { *code = xpdfKeyCodeUp; } else if (!strcmp(p0, "down")) { *code = xpdfKeyCodeDown; } else if (p0[0] == 'f' && p0[1] >= '1' && p0[1] <= '9' && !p0[2]) { *code = xpdfKeyCodeF1 + (p0[1] - '1'); } else if (p0[0] == 'f' && ((p0[1] >= '1' && p0[1] <= '2' && p0[2] >= '0' && p0[2] <= '9') || (p0[1] == '3' && p0[2] >= '0' && p0[2] <= '5')) && !p0[3]) { *code = xpdfKeyCodeF1 + 10 * (p0[1] - '0') + (p0[2] - '0') - 1; } else if (!strncmp(p0, "mousePress", 10) && p0[10] >= '1' && p0[10] <= '7' && !p0[11]) { *code = xpdfKeyCodeMousePress1 + (p0[10] - '1'); } else if (!strncmp(p0, "mouseRelease", 12) && p0[12] >= '1' && p0[12] <= '7' && !p0[13]) { *code = xpdfKeyCodeMouseRelease1 + (p0[12] - '1'); } else if (*p0 >= 0x20 && *p0 <= 0x7e && !p0[1]) { *code = (int)*p0; } else { error(-1, "Bad key/modifier in '%s' config file command (%s:%d)", cmdName, fileName->getCString(), line); return gFalse; } p0 = contextStr->getCString(); if (!strcmp(p0, "any")) { *context = xpdfKeyContextAny; } else { *context = xpdfKeyContextAny; while (1) { if (!strncmp(p0, "fullScreen", 10)) { *context |= xpdfKeyContextFullScreen; p0 += 10; } else if (!strncmp(p0, "window", 6)) { *context |= xpdfKeyContextWindow; p0 += 6; } else if (!strncmp(p0, "continuous", 10)) { *context |= xpdfKeyContextContinuous; p0 += 10; } else if (!strncmp(p0, "singlePage", 10)) { *context |= xpdfKeyContextSinglePage; p0 += 10; } else if (!strncmp(p0, "overLink", 8)) { *context |= xpdfKeyContextOverLink; p0 += 8; } else if (!strncmp(p0, "offLink", 7)) { *context |= xpdfKeyContextOffLink; p0 += 7; } else if (!strncmp(p0, "outline", 7)) { *context |= xpdfKeyContextOutline; p0 += 7; } else if (!strncmp(p0, "mainWin", 7)) { *context |= xpdfKeyContextMainWin; p0 += 7; } else if (!strncmp(p0, "scrLockOn", 9)) { *context |= xpdfKeyContextScrLockOn; p0 += 9; } else if (!strncmp(p0, "scrLockOff", 10)) { *context |= xpdfKeyContextScrLockOff; p0 += 10; } else { error(-1, "Bad context in '%s' config file command (%s:%d)", cmdName, fileName->getCString(), line); return gFalse; } if (!*p0) { break; } if (*p0 != ',') { error(-1, "Bad context in '%s' config file command (%s:%d)", cmdName, fileName->getCString(), line); return gFalse; } ++p0; } } return gTrue;}void GlobalParams::parseCommand(char *cmdName, GString **val, GList *tokens, GString *fileName, int line) { if (tokens->getLength() != 2) { error(-1, "Bad '%s' config file command (%s:%d)", cmdName, fileName->getCString(), line); return; } if (*val) { delete *val; } *val = ((GString *)tokens->get(1))->copy();}void GlobalParams::parseYesNo(char *cmdName, GBool *flag, GList *tokens, GString *fileName, int line) { GString *tok; if (tokens->getLength() != 2) { error(-1, "Bad '%s' config file command (%s:%d)", cmdName, fileName->getCString(), line); return; } tok = (GString *)tokens->get(1); if (!parseYesNo2(tok->getCString(), flag)) { error(-1, "Bad '%s' config file command (%s:%d)", cmdName, fileName->getCString(), line); }}GBool GlobalParams::parseYesNo2(char *token, GBool *flag) { if (!strcmp(token, "yes")) { *flag = gTrue; } else if (!strcmp(token, "no")) { *flag = gFalse; } else { return gFalse; } return gTrue;}void GlobalParams::parseInteger(char *cmdName, int *val, GList *tokens, GString *fileName, int line) { GString *tok; int i; if (tokens->getLength() != 2) { error(-1, "Bad '%s' config file command (%s:%d)", cmdName, fileName->getCString(), line); return; } tok = (GString *)tokens->get(1); if (tok->getLength() == 0) { error(-1, "Bad '%s' config file command (%s:%d)", cmdName, fileName->getCString(), line); return; } if (tok->getChar(0) == '-') { i = 1; } else { i = 0; } for (; i < tok->getLength(); ++i) { if (tok->getChar(i) < '0' || tok->getChar(i) > '9') { error(-1, "Bad '%s' config file command (%s:%d)", cmdName, fileName->getCString(), line); return; } } *val = atoi(tok->getCString());}void GlobalParams::parseFloat(char *cmdName, double *val, GList *tokens, GString *fileName, int line) { GString *tok; int i; if (tokens->getLength() != 2) { error(-1, "Bad '%s' config file command (%s:%d)", cmdName, fileName->getCString(), line); return; } tok = (GString *)tokens->get(1); if (tok->getLength() == 0) { error(-1, "Bad '%s' config file command (%s:%d)", cmdName, fileName->getCString(), line); return; } if (tok->getChar(0) == '-') { i = 1; } else { i = 0; } for (; i < tok->getLength(); ++i) { if (!((tok->getChar(i) >= '0' && tok->getChar(i) <= '9') || tok->getChar(i) == '.')) { error(-1, "Bad '%s' config file command (%s:%d)", cmdName, fileName->getCString(), line); return; } } *val = atof(tok->getCString());}GlobalParams::~GlobalParams() { GHashIter *iter; GString *key; GList *list; freeBuiltinFontTables(); delete macRomanReverseMap; delete baseDir; delete nameToUnicode; deleteGHash(cidToUnicodes, GString); deleteGHash(unicodeToUnicodes, GString); deleteGHash(residentUnicodeMaps, UnicodeMap); deleteGHash(unicodeMaps, GString); deleteGList(toUnicodeDirs, GString); deleteGHash(displayFonts, DisplayFontParam); deleteGHash(displayCIDFonts, DisplayFontParam); deleteGHash(displayNamedCIDFonts, DisplayFontParam);#ifdef WIN32 if (winFontList) { delete winFontList; }#endif if (psFile) { delete psFile; } deleteGHash(psFonts, PSFontParam); deleteGList(psNamedFonts16, PSFontParam); deleteGList(psFonts16, PSFontParam); delete textEncoding; deleteGList(fontDirs, GString); delete initialZoom; if (urlCommand) { delete urlCommand; } if (movieCommand) { delete movieCommand; } deleteGList(keyBindings, KeyBinding); cMapDirs->startIter(&iter); while (cMapDirs->getNext(&iter, &key, (void **)&list)) { deleteGList(list, GString); } delete cMapDirs; delete cidToUnicodeCache; delete unicodeToUnicodeCache; delete unicodeMapCache; delete cMapCache;#ifdef ENABLE_PLUGINS delete securityHandlers; deleteGList(plugins, Plugin);#endif#if MULTITHREADED gDestroyMutex(&mutex); gDestroyMutex(&unicodeMapCacheMutex); gDestroyMutex(&cMapCacheMutex);#endif}//------------------------------------------------------------------------void GlobalParams::setBaseDir(char *dir) { delete baseDir; baseDir = new GString(dir);}void GlobalParams::setupBaseFonts(char *dir) { GString *fontName; GString *fileName;#ifdef WIN32 HMODULE shell32Lib; BOOL (__stdcall *SHGetSpecialFolderPathFunc)(HWND hwndOwner, LPTSTR lpszPath, int nFolder, BOOL fCreate); char winFontDir[MAX_PATH];#endif FILE *f; DisplayFontParamKind kind; DisplayFontParam *dfp; int i, j;#ifdef WIN32 // SHGetSpecialFolderPath isn't available in older versions of // shell32.dll (Win95 and WinNT4), so do a dynamic load winFontDir[0] = '\0'; if ((shell32Lib = LoadLibrary("shell32.dll"))) { if ((SHGetSpecialFolderPathFunc = (BOOL (__stdcall *)(HWND hwndOwner, LPTSTR lpszPath, int nFolder, BOOL fCreate)) GetProcAddress(shell32Lib, "SHGetSpecialFolderPathA"))) { if (!(*SHGetSpecialFolderPathFunc)(NULL, winFontDir, CSIDL_FONTS, FALSE)) { winFontDir[0] = '\0'; } } }#endif for (i = 0; displayFontTab[i].name; ++i) { fontName = new GString(displayFontTab[i].name); if (getDisplayFont(fontName)) { delete fontName; continue; } fileName = NULL; kind = displayFontT1; // make gcc happy if (dir) { fileName = appendToPath(new GString(dir), displayFontTab[i].t1FileName); kind = displayFontT1; if ((f = fopen(fileName->getCString(), "rb"))) { fclose(f); } else { delete fileName; fileName = NULL; } }#ifdef WIN32 if (!fileName && winFontDir[0] && displayFontTab[i].ttFileName) { fileName = appendToPath(new GString(winFontDir), displayFontTab[i].ttFileName); kind = displayFontTT; if ((f = fopen(fileName->getCString(), "rb"))) { fclose(f); } else { delete fileName; fileName = NULL; } } // SHGetSpecialFolderPath(CSIDL_FONTS) doesn't work on Win 2k Server // or Win2003 Server, or with older versions of shell32.dll, so check // the "standard" directories if (displayFontTab[i].ttFileName) { for (j = 0; !fileName && displayFontDirs[j]; ++j) { fileName = appendToPath(new GString(displayFontDirs[j]), displayFontTab[i].ttFileName); kind = displayFontTT; if ((f = fopen(fileName->getCString(), "rb"))) { fclose(f); } else { delete fileName; fileName = NULL; } } }#else for (j = 0; !fileName && displayFontDirs[j]; ++j) { fileName = appendToPath(new GString(displayFontDirs[j]), displayFontTab[i].t1FileName); kind = displayFontT1; if ((f = fopen(fileName->getCString(), "rb"))) { fclose(f); } else { delete fileName; fileName = NULL; } }#endif if (!fileName) { error(-1, "No display font for '%s'", displayFontTab[i].name); delete fontName; continue; } dfp = new DisplayFontParam(fontName, kind); dfp->t1.fileName = fileName; globalParams->addDisplayFont(dfp); }#ifdef WIN32 if (winFontDir[0]) { winFontList = new WinFontList(winFontDir); }#endif}//------------------------------------------------------------------------// accessors//------------------------------------------------------------------------CharCode GlobalParams::getMacRomanCharCode(char *charName) { // no need to lock - macRomanReverseMap is constant return macRomanReverseMap->lookup(charName);}GString *GlobalParams::getBaseDir() { GString *s; lockGlobalParams; s = baseDir->copy(); unlockGlobalParams; return s;}Unicode GlobalParams::mapNameToUnicode(char *charName) { // no need to lock - nameToUnicode is constant return nameToUnicode->lookup(charName);}UnicodeMap *GlobalParams::getResidentUnicodeMap(GString *encodingName) { UnicodeMap *map;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -