📄 globalparams.cc
字号:
//========================================================================//// GlobalParams.cc//// Copyright 2001-2003 Glyph & Cog, LLC////========================================================================#include <aconf.h>#ifdef USE_GCC_PRAGMAS#pragma implementation#endif#include <string.h>#include <stdio.h>#include <ctype.h>#ifdef ENABLE_PLUGINS# ifndef WIN32# include <dlfcn.h># endif#endif#ifdef WIN32# include <shlobj.h>#endif#if HAVE_PAPER_H#include <paper.h>#endif#include "gmem.h"#include "GString.h"#include "GList.h"#include "GHash.h"#include "gfile.h"#include "Error.h"#include "NameToCharCode.h"#include "CharCodeToUnicode.h"#include "UnicodeMap.h"#include "CMap.h"#include "BuiltinFontTables.h"#include "FontEncodingTables.h"#ifdef ENABLE_PLUGINS# include "XpdfPluginAPI.h"#endif#include "GlobalParams.h"#ifdef WIN32# define strcasecmp stricmp#endif#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 "UTF8.h"#ifdef ENABLE_PLUGINS# ifdef WIN32extern XpdfPluginVecTable xpdfPluginVecTable;# endif#endif//------------------------------------------------------------------------#define cidToUnicodeCacheSize 4#define unicodeToUnicodeCacheSize 4//------------------------------------------------------------------------static struct { char *name; char *t1FileName; char *ttFileName;} displayFontTab[] = { {"Courier", "n022003l.pfb", "cour.ttf"}, {"Courier-Bold", "n022004l.pfb", "courbd.ttf"}, {"Courier-BoldOblique", "n022024l.pfb", "courbi.ttf"}, {"Courier-Oblique", "n022023l.pfb", "couri.ttf"}, {"Helvetica", "n019003l.pfb", "arial.ttf"}, {"Helvetica-Bold", "n019004l.pfb", "arialbd.ttf"}, {"Helvetica-BoldOblique", "n019024l.pfb", "arialbi.ttf"}, {"Helvetica-Oblique", "n019023l.pfb", "ariali.ttf"}, {"Symbol", "s050000l.pfb", NULL}, {"Times-Bold", "n021004l.pfb", "timesbd.ttf"}, {"Times-BoldItalic", "n021024l.pfb", "timesbi.ttf"}, {"Times-Italic", "n021023l.pfb", "timesi.ttf"}, {"Times-Roman", "n021003l.pfb", "times.ttf"}, {"ZapfDingbats", "d050000l.pfb", NULL}, {NULL}};#ifdef WIN32static char *displayFontDirs[] = { "c:/windows/fonts", "c:/winnt/fonts", NULL};#elsestatic char *displayFontDirs[] = { "/usr/share/ghostscript/fonts", "/usr/local/share/ghostscript/fonts", "/usr/share/fonts/default/Type1", "/usr/share/fonts/default/ghostscript", "/usr/share/fonts/type1/gsfonts", NULL};#endif//------------------------------------------------------------------------GlobalParams *globalParams = NULL;//------------------------------------------------------------------------// DisplayFontParam//------------------------------------------------------------------------DisplayFontParam::DisplayFontParam(GString *nameA, DisplayFontParamKind kindA) { name = nameA; kind = kindA; switch (kind) { case displayFontT1: t1.fileName = NULL; break; case displayFontTT: tt.fileName = NULL; break; }}DisplayFontParam::~DisplayFontParam() { delete name; switch (kind) { case displayFontT1: if (t1.fileName) { delete t1.fileName; } break; case displayFontTT: if (tt.fileName) { delete tt.fileName; } break; }}#ifdef WIN32//------------------------------------------------------------------------// WinFontInfo//------------------------------------------------------------------------class WinFontInfo: public DisplayFontParam {public: GBool bold, italic; static WinFontInfo *make(GString *nameA, GBool boldA, GBool italicA, HKEY regKey, char *winFontDir); WinFontInfo(GString *nameA, GBool boldA, GBool italicA, GString *fileNameA); virtual ~WinFontInfo(); GBool equals(WinFontInfo *fi);};WinFontInfo *WinFontInfo::make(GString *nameA, GBool boldA, GBool italicA, HKEY regKey, char *winFontDir) { GString *regName; GString *fileNameA; char buf[MAX_PATH]; DWORD n; char c; int i; //----- find the font file fileNameA = NULL; regName = nameA->copy(); if (boldA) { regName->append(" Bold"); } if (italicA) { regName->append(" Italic"); } regName->append(" (TrueType)"); n = sizeof(buf); if (RegQueryValueEx(regKey, regName->getCString(), NULL, NULL, (LPBYTE)buf, &n) == ERROR_SUCCESS) { fileNameA = new GString(winFontDir); fileNameA->append('\\')->append(buf); } delete regName; if (!fileNameA) { delete nameA; return NULL; } //----- normalize the font name i = 0; while (i < nameA->getLength()) { c = nameA->getChar(i); if (c == ' ' || c == ',' || c == '-') { nameA->del(i); } else { ++i; } } return new WinFontInfo(nameA, boldA, italicA, fileNameA);}WinFontInfo::WinFontInfo(GString *nameA, GBool boldA, GBool italicA, GString *fileNameA): DisplayFontParam(nameA, displayFontTT){ bold = boldA; italic = italicA; tt.fileName = fileNameA;}WinFontInfo::~WinFontInfo() {}GBool WinFontInfo::equals(WinFontInfo *fi) { return !name->cmp(fi->name) && bold == fi->bold && italic == fi->italic;}//------------------------------------------------------------------------// WinFontList//------------------------------------------------------------------------class WinFontList {public: WinFontList(char *winFontDirA); ~WinFontList(); WinFontInfo *find(GString *font);private: void add(WinFontInfo *fi); static int CALLBACK enumFunc1(CONST LOGFONT *font, CONST TEXTMETRIC *metrics, DWORD type, LPARAM data); static int CALLBACK enumFunc2(CONST LOGFONT *font, CONST TEXTMETRIC *metrics, DWORD type, LPARAM data); GList *fonts; // [WinFontInfo] HDC dc; // (only used during enumeration) HKEY regKey; // (only used during enumeration) char *winFontDir; // (only used during enumeration)};WinFontList::WinFontList(char *winFontDirA) { OSVERSIONINFO version; char *path; fonts = new GList(); dc = GetDC(NULL); winFontDir = winFontDirA; version.dwOSVersionInfoSize = sizeof(version); GetVersionEx(&version); if (version.dwPlatformId == VER_PLATFORM_WIN32_NT) { path = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts\\"; } else { path = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Fonts\\"; } if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, path, 0, KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS, ®Key) == ERROR_SUCCESS) { EnumFonts(dc, NULL, &WinFontList::enumFunc1, (LPARAM)this); RegCloseKey(regKey); } ReleaseDC(NULL, dc);}WinFontList::~WinFontList() { deleteGList(fonts, WinFontInfo);}void WinFontList::add(WinFontInfo *fi) { int i; for (i = 0; i < fonts->getLength(); ++i) { if (((WinFontInfo *)fonts->get(i))->equals(fi)) { delete fi; return; } } fonts->append(fi);}WinFontInfo *WinFontList::find(GString *font) { GString *name; GBool bold, italic; WinFontInfo *fi; char c; int n, i; name = font->copy(); // remove space, comma, dash chars i = 0; while (i < name->getLength()) { c = name->getChar(i); if (c == ' ' || c == ',' || c == '-') { name->del(i); } else { ++i; } } n = name->getLength(); // remove trailing "MT" (Foo-MT, Foo-BoldMT, etc.) if (!strcmp(name->getCString() + n - 2, "MT")) { name->del(n - 2, 2); n -= 2; } // look for "Italic" if (!strcmp(name->getCString() + n - 6, "Italic")) { name->del(n - 6, 6); italic = gTrue; n -= 6; } else { italic = gFalse; } // look for "Bold" if (!strcmp(name->getCString() + n - 4, "Bold")) { name->del(n - 4, 4); bold = gTrue; n -= 4; } else { bold = gFalse; } // remove trailing "MT" (FooMT-Bold, etc.) if (!strcmp(name->getCString() + n - 2, "MT")) { name->del(n - 2, 2); n -= 2; } // remove trailing "PS" if (!strcmp(name->getCString() + n - 2, "PS")) { name->del(n - 2, 2); n -= 2; } // search for the font fi = NULL; for (i = 0; i < fonts->getLength(); ++i) { fi = (WinFontInfo *)fonts->get(i); if (!fi->name->cmp(name) && fi->bold == bold && fi->italic == italic) { break; } fi = NULL; } delete name; return fi;}int CALLBACK WinFontList::enumFunc1(CONST LOGFONT *font, CONST TEXTMETRIC *metrics, DWORD type, LPARAM data) { WinFontList *fl = (WinFontList *)data; EnumFonts(fl->dc, font->lfFaceName, &WinFontList::enumFunc2, (LPARAM)fl); return 1;}int CALLBACK WinFontList::enumFunc2(CONST LOGFONT *font, CONST TEXTMETRIC *metrics, DWORD type, LPARAM data) { WinFontList *fl = (WinFontList *)data; WinFontInfo *fi; if (type & TRUETYPE_FONTTYPE) { if ((fi = WinFontInfo::make(new GString(font->lfFaceName), font->lfWeight >= 600, font->lfItalic ? gTrue : gFalse, fl->regKey, fl->winFontDir))) { fl->add(fi); } } return 1;}#endif // WIN32//------------------------------------------------------------------------// PSFontParam//------------------------------------------------------------------------PSFontParam::PSFontParam(GString *pdfFontNameA, int wModeA, GString *psFontNameA, GString *encodingA) { pdfFontName = pdfFontNameA; wMode = wModeA; psFontName = psFontNameA; encoding = encodingA;}PSFontParam::~PSFontParam() { delete pdfFontName; delete psFontName; if (encoding) { delete encoding; }}//------------------------------------------------------------------------// KeyBinding//------------------------------------------------------------------------KeyBinding::KeyBinding(int codeA, int modsA, int contextA, char *cmd0) { code = codeA; mods = modsA; context = contextA; cmds = new GList(); cmds->append(new GString(cmd0));}KeyBinding::KeyBinding(int codeA, int modsA, int contextA, char *cmd0, char *cmd1) { code = codeA; mods = modsA; context = contextA; cmds = new GList(); cmds->append(new GString(cmd0)); cmds->append(new GString(cmd1));}KeyBinding::KeyBinding(int codeA, int modsA, int contextA, GList *cmdsA) { code = codeA; mods = modsA; context = contextA; cmds = cmdsA;}KeyBinding::~KeyBinding() { deleteGList(cmds, GString);}#ifdef ENABLE_PLUGINS//------------------------------------------------------------------------// Plugin//------------------------------------------------------------------------class Plugin {public: static Plugin *load(char *type, char *name); ~Plugin();private:#ifdef WIN32 Plugin(HMODULE libA); HMODULE lib;#else Plugin(void *dlA); void *dl;#endif};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -