⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 globalparams.cc

📁 source code: Covert TXT to PDF
💻 CC
📖 第 1 页 / 共 3 页
字号:
//========================================================================//// GlobalParams.cc//// Copyright 2001-2002 Glyph & Cog, LLC////========================================================================#include <aconf.h>#ifdef USE_GCC_PRAGMAS#pragma implementation#endif#include <string.h>#include <ctype.h>#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"#include "GlobalParams.h"#if MULTITHREADED#  define globalParamsLock gLockMutex(&mutex)#  define globalParamsUnlock gUnlockMutex(&mutex)#else#  define globalParamsLock#  define globalParamsUnlock#endif#include "NameToUnicodeTable.h"#include "UnicodeMapTables.h"#include "DisplayFontTable.h"#include "UTF8.h"//------------------------------------------------------------------------GlobalParams *globalParams = NULL;//------------------------------------------------------------------------// DisplayFontParam//------------------------------------------------------------------------DisplayFontParam::DisplayFontParam(GString *nameA,				   DisplayFontParamKind kindA) {  name = nameA;  kind = kindA;  switch (kind) {  case displayFontX:    x.xlfd = NULL;    x.encoding = NULL;    break;  case displayFontT1:    t1.fileName = NULL;    break;  case displayFontTT:    tt.fileName = NULL;    break;  }}DisplayFontParam::DisplayFontParam(char *nameA, char *xlfdA, char *encodingA) {  name = new GString(nameA);  kind = displayFontX;  x.xlfd = new GString(xlfdA);  x.encoding = new GString(encodingA);}DisplayFontParam::~DisplayFontParam() {  delete name;  switch (kind) {  case displayFontX:    if (x.xlfd) {      delete x.xlfd;    }    if (x.encoding) {      delete x.encoding;    }    break;  case displayFontT1:    if (t1.fileName) {      delete t1.fileName;    }    break;  case displayFontTT:    if (tt.fileName) {      delete tt.fileName;    }    break;  }}//------------------------------------------------------------------------// 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;  }}//------------------------------------------------------------------------// parsing//------------------------------------------------------------------------GlobalParams::GlobalParams(char *cfgFileName) {  UnicodeMap *map;  DisplayFontParam *dfp;  GString *fileName;  FILE *f;  int i;#if MULTITHREADED  gInitMutex(&mutex);#endif  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 = 255; i >= 0; --i) {    if (macRomanEncoding[i]) {      macRomanReverseMap->add(macRomanEncoding[i], (CharCode)i);    }  }  nameToUnicode = new NameToCharCode();  cidToUnicodes = new GHash(gTrue);  residentUnicodeMaps = new GHash();  unicodeMaps = new GHash(gTrue);  cMapDirs = new GHash(gTrue);  toUnicodeDirs = new GList();  displayFonts = new GHash();  displayCIDFonts = new GHash();  displayNamedCIDFonts = new GHash();#if HAVE_PAPER_H  char *paperName;  const struct paper *paperType;  paperinit();  if ((paperName = systempapername())) {    paperType = paperinfo(paperName);    psPaperWidth = (int)paperpswidth(paperType);    psPaperHeight = (int)paperpsheight(paperType);  } else {    error(-1, "No paper information available - using defaults");    psPaperWidth = defPaperWidth;    psPaperHeight = defPaperHeight;  }  paperdone();#else  psPaperWidth = defPaperWidth;  psPaperHeight = defPaperHeight;#endif  psDuplex = gFalse;  psLevel = psLevel2;  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)  textEOL = eolDOS;#elif defined(MACOS)  textEOL = eolMac;#else  textEOL = eolUnix;#endif  textKeepTinyChars = gFalse;  fontDirs = new GList();  initialZoom = new GString("1");  t1libControl = fontRastAALow;  freetypeControl = fontRastAALow;  urlCommand = NULL;  movieCommand = NULL;  mapNumericCharNames = gTrue;  printCommands = gFalse;  errQuiet = gFalse;  cidToUnicodeCache = new CIDToUnicodeCache();  unicodeMapCache = new UnicodeMapCache();  cMapCache = new CMapCache();  // set up the initial nameToUnicode table  for (i = 0; nameToUnicodeTab[i].name; ++i) {    nameToUnicode->add(nameToUnicodeTab[i].name, nameToUnicodeTab[i].u);  }  // set up the residentUnicodeMaps table  map = new UnicodeMap("Latin1", gFalse,		       latin1UnicodeMapRanges, latin1UnicodeMapLen);  residentUnicodeMaps->add(map->getEncodingName(), map);  map = new UnicodeMap("ASCII7", gFalse,		       ascii7UnicodeMapRanges, ascii7UnicodeMapLen);  residentUnicodeMaps->add(map->getEncodingName(), map);  map = new UnicodeMap("Symbol", gFalse,		       symbolUnicodeMapRanges, symbolUnicodeMapLen);  residentUnicodeMaps->add(map->getEncodingName(), map);  map = new UnicodeMap("ZapfDingbats", gFalse, zapfDingbatsUnicodeMapRanges,		       zapfDingbatsUnicodeMapLen);  residentUnicodeMaps->add(map->getEncodingName(), map);  map = new UnicodeMap("UTF-8", gTrue, &mapUTF8);  residentUnicodeMaps->add(map->getEncodingName(), map);  map = new UnicodeMap("UCS-2", gTrue, &mapUCS2);  residentUnicodeMaps->add(map->getEncodingName(), map);  // default displayFonts table  for (i = 0; displayFontTab[i].name; ++i) {    dfp = new DisplayFontParam(displayFontTab[i].name,			       displayFontTab[i].xlfd,			       displayFontTab[i].encoding);    displayFonts->add(dfp->name, dfp);  }  // look for a user config file, then a system-wide config file  f = NULL;  fileName = NULL;  if (cfgFileName && cfgFileName[0]) {    fileName = new GString(cfgFileName);    if (!(f = fopen(fileName->getCString(), "r"))) {      delete fileName;    }  }  if (!f) {    fileName = appendToPath(getHomeDir(), xpdfUserConfigFile);    if (!(f = fopen(fileName->getCString(), "r"))) {      delete fileName;    }  }  if (!f) {#if defined(WIN32) && !defined(__CYGWIN32__)    char buf[512];    i = GetModuleFileName(NULL, buf, sizeof(buf));    if (i <= 0 || i >= sizeof(buf)) {      // error or path too long for buffer - just use the current dir      buf[0] = '\0';    }    fileName = grabPath(buf);    appendToPath(fileName, xpdfSysConfigFile);#else    fileName = new GString(xpdfSysConfigFile);#endif    if (!(f = fopen(fileName->getCString(), "r"))) {      delete fileName;    }  }  if (f) {    parseFile(fileName, f);    delete fileName;    fclose(f);  }}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 (getLine(buf, sizeof(buf) - 1, f)) {    // break the line into tokens    tokens = new GList();    p1 = buf;    while (*p1) {      for (; *p1 && isspace(*p1); ++p1) ;      if (!*p1) {	break;      }      if (*p1 == '"' || *p1 == '\'') {	for (p2 = p1 + 1; *p2 && *p2 != *p1; ++p2) ;	++p1;      } else {	for (p2 = p1 + 1; *p2 && !isspace(*p2); ++p2) ;      }      tokens->append(new GString(p1, p2 - p1));      p1 = *p2 ? p2 + 1 : p2;    }    if (tokens->getLength() > 0 &&	((GString *)tokens->get(0))->getChar(0) != '#') {      cmd = (GString *)tokens->get(0);      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")) {	parseCIDToUnicode(tokens, fileName, line);      } else if (!cmd->cmp("unicodeMap")) {	parseUnicodeMap(tokens, fileName, line);      } else if (!cmd->cmp("cMapDir")) {	parseCMapDir(tokens, fileName, line);      } else if (!cmd->cmp("toUnicodeDir")) {	parseToUnicodeDir(tokens, fileName, line);      } else if (!cmd->cmp("displayFontX")) {	parseDisplayFont(tokens, displayFonts, displayFontX, fileName, line);      } else if (!cmd->cmp("displayFontT1")) {	parseDisplayFont(tokens, displayFonts, displayFontT1, fileName, line);      } else if (!cmd->cmp("displayFontTT")) {	parseDisplayFont(tokens, displayFonts, displayFontTT, fileName, line);      } else if (!cmd->cmp("displayNamedCIDFontX")) {	parseDisplayFont(tokens, displayNamedCIDFonts,			 displayFontX, fileName, line);      } else if (!cmd->cmp("displayCIDFontX")) {	parseDisplayFont(tokens, displayCIDFonts,			 displayFontX, fileName, line);      } else if (!cmd->cmp("displayNamedCIDFontT1")) {	parseDisplayFont(tokens, displayNamedCIDFonts,			 displayFontT1, fileName, line);      } else if (!cmd->cmp("displayCIDFontT1")) {	parseDisplayFont(tokens, displayCIDFonts,			 displayFontT1, 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);      } else if (!cmd->cmp("psDuplex")) {	parseYesNo("psDuplex", &psDuplex, tokens, fileName, line);      } else if (!cmd->cmp("psLevel")) {	parsePSLevel(tokens, fileName, line);      } else if (!cmd->cmp("psEmbedType1Fonts")) {	parseYesNo("psEmbedType1", &psEmbedType1, tokens, fileName, line);      } 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);      } else if (!cmd->cmp("textEOL")) {	parseTextEOL(tokens, fileName, line);      } else if (!cmd->cmp("textKeepTinyChars")) {	parseYesNo("textKeepTinyChars", &textKeepTinyChars,		   tokens, fileName, line);      } 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,			     tokens, fileName, line);      } else if (!cmd->cmp("freetypeControl")) {	parseFontRastControl("freetypeControl", &freetypeControl,			     tokens, fileName, line);      } else if (!cmd->cmp("urlCommand")) {	parseCommand("urlCommand", &urlCommand, tokens, fileName, line);      } else if (!cmd->cmp("movieCommand")) {	parseCommand("movieCommand", &movieCommand, tokens, fileName, line);      } else if (!cmd->cmp("mapNumericCharNames")) {	parseYesNo("mapNumericCharNames", &mapNumericCharNames,		   tokens, fileName, line);      } else if (!cmd->cmp("printCommands")) {	parseYesNo("printCommands", &printCommands, tokens, fileName, line);      } else if (!cmd->cmp("errQuiet")) {	parseYesNo("errQuiet", &errQuiet, tokens, fileName, line);      } else if (!cmd->cmp("fontpath") || !cmd->cmp("fontmap")) {	error(-1, "Unknown config file command");	error(-1, "-- the config file format has changed since Xpdf 0.9x");      } else {	error(-1, "Unknown config file command '%s' (%s:%d)",	      cmd->getCString(), fileName->getCString(), line);      }    }    deleteGList(tokens, GString);    ++line;  }}void GlobalParams::parseNameToUnicode(GList *tokens, GString *fileName,					 int line) {  GString *name;  char *tok1, *tok2;  FILE *f;  char buf[256];  int line2;  Unicode u;  if (tokens->getLength() != 2) {    error(-1, "Bad 'nameToUnicode' config file command (%s:%d)",	  fileName->getCString(), line);    return;  }  name = (GString *)tokens->get(1);  if (!(f = fopen(name->getCString(), "r"))) {    error(-1, "Couldn't open 'nameToUnicode' file '%s'",	  name->getCString());    return;  }  line2 = 1;  while (getLine(buf, sizeof(buf), f)) {    tok1 = strtok(buf, " \t\r\n");    tok2 = strtok(NULL, " \t\r\n");    if (tok1 && tok2) {      sscanf(tok1, "%x", &u);      nameToUnicode->add(tok2, u);    } else {      error(-1, "Bad line in 'nameToUnicode' file (%s:%d)", name, line2);    }    ++line2;  }  fclose(f);}void GlobalParams::parseCIDToUnicode(GList *tokens, GString *fileName,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -