Coverage Report

Created: 2024-02-11 07:26

/src/xpdf-4.05/xpdf/GlobalParams.cc
Line
Count
Source (jump to first uncovered line)
1
//========================================================================
2
//
3
// GlobalParams.cc
4
//
5
// Copyright 2001-2003 Glyph & Cog, LLC
6
//
7
//========================================================================
8
9
#include <aconf.h>
10
11
#include <string.h>
12
#include <stdio.h>
13
#include <stdarg.h>
14
#include <ctype.h>
15
#include <time.h>
16
#ifdef _WIN32
17
#  include <shlobj.h>
18
#endif
19
#if HAVE_PAPER_H
20
#include <paper.h>
21
#endif
22
#if HAVE_FONTCONFIG
23
#  include <fontconfig/fontconfig.h>
24
#endif
25
#include "gmem.h"
26
#include "gmempp.h"
27
#include "GString.h"
28
#include "GList.h"
29
#include "GHash.h"
30
#include "gfile.h"
31
#include "FoFiIdentifier.h"
32
#include "Error.h"
33
#include "NameToCharCode.h"
34
#include "CharCodeToUnicode.h"
35
#include "UnicodeRemapping.h"
36
#include "UnicodeMap.h"
37
#include "CMap.h"
38
#include "BuiltinFontTables.h"
39
#include "FontEncodingTables.h"
40
#include "GlobalParams.h"
41
42
#ifdef _WIN32
43
#ifndef __GNUC__
44
#  define strcasecmp stricmp
45
#  define strncasecmp strnicmp
46
#endif
47
#endif
48
49
#if MULTITHREADED
50
10.4k
#  define lockGlobalParams            gLockMutex(&mutex)
51
0
#  define lockUnicodeMapCache         gLockMutex(&unicodeMapCacheMutex)
52
0
#  define lockCMapCache               gLockMutex(&cMapCacheMutex)
53
10.4k
#  define unlockGlobalParams          gUnlockMutex(&mutex)
54
0
#  define unlockUnicodeMapCache       gUnlockMutex(&unicodeMapCacheMutex)
55
0
#  define unlockCMapCache             gUnlockMutex(&cMapCacheMutex)
56
#else
57
#  define lockGlobalParams
58
#  define lockUnicodeMapCache
59
#  define lockCMapCache
60
#  define unlockGlobalParams
61
#  define unlockUnicodeMapCache
62
#  define unlockCMapCache
63
#endif
64
65
#include "NameToUnicodeTable.h"
66
#include "UnicodeMapTables.h"
67
#include "UTF8.h"
68
69
//------------------------------------------------------------------------
70
71
3.17k
#define cidToUnicodeCacheSize     4
72
3.17k
#define unicodeToUnicodeCacheSize 4
73
74
//------------------------------------------------------------------------
75
76
static struct {
77
  const char *name;
78
  const char *t1FileName;
79
  const char *ttFileName;
80
  const char *macFileName;  // may be .dfont, .ttf, or .ttc
81
  const char *macFontName;  // font name inside .dfont or .ttc
82
  const char *obliqueFont;  // name of font to oblique
83
  double obliqueFactor;   // oblique sheer factor
84
} displayFontTab[] = {
85
  {"Courier",               "n022003l.pfb", "cour.ttf",    "Courier",      "Courier",                NULL,             0},
86
  {"Courier-Bold",          "n022004l.pfb", "courbd.ttf",  "Courier",      "Courier Bold",           NULL,             0},
87
  {"Courier-BoldOblique",   "n022024l.pfb", "courbi.ttf",  "Courier",      "Courier Bold Oblique",   "Courier-Bold",   0.212557},
88
  {"Courier-Oblique",       "n022023l.pfb", "couri.ttf",   "Courier",      "Courier Oblique",        "Courier",        0.212557},
89
  {"Helvetica",             "n019003l.pfb", "arial.ttf",   "Helvetica",    "Helvetica",              NULL,             0},
90
  {"Helvetica-Bold",        "n019004l.pfb", "arialbd.ttf", "Helvetica",    "Helvetica Bold",         NULL,             0},
91
  {"Helvetica-BoldOblique", "n019024l.pfb", "arialbi.ttf", "Helvetica",    "Helvetica Bold Oblique", "Helvetica-Bold", 0.212557},
92
  {"Helvetica-Oblique",     "n019023l.pfb", "ariali.ttf",  "Helvetica",    "Helvetica Oblique",      "Helvetica",      0.212557},
93
  {"Symbol",                "s050000l.pfb", NULL,          "Symbol",       "Symbol",                 NULL,             0},
94
  {"Times-Bold",            "n021004l.pfb", "timesbd.ttf", "Times",        "Times Bold",             NULL,             0},
95
  {"Times-BoldItalic",      "n021024l.pfb", "timesbi.ttf", "Times",        "Times Bold Italic",       NULL,             0},
96
  {"Times-Italic",          "n021023l.pfb", "timesi.ttf",  "Times",        "Times Italic",           NULL,             0},
97
  {"Times-Roman",           "n021003l.pfb", "times.ttf",   "Times",        "Times Roman",            NULL,             0},
98
  {"ZapfDingbats",          "d050000l.pfb", NULL,          "ZapfDingbats", "Zapf Dingbats",          NULL,             0},
99
  {NULL}
100
};
101
102
static const char *displayFontDirs[] = {
103
#ifdef BASE14_FONT_DIR
104
  BASE14_FONT_DIR,
105
#endif
106
#ifdef _WIN32
107
  "c:/windows/fonts",
108
  "c:/winnt/fonts",
109
#else // _WIN32
110
  "/usr/share/ghostscript/fonts",
111
  "/usr/local/share/ghostscript/fonts",
112
  "/usr/share/fonts/default/Type1",
113
  "/usr/share/fonts/default/ghostscript",
114
  "/usr/share/fonts/type1/gsfonts",
115
#if defined(__sun) && defined(__SVR4)
116
  "/usr/sfw/share/ghostscript/fonts",
117
#endif
118
#endif // _WIN32
119
  NULL
120
};
121
122
#ifdef __APPLE__
123
static const char *macSystemFontPath = "/System/Library/Fonts";
124
#endif
125
126
struct Base14FontInfo {
127
0
  Base14FontInfo(GString *fileNameA, int fontNumA, double obliqueA) {
128
0
    fileName = fileNameA;
129
0
    fontNum = fontNumA;
130
0
    oblique = obliqueA;
131
0
  }
132
0
  ~Base14FontInfo() {
133
0
    delete fileName;
134
0
  }
135
  GString *fileName;
136
  int fontNum;
137
  double oblique;
138
};
139
140
//------------------------------------------------------------------------
141
142
GlobalParams *globalParams = NULL;
143
144
const char *GlobalParams::defaultTextEncoding = "Latin1";
145
146
//------------------------------------------------------------------------
147
// PSFontParam16
148
//------------------------------------------------------------------------
149
150
PSFontParam16::PSFontParam16(GString *nameA, int wModeA,
151
0
           GString *psFontNameA, GString *encodingA) {
152
0
  name = nameA;
153
0
  wMode = wModeA;
154
0
  psFontName = psFontNameA;
155
0
  encoding = encodingA;
156
0
}
157
158
0
PSFontParam16::~PSFontParam16() {
159
0
  delete name;
160
0
  delete psFontName;
161
0
  delete encoding;
162
0
}
163
164
//------------------------------------------------------------------------
165
// SysFontInfo
166
//------------------------------------------------------------------------
167
168
class SysFontInfo {
169
public:
170
171
  GString *name;
172
  GString *path;
173
  SysFontType type;
174
  int fontNum;      // for TrueType collections
175
176
  SysFontInfo(GString *nameA, GString *pathA, SysFontType typeA, int fontNumA);
177
  ~SysFontInfo();
178
  GString *mungeName1(GString *in);
179
  GString *mungeName2(GString *in);
180
  void mungeName3(GString *nameA, GBool *bold, GBool *italic);
181
  int match(GString *nameA);
182
};
183
184
SysFontInfo::SysFontInfo(GString *nameA, GString *pathA,
185
0
       SysFontType typeA, int fontNumA) {
186
0
  name = nameA;
187
0
  path = pathA;
188
0
  type = typeA;
189
0
  fontNum = fontNumA;
190
0
}
191
192
0
SysFontInfo::~SysFontInfo() {
193
0
  delete name;
194
0
  delete path;
195
0
}
196
197
// Remove space/comma/dash/underscore chars.
198
// Uppercase the name.
199
0
GString *SysFontInfo::mungeName1(GString *in) {
200
0
  GString *out = new GString();
201
0
  for (char *p = in->getCString(); *p; ++p) {
202
0
    if (*p == ' ' || *p == ',' || *p == '-' || *p == '_') {
203
      // skip
204
0
    } else if (*p >= 'a' && *p <= 'z') {
205
0
      out->append((char)(*p & 0xdf));
206
0
    } else {
207
0
      out->append(*p);
208
0
    }
209
0
  }
210
0
  return out;
211
0
}
212
213
// Remove trailing encoding tags from the name.
214
// Split the name into tokens at space/comma/dash/underscore.
215
// Remove trailing "MT" or "BT" from tokens.
216
// Remove trailing "PS" and "WGL4" from tokens.
217
// Uppercase each token.
218
// Concatenate tokens (dropping the space/comma/dash chars).
219
0
GString *SysFontInfo::mungeName2(GString *in) {
220
0
  GString *out = new GString();
221
0
  char *p0 = in->getCString();
222
0
  while (*p0) {
223
0
    if (!strcmp(p0, "Identity-H") || !strcmp(p0, "Identity-V") ||
224
0
  !strcmp(p0, "GB2312") ||
225
0
  !strcmp(p0, "UniGB-UCS2-H") || !strcmp(p0, "UniGB-UCS2-V")) {
226
0
      break;
227
0
    }
228
0
    char *p1;
229
0
    for (p1 = p0 + 1;
230
0
   *p1 && *p1 != ' ' && *p1 != ',' && *p1 != '-' && *p1 != '_';
231
0
   ++p1) ;
232
0
    char *p2 = p1;
233
0
    if (p2 - p0 >= 2 && (p2[-2] == 'B' || p2[-2] == 'M') && p2[-1] == 'T') {
234
0
      p2 -= 2;
235
0
    }
236
0
    if (p2 - p0 >= 2 && p2[-2] == 'P' && p2[-1] == 'S') {
237
0
      p2 -= 2;
238
0
    }
239
0
    if (p2 - p0 >= 4 &&
240
0
  p2[-4] == 'W' && p2[-3] == 'G' && p2[-2] == 'L' && p2[-1] == '4') {
241
0
      p2 -= 4;
242
0
    }
243
0
    for (; p0 < p2; ++p0) {
244
0
      if (*p0 >= 'a' && *p0 <= 'z') {
245
0
  out->append((char)(*p0 & 0xdf));
246
0
      } else {
247
0
  out->append(*p0);
248
0
      }
249
0
    }
250
0
    for (p0 = p1; *p0 == ' ' || *p0 == ',' || *p0 == '-' || *p0 == '_'; ++p0) ;
251
0
  }
252
0
  return out;
253
0
}
254
255
// Remove trailing bold/italic/regular/roman tags from the name.
256
// (Note: the names have already been uppercased by mungeName1/2.)
257
0
void SysFontInfo::mungeName3(GString *nameA, GBool *bold, GBool *italic) {
258
0
  *bold = gFalse;
259
0
  *italic = gFalse;
260
0
  int n = nameA->getLength();
261
0
  while (1) {
262
0
    if (n >= 4 && !strcmp(nameA->getCString() + n - 4, "BOLD")) {
263
0
      nameA->del(n - 4, 4);
264
0
      n -= 4;
265
0
      *bold = gTrue;
266
0
    } else if (n >= 6 && !strcmp(nameA->getCString() + n - 6, "ITALIC")) {
267
0
      nameA->del(n - 6, 6);
268
0
      n -= 6;
269
0
      *italic = gTrue;
270
0
    } else if (n >= 7 && !strcmp(nameA->getCString() + n - 7, "REGULAR")) {
271
0
      nameA->del(n - 7, 7);
272
0
      n -= 7;
273
0
    } else if (n >= 5 && !strcmp(nameA->getCString() + n - 5, "ROMAN")) {
274
0
      nameA->del(n - 5, 5);
275
0
      n -= 5;
276
0
    } else {
277
0
      break;
278
0
    }
279
0
  }
280
0
}
281
282
// Returns a score indicating how well this font matches [nameA].  A
283
// higher score is better.  Zero indicates a non-match.
284
0
int SysFontInfo::match(GString *nameA) {
285
  // fast fail: check if the first two letters match
286
0
  if (strncasecmp(name->getCString(), nameA->getCString(), 2)) {
287
0
    return 0;
288
0
  }
289
290
0
  GString *pdfName1 = mungeName1(nameA);
291
0
  GString *sysName1 = mungeName1(name);
292
0
  if (!pdfName1->cmp(sysName1)) {
293
0
    delete pdfName1;
294
0
    delete sysName1;
295
0
    return 8;
296
0
  }
297
298
0
  GString *pdfName2 = mungeName2(nameA);
299
0
  GString *sysName2 = mungeName2(name);
300
0
  if (!pdfName2->cmp(sysName2)) {
301
0
    delete pdfName1;
302
0
    delete sysName1;
303
0
    delete pdfName2;
304
0
    delete sysName2;
305
0
    return 7;
306
0
  }
307
308
0
  GBool pdfBold1, pdfItalic1, sysBold1, sysItalic1;
309
0
  mungeName3(pdfName1, &pdfBold1, &pdfItalic1);
310
0
  mungeName3(sysName1, &sysBold1, &sysItalic1);
311
0
  int eq1 = !pdfName1->cmp(sysName1);
312
313
0
  GBool pdfBold2, pdfItalic2, sysBold2, sysItalic2;
314
0
  mungeName3(pdfName2, &pdfBold2, &pdfItalic2);
315
0
  mungeName3(sysName2, &sysBold2, &sysItalic2);
316
0
  int eq2 =!pdfName2->cmp(sysName2);
317
318
0
  delete pdfName1;
319
0
  delete sysName1;
320
0
  delete pdfName2;
321
0
  delete sysName2;
322
323
0
  if (eq1 && pdfBold1 == sysBold1 && pdfItalic1 == sysItalic1) {
324
0
    return 6;
325
0
  }
326
0
  if (eq2 && pdfBold2 == sysBold2 && pdfItalic2 == sysItalic2) {
327
0
    return 5;
328
0
  }
329
0
  if (eq1 && pdfItalic1 == sysItalic1) {
330
0
    return 4;
331
0
  }
332
0
  if (eq2 && pdfItalic2 == sysItalic2) {
333
0
    return 3;
334
0
  }
335
0
  if (eq1) {
336
0
    return 2;
337
0
  }
338
0
  if (eq2) {
339
0
    return 1;
340
0
  }
341
342
0
  return 0;
343
0
}
344
345
//------------------------------------------------------------------------
346
// SysFontList
347
//------------------------------------------------------------------------
348
349
class SysFontList {
350
public:
351
352
  SysFontList();
353
  ~SysFontList();
354
  SysFontInfo *find(GString *name);
355
356
#ifdef _WIN32
357
  void scanWindowsFonts(char *winFontDir);
358
#endif
359
360
#if HAVE_FONTCONFIG
361
  void scanFontconfigFonts();
362
#endif
363
364
private:
365
366
#ifdef _WIN32
367
  SysFontInfo *makeWindowsFont(char *name, int fontNum,
368
             char *path);
369
#endif
370
371
  GList *fonts;     // [SysFontInfo]
372
};
373
374
3.17k
SysFontList::SysFontList() {
375
3.17k
  fonts = new GList();
376
3.17k
}
377
378
3.17k
SysFontList::~SysFontList() {
379
3.17k
  deleteGList(fonts, SysFontInfo);
380
3.17k
}
381
382
0
SysFontInfo *SysFontList::find(GString *name) {
383
0
  SysFontInfo *match = NULL;
384
0
  int score = 0;
385
0
  for (int i = 0; i < fonts->getLength(); ++i) {
386
0
    SysFontInfo *fi = (SysFontInfo *)fonts->get(i);
387
0
    int s = fi->match(name);
388
0
    if (s > score) {
389
0
      match = fi;
390
0
      score = s;
391
0
    }
392
0
  }
393
0
  return match;
394
0
}
395
396
#ifdef _WIN32
397
void SysFontList::scanWindowsFonts(char *winFontDir) {
398
  OSVERSIONINFO version;
399
  const char *path;
400
  DWORD idx, valNameLen, dataLen, type;
401
  HKEY regKey;
402
  char valName[1024], data[1024];
403
  int n, fontNum;
404
  char *p0, *p1;
405
  GString *fontPath;
406
407
  version.dwOSVersionInfoSize = sizeof(version);
408
  GetVersionEx(&version);
409
  if (version.dwPlatformId == VER_PLATFORM_WIN32_NT) {
410
    path = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts\\";
411
  } else {
412
    path = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Fonts\\";
413
  }
414
  if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, path, 0,
415
        KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS,
416
        &regKey) == ERROR_SUCCESS) {
417
    idx = 0;
418
    while (1) {
419
      valNameLen = sizeof(valName) - 1;
420
      dataLen = sizeof(data) - 1;
421
      if (RegEnumValueA(regKey, idx, valName, &valNameLen, NULL,
422
      &type, (LPBYTE)data, &dataLen) != ERROR_SUCCESS) {
423
  break;
424
      }
425
      if (type == REG_SZ &&
426
    valNameLen > 0 && valNameLen < sizeof(valName) &&
427
    dataLen > 0 && dataLen < sizeof(data)) {
428
  valName[valNameLen] = '\0';
429
  data[dataLen] = '\0';
430
  n = (int)strlen(data);
431
  if (!strcasecmp(data + n - 4, ".ttf") ||
432
      !strcasecmp(data + n - 4, ".ttc") ||
433
      !strcasecmp(data + n - 4, ".otf")) {
434
    fontPath = new GString(data);
435
    if (!(dataLen >= 3 && data[1] == ':' && data[2] == '\\')) {
436
      fontPath->insert(0, '\\');
437
      fontPath->insert(0, winFontDir);
438
    }
439
    p0 = valName;
440
    fontNum = 0;
441
    while (*p0) {
442
      p1 = strstr(p0, " & ");
443
      if (p1) {
444
        *p1 = '\0';
445
        p1 = p1 + 3;
446
      } else {
447
        p1 = p0 + strlen(p0);
448
      }
449
      fonts->append(makeWindowsFont(p0, fontNum,
450
            fontPath->getCString()));
451
      p0 = p1;
452
      ++fontNum;
453
    }
454
    delete fontPath;
455
  }
456
      }
457
      ++idx;
458
    }
459
    RegCloseKey(regKey);
460
  }
461
}
462
463
SysFontInfo *SysFontList::makeWindowsFont(char *name, int fontNum,
464
            char *path) {
465
  int n = (int)strlen(name);
466
467
  // remove trailing ' (TrueType)' or ' (OpenType)'
468
  if (n > 11 && (!strncmp(name + n - 11, " (TrueType)", 11) ||
469
     !strncmp(name + n - 11, " (OpenType)", 11))) {
470
    n -= 11;
471
  }
472
473
  SysFontType type;
474
  if (!strcasecmp(path + strlen(path) - 4, ".ttc")) {
475
    type = sysFontTTC;
476
  } else if (!strcasecmp(path + strlen(path) - 4, ".otf")) {
477
    type = sysFontOTF;
478
  } else {
479
    type = sysFontTTF;
480
  }
481
482
  return new SysFontInfo(new GString(name, n), new GString(path),
483
       type, fontNum);
484
}
485
#endif // _WIN32
486
487
#if HAVE_FONTCONFIG
488
void SysFontList::scanFontconfigFonts() {
489
  FcConfig *cfg;
490
  FcPattern *pattern;
491
  FcObjectSet *objSet;
492
  FcFontSet *fontSet;
493
  char *name, *file;
494
  SysFontType type;
495
  int fontNum, i, n;
496
497
  if (!(cfg = FcInitLoadConfigAndFonts())) {
498
    return;
499
  }
500
501
  pattern = FcPatternBuild(NULL,
502
         FC_OUTLINE, FcTypeBool, FcTrue,
503
         FC_SCALABLE, FcTypeBool, FcTrue,
504
         NULL);
505
  objSet = FcObjectSetBuild(FC_FULLNAME, FC_FILE, FC_INDEX, NULL);
506
  fontSet = FcFontList(cfg, pattern, objSet);
507
  FcPatternDestroy(pattern);
508
  FcObjectSetDestroy(objSet);
509
510
  if (fontSet) {
511
    for (i = 0; i < fontSet->nfont; ++i) {
512
513
      //--- font file, font type
514
      if (FcPatternGetString(fontSet->fonts[i], FC_FILE, 0,
515
           (FcChar8 **)&file)
516
    != FcResultMatch) {
517
  continue;
518
      }
519
      n = (int)strlen(file);
520
      if (n > 4 && !strcasecmp(file + n - 4, ".pfa")) {
521
  type = sysFontPFA;
522
      } else if (n > 4 && !strcasecmp(file + n - 4, ".pfb")) {
523
  type = sysFontPFB;
524
      } else if (n > 4 && !strcasecmp(file + n - 4, ".ttf")) {
525
  type = sysFontTTF;
526
      } else if (n > 4 && !strcasecmp(file + n - 4, ".otf")) {
527
  type = sysFontOTF;
528
      } else {
529
  continue;
530
      }
531
532
      //--- font number
533
      if (FcPatternGetInteger(fontSet->fonts[i], FC_INDEX, 0, &fontNum)
534
    != FcResultMatch) {
535
  fontNum = 0;
536
      }
537
538
      //--- font name
539
      if (FcPatternGetString(fontSet->fonts[i], FC_FULLNAME, 0,
540
           (FcChar8 **)&name)
541
    != FcResultMatch) {
542
  continue;
543
      }
544
545
      fonts->append(new SysFontInfo(new GString(name), new GString(file),
546
            type, fontNum));
547
    }
548
549
    FcFontSetDestroy(fontSet);
550
  }
551
552
  FcConfigDestroy(cfg);
553
}
554
#endif // HAVE_FONTCONFIG
555
556
//------------------------------------------------------------------------
557
// KeyBinding
558
//------------------------------------------------------------------------
559
560
193k
KeyBinding::KeyBinding(int codeA, int modsA, int contextA, const char *cmd0) {
561
193k
  code = codeA;
562
193k
  mods = modsA;
563
193k
  context = contextA;
564
193k
  cmds = new GList();
565
193k
  cmds->append(new GString(cmd0));
566
193k
}
567
568
KeyBinding::KeyBinding(int codeA, int modsA, int contextA,
569
0
           const char *cmd0, const char *cmd1) {
570
0
  code = codeA;
571
0
  mods = modsA;
572
0
  context = contextA;
573
0
  cmds = new GList();
574
0
  cmds->append(new GString(cmd0));
575
0
  cmds->append(new GString(cmd1));
576
0
}
577
578
0
KeyBinding::KeyBinding(int codeA, int modsA, int contextA, GList *cmdsA) {
579
0
  code = codeA;
580
0
  mods = modsA;
581
0
  context = contextA;
582
0
  cmds = cmdsA;
583
0
}
584
585
193k
KeyBinding::~KeyBinding() {
586
193k
  deleteGList(cmds, GString);
587
193k
}
588
589
//------------------------------------------------------------------------
590
// PopupMenuCmd
591
//------------------------------------------------------------------------
592
593
0
PopupMenuCmd::PopupMenuCmd(GString *labelA, GList *cmdsA) {
594
0
  label = labelA;
595
0
  cmds = cmdsA;
596
0
}
597
598
0
PopupMenuCmd::~PopupMenuCmd() {
599
0
  delete label;
600
0
  deleteGList(cmds, GString);
601
0
}
602
603
//------------------------------------------------------------------------
604
// parsing
605
//------------------------------------------------------------------------
606
607
3.17k
GlobalParams::GlobalParams(const char *cfgFileName) {
608
3.17k
  UnicodeMap *map;
609
3.17k
  GString *fileName;
610
3.17k
  FILE *f;
611
3.17k
  int i;
612
613
3.17k
#if MULTITHREADED
614
3.17k
  gInitMutex(&mutex);
615
3.17k
  gInitMutex(&unicodeMapCacheMutex);
616
3.17k
  gInitMutex(&cMapCacheMutex);
617
3.17k
#endif
618
619
#ifdef _WIN32
620
  tlsWin32ErrorInfo = TlsAlloc();
621
#endif
622
623
3.17k
  initBuiltinFontTables();
624
625
  // scan the encoding in reverse because we want the lowest-numbered
626
  // index for each char name ('space' is encoded twice)
627
3.17k
  macRomanReverseMap = new NameToCharCode();
628
816k
  for (i = 255; i >= 0; --i) {
629
813k
    if (macRomanEncoding[i]) {
630
708k
      macRomanReverseMap->add(macRomanEncoding[i], (CharCode)i);
631
708k
    }
632
813k
  }
633
634
#ifdef _WIN32
635
  // baseDir will be set by a call to setBaseDir
636
  baseDir = new GString();
637
#else
638
3.17k
  baseDir = appendToPath(getHomeDir(), ".xpdf");
639
3.17k
#endif
640
3.17k
  configFileVars = new GHash(gTrue);
641
3.17k
  setDataDirVar();
642
3.17k
  nameToUnicode = new NameToCharCode();
643
3.17k
  cidToUnicodes = new GHash(gTrue);
644
3.17k
  unicodeToUnicodes = new GHash(gTrue);
645
3.17k
  residentUnicodeMaps = new GHash();
646
3.17k
  unicodeMaps = new GHash(gTrue);
647
3.17k
  cMapDirs = new GHash(gTrue);
648
3.17k
  toUnicodeDirs = new GList();
649
3.17k
  unicodeRemapping = new UnicodeRemapping();
650
3.17k
  fontFiles = new GHash(gTrue);
651
3.17k
  fontDirs = new GList();
652
3.17k
  ccFontFiles = new GHash(gTrue);
653
3.17k
  base14SysFonts = new GHash(gTrue);
654
3.17k
  sysFonts = new SysFontList();
655
#if HAVE_PAPER_H
656
  const char *paperName;
657
  const struct paper *paperType;
658
  paperinit();
659
  if ((paperName = systempapername())) {
660
    paperType = paperinfo(paperName);
661
    psPaperWidth = (int)paperpswidth(paperType);
662
    psPaperHeight = (int)paperpsheight(paperType);
663
  } else {
664
    error(errConfig, -1, "No paper information available - using defaults");
665
    psPaperWidth = defPaperWidth;
666
    psPaperHeight = defPaperHeight;
667
  }
668
  paperdone();
669
#else
670
3.17k
  psPaperWidth = defPaperWidth;
671
3.17k
  psPaperHeight = defPaperHeight;
672
3.17k
#endif
673
3.17k
  psImageableLLX = psImageableLLY = 0;
674
3.17k
  psImageableURX = psPaperWidth;
675
3.17k
  psImageableURY = psPaperHeight;
676
3.17k
  psCrop = gTrue;
677
3.17k
  psUseCropBoxAsPage = gFalse;
678
3.17k
  psExpandSmaller = gFalse;
679
3.17k
  psShrinkLarger = gTrue;
680
3.17k
  psCenter = gTrue;
681
3.17k
  psDuplex = gFalse;
682
3.17k
  psLevel = psLevel2;
683
3.17k
  psResidentFonts = new GHash(gTrue);
684
3.17k
  psResidentFonts16 = new GList();
685
3.17k
  psResidentFontsCC = new GList();
686
3.17k
  psEmbedType1 = gTrue;
687
3.17k
  psEmbedTrueType = gTrue;
688
3.17k
  psEmbedCIDPostScript = gTrue;
689
3.17k
  psEmbedCIDTrueType = gTrue;
690
3.17k
  psFontPassthrough = gFalse;
691
3.17k
  psPreload = gFalse;
692
3.17k
  psOPI = gFalse;
693
3.17k
  psASCIIHex = gFalse;
694
3.17k
  psLZW = gTrue;
695
3.17k
  psUncompressPreloadedImages = gFalse;
696
3.17k
  psMinLineWidth = 0;
697
3.17k
  psRasterResolution = 300;
698
3.17k
  psRasterMono = gFalse;
699
3.17k
  psRasterSliceSize = 20000000;
700
3.17k
  psAlwaysRasterize = gFalse;
701
3.17k
  psNeverRasterize = gFalse;
702
3.17k
  textEncoding = new GString(defaultTextEncoding);
703
#if defined(_WIN32)
704
  textEOL = eolDOS;
705
#else
706
3.17k
  textEOL = eolUnix;
707
3.17k
#endif
708
3.17k
  textPageBreaks = gTrue;
709
3.17k
  textKeepTinyChars = gTrue;
710
3.17k
  initialZoom = new GString("125");
711
3.17k
  defaultFitZoom = 0;
712
3.17k
  zoomScaleFactor = 1;
713
3.17k
  zoomValues = new GList();
714
3.17k
  zoomValues->append(new GString("25"));
715
3.17k
  zoomValues->append(new GString("50"));
716
3.17k
  zoomValues->append(new GString("75"));
717
3.17k
  zoomValues->append(new GString("100"));
718
3.17k
  zoomValues->append(new GString("110"));
719
3.17k
  zoomValues->append(new GString("125"));
720
3.17k
  zoomValues->append(new GString("150"));
721
3.17k
  zoomValues->append(new GString("175"));
722
3.17k
  zoomValues->append(new GString("200"));
723
3.17k
  zoomValues->append(new GString("300"));
724
3.17k
  zoomValues->append(new GString("400"));
725
3.17k
  zoomValues->append(new GString("600"));
726
3.17k
  zoomValues->append(new GString("800"));
727
3.17k
  initialDisplayMode = new GString("continuous");
728
3.17k
  initialToolbarState = gTrue;
729
3.17k
  initialSidebarState = gTrue;
730
3.17k
  initialSidebarWidth = 0;
731
3.17k
  initialSelectMode = new GString("linear");
732
3.17k
  maxTileWidth = 1500;
733
3.17k
  maxTileHeight = 1500;
734
3.17k
  tileCacheSize = 10;
735
3.17k
  workerThreads = 1;
736
3.17k
  enableFreeType = gTrue;
737
3.17k
  disableFreeTypeHinting = gFalse;
738
3.17k
  antialias = gTrue;
739
3.17k
  vectorAntialias = gTrue;
740
3.17k
  imageMaskAntialias = gTrue;
741
3.17k
  antialiasPrinting = gFalse;
742
3.17k
  strokeAdjust = strokeAdjustNormal;
743
3.17k
  screenType = screenUnset;
744
3.17k
  screenSize = -1;
745
3.17k
  screenDotRadius = -1;
746
3.17k
  screenGamma = 1.0;
747
3.17k
  screenBlackThreshold = 0.0;
748
3.17k
  screenWhiteThreshold = 1.0;
749
3.17k
  minLineWidth = 0.0;
750
3.17k
  enablePathSimplification = gFalse;
751
3.17k
  drawAnnotations = gTrue;
752
3.17k
  drawFormFields = gTrue;
753
3.17k
  enableXFA = gTrue;
754
3.17k
  overprintPreview = gFalse;
755
3.17k
  paperColor = new GString("#ffffff");
756
3.17k
  matteColor = new GString("#808080");
757
3.17k
  fullScreenMatteColor = new GString("#000000");
758
3.17k
  selectionColor = new GString("#8080ff");
759
3.17k
  reverseVideoInvertImages = gFalse;
760
3.17k
  allowLinksToChangeZoom = gTrue;
761
3.17k
  launchCommand = NULL;
762
3.17k
  movieCommand = NULL;
763
3.17k
  defaultPrinter = NULL;
764
3.17k
  mapNumericCharNames = gTrue;
765
3.17k
  mapUnknownCharNames = gFalse;
766
3.17k
  mapExtTrueTypeFontsViaUnicode = gTrue;
767
3.17k
  useTrueTypeUnicodeMapping = gFalse;
768
3.17k
  ignoreWrongSizeToUnicode = gFalse;
769
3.17k
  droppedFonts = new GHash(gTrue);
770
3.17k
  separateRotatedText = gFalse;
771
3.17k
  createDefaultKeyBindings();
772
3.17k
  popupMenuCmds = new GList();
773
3.17k
  initStateFilePaths();
774
3.17k
  saveSessionOnQuit = gTrue;
775
3.17k
  savePageNumbers = gTrue;
776
3.17k
  printCommands = gFalse;
777
3.17k
  printStatusInfo = gFalse;
778
3.17k
  errQuiet = gFalse;
779
3.17k
  debugLogFile = NULL;
780
781
3.17k
  cidToUnicodeCache = new CharCodeToUnicodeCache(cidToUnicodeCacheSize);
782
3.17k
  unicodeToUnicodeCache =
783
3.17k
      new CharCodeToUnicodeCache(unicodeToUnicodeCacheSize);
784
3.17k
  unicodeMapCache = new UnicodeMapCache();
785
3.17k
  cMapCache = new CMapCache();
786
787
  // set up the initial nameToUnicode table
788
13.4M
  for (i = 0; nameToUnicodeTab[i].name; ++i) {
789
13.4M
    nameToUnicode->add(nameToUnicodeTab[i].name, nameToUnicodeTab[i].u);
790
13.4M
  }
791
792
  // set up the residentUnicodeMaps table
793
3.17k
  map = new UnicodeMap("Latin1", gFalse,
794
3.17k
           latin1UnicodeMapRanges, latin1UnicodeMapLen);
795
3.17k
  residentUnicodeMaps->add(map->getEncodingName(), map);
796
3.17k
  map = new UnicodeMap("ASCII7", gFalse,
797
3.17k
           ascii7UnicodeMapRanges, ascii7UnicodeMapLen);
798
3.17k
  residentUnicodeMaps->add(map->getEncodingName(), map);
799
3.17k
  map = new UnicodeMap("Symbol", gFalse,
800
3.17k
           symbolUnicodeMapRanges, symbolUnicodeMapLen);
801
3.17k
  residentUnicodeMaps->add(map->getEncodingName(), map);
802
3.17k
  map = new UnicodeMap("ZapfDingbats", gFalse, zapfDingbatsUnicodeMapRanges,
803
3.17k
           zapfDingbatsUnicodeMapLen);
804
3.17k
  residentUnicodeMaps->add(map->getEncodingName(), map);
805
3.17k
  map = new UnicodeMap("UTF-8", gTrue, &mapUTF8);
806
3.17k
  residentUnicodeMaps->add(map->getEncodingName(), map);
807
3.17k
  map = new UnicodeMap("UCS-2", gTrue, &mapUCS2);
808
3.17k
  residentUnicodeMaps->add(map->getEncodingName(), map);
809
810
  // look for a user config file, then a system-wide config file
811
3.17k
  f = NULL;
812
3.17k
  fileName = NULL;
813
3.17k
  if (cfgFileName && cfgFileName[0]) {
814
0
    fileName = new GString(cfgFileName);
815
0
    if (!(f = fopen(fileName->getCString(), "r"))) {
816
0
      delete fileName;
817
0
    }
818
0
  }
819
3.17k
  if (!f) {
820
3.17k
    fileName = appendToPath(getHomeDir(), xpdfUserConfigFile);
821
3.17k
    if (!(f = fopen(fileName->getCString(), "r"))) {
822
3.17k
      delete fileName;
823
3.17k
    }
824
3.17k
  }
825
3.17k
  if (!f) {
826
#ifdef _WIN32
827
    char buf[512];
828
    i = GetModuleFileNameA(NULL, buf, sizeof(buf));
829
    if (i <= 0 || i >= sizeof(buf)) {
830
      // error or path too long for buffer - just use the current dir
831
      buf[0] = '\0';
832
    }
833
    fileName = grabPath(buf);
834
    appendToPath(fileName, xpdfSysConfigFile);
835
#else
836
3.17k
    fileName = new GString(xpdfSysConfigFile);
837
3.17k
#endif
838
3.17k
    if (!(f = fopen(fileName->getCString(), "r"))) {
839
3.17k
      delete fileName;
840
3.17k
    }
841
3.17k
  }
842
3.17k
  if (f) {
843
0
    parseFile(fileName, f);
844
0
    delete fileName;
845
0
    fclose(f);
846
0
  }
847
3.17k
}
848
849
3.17k
void GlobalParams::setDataDirVar() {
850
3.17k
  GString *dir;
851
852
#if defined(XPDFRC_DATADIR)
853
  dir = new GString(XPDFRC_DATADIR);
854
#elif defined(_WIN32)
855
  wchar_t buf[512];
856
  DWORD n = GetModuleFileNameW(NULL, buf, sizeof(buf) / sizeof(wchar_t));
857
  if (n <= 0 || n >= sizeof(buf)) {
858
    // error or path too long for buffer - just use the current dir
859
    buf[0] = L'\0';
860
  }
861
  GString *path = fileNameToUTF8(buf);
862
  dir = grabPath(path->getCString());
863
  delete path;
864
  appendToPath(dir, "data");
865
#else
866
  //~ may be useful to allow the options of using the install dir
867
  //~   and/or the user's home dir (?)
868
3.17k
  dir = new GString("./data");
869
3.17k
#endif
870
871
3.17k
  configFileVars->add(new GString("DATADIR"), dir);
872
3.17k
}
873
874
3.17k
void GlobalParams::createDefaultKeyBindings() {
875
3.17k
  keyBindings = new GList();
876
877
  //----- mouse buttons
878
3.17k
  keyBindings->append(new KeyBinding(xpdfKeyCodeMousePress1, xpdfKeyModNone,
879
3.17k
             xpdfKeyContextAny, "startSelection"));
880
3.17k
  keyBindings->append(new KeyBinding(xpdfKeyCodeMousePress1, xpdfKeyModShift,
881
3.17k
             xpdfKeyContextAny,
882
3.17k
             "startExtendedSelection"));
883
3.17k
  keyBindings->append(new KeyBinding(xpdfKeyCodeMouseRelease1, xpdfKeyModNone,
884
3.17k
             xpdfKeyContextAny, "endSelection"));
885
3.17k
  keyBindings->append(new KeyBinding(xpdfKeyCodeMouseRelease1, xpdfKeyModShift,
886
3.17k
             xpdfKeyContextAny,
887
3.17k
             "endSelection"));
888
3.17k
  keyBindings->append(new KeyBinding(xpdfKeyCodeMouseDoubleClick1,
889
3.17k
             xpdfKeyModNone, xpdfKeyContextAny,
890
3.17k
             "selectWord"));
891
3.17k
  keyBindings->append(new KeyBinding(xpdfKeyCodeMouseTripleClick1,
892
3.17k
             xpdfKeyModNone, xpdfKeyContextAny,
893
3.17k
             "selectLine"));
894
3.17k
  keyBindings->append(new KeyBinding(xpdfKeyCodeMouseClick1, xpdfKeyModNone,
895
3.17k
             xpdfKeyContextAny, "followLinkNoSel"));
896
3.17k
  keyBindings->append(new KeyBinding(xpdfKeyCodeMouseClick2, xpdfKeyModNone,
897
3.17k
             xpdfKeyContextOverLink,
898
3.17k
             "followLinkInNewTab"));
899
3.17k
  keyBindings->append(new KeyBinding(xpdfKeyCodeMousePress2, xpdfKeyModNone,
900
3.17k
             xpdfKeyContextAny, "startPan"));
901
3.17k
  keyBindings->append(new KeyBinding(xpdfKeyCodeMouseRelease2, xpdfKeyModNone,
902
3.17k
             xpdfKeyContextAny, "endPan"));
903
3.17k
  keyBindings->append(new KeyBinding(xpdfKeyCodeMousePress3, xpdfKeyModNone,
904
3.17k
             xpdfKeyContextAny, "postPopupMenu"));
905
3.17k
  keyBindings->append(new KeyBinding(xpdfKeyCodeMousePress4, xpdfKeyModNone,
906
3.17k
             xpdfKeyContextAny,
907
3.17k
             "scrollUpPrevPage(16)"));
908
3.17k
  keyBindings->append(new KeyBinding(xpdfKeyCodeMousePress5, xpdfKeyModNone,
909
3.17k
             xpdfKeyContextAny,
910
3.17k
             "scrollDownNextPage(16)"));
911
3.17k
  keyBindings->append(new KeyBinding(xpdfKeyCodeMousePress6, xpdfKeyModNone,
912
3.17k
             xpdfKeyContextAny, "scrollLeft(16)"));
913
3.17k
  keyBindings->append(new KeyBinding(xpdfKeyCodeMousePress7, xpdfKeyModNone,
914
3.17k
             xpdfKeyContextAny, "scrollRight(16)"));
915
3.17k
  keyBindings->append(new KeyBinding(xpdfKeyCodeMousePress4, xpdfKeyModCtrl,
916
3.17k
             xpdfKeyContextAny, "zoomIn"));
917
3.17k
  keyBindings->append(new KeyBinding(xpdfKeyCodeMousePress5, xpdfKeyModCtrl,
918
3.17k
             xpdfKeyContextAny, "zoomOut"));
919
920
  //----- control keys
921
3.17k
  keyBindings->append(new KeyBinding('o', xpdfKeyModCtrl,
922
3.17k
             xpdfKeyContextAny, "open"));
923
3.17k
  keyBindings->append(new KeyBinding('r', xpdfKeyModCtrl,
924
3.17k
             xpdfKeyContextAny, "reload"));
925
3.17k
  keyBindings->append(new KeyBinding('f', xpdfKeyModCtrl,
926
3.17k
             xpdfKeyContextAny, "find"));
927
3.17k
  keyBindings->append(new KeyBinding('g', xpdfKeyModCtrl,
928
3.17k
             xpdfKeyContextAny, "findNext"));
929
3.17k
  keyBindings->append(new KeyBinding('c', xpdfKeyModCtrl,
930
3.17k
             xpdfKeyContextAny, "copy"));
931
3.17k
  keyBindings->append(new KeyBinding('p', xpdfKeyModCtrl,
932
3.17k
             xpdfKeyContextAny, "print"));
933
3.17k
  keyBindings->append(new KeyBinding('0', xpdfKeyModCtrl,
934
3.17k
             xpdfKeyContextAny, "zoomPercent(125)"));
935
3.17k
  keyBindings->append(new KeyBinding('+', xpdfKeyModCtrl,
936
3.17k
             xpdfKeyContextAny, "zoomIn"));
937
3.17k
  keyBindings->append(new KeyBinding('=', xpdfKeyModCtrl,
938
3.17k
             xpdfKeyContextAny, "zoomIn"));
939
3.17k
  keyBindings->append(new KeyBinding('-', xpdfKeyModCtrl,
940
3.17k
             xpdfKeyContextAny, "zoomOut"));
941
3.17k
  keyBindings->append(new KeyBinding('s', xpdfKeyModCtrl,
942
3.17k
             xpdfKeyContextAny, "saveAs"));
943
3.17k
  keyBindings->append(new KeyBinding('t', xpdfKeyModCtrl,
944
3.17k
             xpdfKeyContextAny, "newTab"));
945
3.17k
  keyBindings->append(new KeyBinding('n', xpdfKeyModCtrl,
946
3.17k
             xpdfKeyContextAny, "newWindow"));
947
3.17k
  keyBindings->append(new KeyBinding('w', xpdfKeyModCtrl,
948
3.17k
             xpdfKeyContextAny, "closeTabOrQuit"));
949
3.17k
  keyBindings->append(new KeyBinding('l', xpdfKeyModCtrl,
950
3.17k
             xpdfKeyContextAny,
951
3.17k
             "toggleFullScreenMode"));
952
3.17k
  keyBindings->append(new KeyBinding('q', xpdfKeyModCtrl,
953
3.17k
             xpdfKeyContextAny, "quit"));
954
3.17k
  keyBindings->append(new KeyBinding(xpdfKeyCodeTab, xpdfKeyModCtrl,
955
3.17k
             xpdfKeyContextAny, "nextTab"));
956
3.17k
  keyBindings->append(new KeyBinding(xpdfKeyCodeTab,
957
3.17k
             xpdfKeyModShift | xpdfKeyModCtrl,
958
3.17k
             xpdfKeyContextAny, "prevTab"));
959
3.17k
  keyBindings->append(new KeyBinding('?', xpdfKeyModCtrl,
960
3.17k
             xpdfKeyContextAny, "help"));
961
962
  //----- alt keys
963
3.17k
  keyBindings->append(new KeyBinding(xpdfKeyCodeLeft, xpdfKeyModAlt,
964
3.17k
             xpdfKeyContextAny, "goBackward"));
965
3.17k
  keyBindings->append(new KeyBinding(xpdfKeyCodeRight, xpdfKeyModAlt,
966
3.17k
             xpdfKeyContextAny, "goForward"));
967
968
  //----- home/end keys
969
3.17k
  keyBindings->append(new KeyBinding(xpdfKeyCodeHome, xpdfKeyModCtrl,
970
3.17k
             xpdfKeyContextAny, "gotoPage(1)"));
971
3.17k
  keyBindings->append(new KeyBinding(xpdfKeyCodeHome, xpdfKeyModNone,
972
3.17k
             xpdfKeyContextAny, "scrollToTopLeft"));
973
3.17k
  keyBindings->append(new KeyBinding(xpdfKeyCodeEnd, xpdfKeyModCtrl,
974
3.17k
             xpdfKeyContextAny, "gotoLastPage"));
975
3.17k
  keyBindings->append(new KeyBinding(xpdfKeyCodeEnd, xpdfKeyModNone,
976
3.17k
             xpdfKeyContextAny,
977
3.17k
             "scrollToBottomRight"));
978
979
  //----- pgup/pgdn keys
980
3.17k
  keyBindings->append(new KeyBinding(xpdfKeyCodePgUp, xpdfKeyModNone,
981
3.17k
             xpdfKeyContextAny, "pageUp"));
982
3.17k
  keyBindings->append(new KeyBinding(xpdfKeyCodePgDn, xpdfKeyModNone,
983
3.17k
             xpdfKeyContextAny, "pageDown"));
984
3.17k
  keyBindings->append(new KeyBinding(xpdfKeyCodePgUp, xpdfKeyModCtrl,
985
3.17k
             xpdfKeyContextAny, "prevPage"));
986
3.17k
  keyBindings->append(new KeyBinding(xpdfKeyCodePgDn, xpdfKeyModCtrl,
987
3.17k
             xpdfKeyContextAny, "nextPage"));
988
3.17k
  keyBindings->append(new KeyBinding(xpdfKeyCodePgUp, xpdfKeyModCtrl,
989
3.17k
             xpdfKeyContextScrLockOn,
990
3.17k
             "prevPageNoScroll"));
991
3.17k
  keyBindings->append(new KeyBinding(xpdfKeyCodePgDn, xpdfKeyModCtrl,
992
3.17k
             xpdfKeyContextScrLockOn,
993
3.17k
             "nextPageNoScroll"));
994
995
  //----- esc key
996
3.17k
  keyBindings->append(new KeyBinding(xpdfKeyCodeEsc, xpdfKeyModNone,
997
3.17k
             xpdfKeyContextFullScreen,
998
3.17k
             "windowMode"));
999
1000
  //----- arrow keys
1001
3.17k
  keyBindings->append(new KeyBinding(xpdfKeyCodeLeft, xpdfKeyModNone,
1002
3.17k
             xpdfKeyContextAny, "scrollLeft(16)"));
1003
3.17k
  keyBindings->append(new KeyBinding(xpdfKeyCodeRight, xpdfKeyModNone,
1004
3.17k
             xpdfKeyContextAny, "scrollRight(16)"));
1005
3.17k
  keyBindings->append(new KeyBinding(xpdfKeyCodeUp, xpdfKeyModNone,
1006
3.17k
             xpdfKeyContextAny, "scrollUp(16)"));
1007
3.17k
  keyBindings->append(new KeyBinding(xpdfKeyCodeDown, xpdfKeyModNone,
1008
3.17k
             xpdfKeyContextAny, "scrollDown(16)"));
1009
3.17k
  keyBindings->append(new KeyBinding(xpdfKeyCodeUp, xpdfKeyModCtrl,
1010
3.17k
             xpdfKeyContextAny, "prevPage"));
1011
3.17k
  keyBindings->append(new KeyBinding(xpdfKeyCodeDown, xpdfKeyModCtrl,
1012
3.17k
             xpdfKeyContextAny, "nextPage"));
1013
3.17k
  keyBindings->append(new KeyBinding(xpdfKeyCodeUp, xpdfKeyModCtrl,
1014
3.17k
             xpdfKeyContextScrLockOn,
1015
3.17k
             "prevPageNoScroll"));
1016
3.17k
  keyBindings->append(new KeyBinding(xpdfKeyCodeDown, xpdfKeyModCtrl,
1017
3.17k
             xpdfKeyContextScrLockOn,
1018
3.17k
             "nextPageNoScroll"));
1019
1020
  //----- letter keys
1021
3.17k
  keyBindings->append(new KeyBinding(' ', xpdfKeyModNone,
1022
3.17k
             xpdfKeyContextAny, "pageDown"));
1023
3.17k
  keyBindings->append(new KeyBinding('g', xpdfKeyModNone,
1024
3.17k
             xpdfKeyContextAny, "focusToPageNum"));
1025
3.17k
  keyBindings->append(new KeyBinding('z', xpdfKeyModNone,
1026
3.17k
             xpdfKeyContextAny, "zoomFitPage"));
1027
3.17k
  keyBindings->append(new KeyBinding('w', xpdfKeyModNone,
1028
3.17k
             xpdfKeyContextAny, "zoomFitWidth"));
1029
3.17k
}
1030
1031
3.17k
void GlobalParams::initStateFilePaths() {
1032
#ifdef _WIN32
1033
  char path[MAX_PATH];
1034
  if (SHGetFolderPathA(NULL, CSIDL_APPDATA, NULL,
1035
           SHGFP_TYPE_CURRENT, path) != S_OK) {
1036
    return;
1037
  }
1038
  GString *dir = appendToPath(new GString(path), "xpdf");
1039
  CreateDirectoryA(dir->getCString(), NULL);
1040
  pagesFile = appendToPath(dir->copy(), "xpdf.pages");
1041
  tabStateFile = appendToPath(dir->copy(), "xpdf.tab-state");
1042
  sessionFile = appendToPath(dir, "xpdf.session");
1043
#else
1044
3.17k
  pagesFile = appendToPath(getHomeDir(), ".xpdf.pages");
1045
3.17k
  tabStateFile = appendToPath(getHomeDir(), ".xpdf.tab-state");
1046
3.17k
  sessionFile = appendToPath(getHomeDir(), ".xpdf.session");
1047
3.17k
#endif
1048
3.17k
}
1049
1050
0
void GlobalParams::parseFile(GString *fileName, FILE *f) {
1051
0
  int line;
1052
0
  char buf[512];
1053
1054
0
  line = 1;
1055
0
  while (getLine(buf, sizeof(buf) - 1, f)) {
1056
0
    parseLine(buf, fileName, line);
1057
0
    ++line;
1058
0
  }
1059
0
}
1060
1061
0
void GlobalParams::parseLine(char *buf, GString *fileName, int line) {
1062
0
  GList *tokens;
1063
0
  GString *cmd, *incFile;
1064
0
  FILE *f2;
1065
1066
  // break the line into tokens
1067
0
  tokens = parseLineTokens(buf, fileName, line);
1068
1069
  // parse the line
1070
0
  if (tokens->getLength() > 0 &&
1071
0
      ((GString *)tokens->get(0))->getChar(0) != '#') {
1072
0
    cmd = (GString *)tokens->get(0);
1073
0
    if (!cmd->cmp("include")) {
1074
0
      if (tokens->getLength() == 2) {
1075
0
  incFile = (GString *)tokens->get(1);
1076
0
  if ((f2 = openFile(incFile->getCString(), "r"))) {
1077
0
    parseFile(incFile, f2);
1078
0
    fclose(f2);
1079
0
  } else {
1080
0
    error(errConfig, -1,
1081
0
    "Couldn't find included config file: '{0:t}' ({1:t}:{2:d})",
1082
0
    incFile, fileName, line);
1083
0
  }
1084
0
      } else {
1085
0
  error(errConfig, -1, "Bad 'include' config file command ({0:t}:{1:d})",
1086
0
        fileName, line);
1087
0
      }
1088
0
    } else if (!cmd->cmp("nameToUnicode")) {
1089
0
      parseNameToUnicode(tokens, fileName, line);
1090
0
    } else if (!cmd->cmp("cidToUnicode")) {
1091
0
      parseCIDToUnicode(tokens, fileName, line);
1092
0
    } else if (!cmd->cmp("unicodeToUnicode")) {
1093
0
      parseUnicodeToUnicode(tokens, fileName, line);
1094
0
    } else if (!cmd->cmp("unicodeMap")) {
1095
0
      parseUnicodeMap(tokens, fileName, line);
1096
0
    } else if (!cmd->cmp("cMapDir")) {
1097
0
      parseCMapDir(tokens, fileName, line);
1098
0
    } else if (!cmd->cmp("toUnicodeDir")) {
1099
0
      parseToUnicodeDir(tokens, fileName, line);
1100
0
    } else if (!cmd->cmp("unicodeRemapping")) {
1101
0
      parseUnicodeRemapping(tokens, fileName, line);
1102
0
    } else if (!cmd->cmp("fontFile")) {
1103
0
      parseFontFile(tokens, fileName, line);
1104
0
    } else if (!cmd->cmp("fontDir")) {
1105
0
      parseFontDir(tokens, fileName, line);
1106
0
    } else if (!cmd->cmp("fontFileCC")) {
1107
0
      parseFontFileCC(tokens, fileName, line);
1108
0
    } else if (!cmd->cmp("psPaperSize")) {
1109
0
      parsePSPaperSize(tokens, fileName, line);
1110
0
    } else if (!cmd->cmp("psImageableArea")) {
1111
0
      parsePSImageableArea(tokens, fileName, line);
1112
0
    } else if (!cmd->cmp("psCrop")) {
1113
0
      parseYesNo("psCrop", &psCrop, tokens, fileName, line);
1114
0
    } else if (!cmd->cmp("psUseCropBoxAsPage")) {
1115
0
      parseYesNo("psUseCropBoxAsPage", &psUseCropBoxAsPage,
1116
0
     tokens, fileName, line);
1117
0
    } else if (!cmd->cmp("psExpandSmaller")) {
1118
0
      parseYesNo("psExpandSmaller", &psExpandSmaller,
1119
0
     tokens, fileName, line);
1120
0
    } else if (!cmd->cmp("psShrinkLarger")) {
1121
0
      parseYesNo("psShrinkLarger", &psShrinkLarger, tokens, fileName, line);
1122
0
    } else if (!cmd->cmp("psCenter")) {
1123
0
      parseYesNo("psCenter", &psCenter, tokens, fileName, line);
1124
0
    } else if (!cmd->cmp("psDuplex")) {
1125
0
      parseYesNo("psDuplex", &psDuplex, tokens, fileName, line);
1126
0
    } else if (!cmd->cmp("psLevel")) {
1127
0
      parsePSLevel(tokens, fileName, line);
1128
0
    } else if (!cmd->cmp("psResidentFont")) {
1129
0
      parsePSResidentFont(tokens, fileName, line);
1130
0
    } else if (!cmd->cmp("psResidentFont16")) {
1131
0
      parsePSResidentFont16(tokens, fileName, line);
1132
0
    } else if (!cmd->cmp("psResidentFontCC")) {
1133
0
      parsePSResidentFontCC(tokens, fileName, line);
1134
0
    } else if (!cmd->cmp("psEmbedType1Fonts")) {
1135
0
      parseYesNo("psEmbedType1", &psEmbedType1, tokens, fileName, line);
1136
0
    } else if (!cmd->cmp("psEmbedTrueTypeFonts")) {
1137
0
      parseYesNo("psEmbedTrueType", &psEmbedTrueType,
1138
0
     tokens, fileName, line);
1139
0
    } else if (!cmd->cmp("psEmbedCIDPostScriptFonts")) {
1140
0
      parseYesNo("psEmbedCIDPostScript", &psEmbedCIDPostScript,
1141
0
     tokens, fileName, line);
1142
0
    } else if (!cmd->cmp("psEmbedCIDTrueTypeFonts")) {
1143
0
      parseYesNo("psEmbedCIDTrueType", &psEmbedCIDTrueType,
1144
0
     tokens, fileName, line);
1145
0
    } else if (!cmd->cmp("psFontPassthrough")) {
1146
0
      parseYesNo("psFontPassthrough", &psFontPassthrough,
1147
0
     tokens, fileName, line);
1148
0
    } else if (!cmd->cmp("psPreload")) {
1149
0
      parseYesNo("psPreload", &psPreload, tokens, fileName, line);
1150
0
    } else if (!cmd->cmp("psOPI")) {
1151
0
      parseYesNo("psOPI", &psOPI, tokens, fileName, line);
1152
0
    } else if (!cmd->cmp("psASCIIHex")) {
1153
0
      parseYesNo("psASCIIHex", &psASCIIHex, tokens, fileName, line);
1154
0
    } else if (!cmd->cmp("psLZW")) {
1155
0
      parseYesNo("psLZW", &psLZW, tokens, fileName, line);
1156
0
    } else if (!cmd->cmp("psUncompressPreloadedImages")) {
1157
0
      parseYesNo("psUncompressPreloadedImages", &psUncompressPreloadedImages,
1158
0
     tokens, fileName, line);
1159
0
    } else if (!cmd->cmp("psMinLineWidth")) {
1160
0
      parseFloat("psMinLineWidth", &psMinLineWidth,
1161
0
     tokens, fileName, line);
1162
0
    } else if (!cmd->cmp("psRasterResolution")) {
1163
0
      parseFloat("psRasterResolution", &psRasterResolution,
1164
0
     tokens, fileName, line);
1165
0
    } else if (!cmd->cmp("psRasterMono")) {
1166
0
      parseYesNo("psRasterMono", &psRasterMono, tokens, fileName, line);
1167
0
    } else if (!cmd->cmp("psRasterSliceSize")) {
1168
0
      parseInteger("psRasterSliceSize", &psRasterSliceSize,
1169
0
       tokens, fileName, line);
1170
0
    } else if (!cmd->cmp("psAlwaysRasterize")) {
1171
0
      parseYesNo("psAlwaysRasterize", &psAlwaysRasterize,
1172
0
     tokens, fileName, line);
1173
0
    } else if (!cmd->cmp("psNeverRasterize")) {
1174
0
      parseYesNo("psNeverRasterize", &psNeverRasterize,
1175
0
     tokens, fileName, line);
1176
0
    } else if (!cmd->cmp("textEncoding")) {
1177
0
      parseString("textEncoding", &textEncoding, tokens, fileName, line);
1178
0
    } else if (!cmd->cmp("textEOL")) {
1179
0
      parseTextEOL(tokens, fileName, line);
1180
0
    } else if (!cmd->cmp("textPageBreaks")) {
1181
0
      parseYesNo("textPageBreaks", &textPageBreaks,
1182
0
     tokens, fileName, line);
1183
0
    } else if (!cmd->cmp("textKeepTinyChars")) {
1184
0
      parseYesNo("textKeepTinyChars", &textKeepTinyChars,
1185
0
     tokens, fileName, line);
1186
0
    } else if (!cmd->cmp("initialZoom")) {
1187
0
      parseString("initialZoom", &initialZoom, tokens, fileName, line);
1188
0
    } else if (!cmd->cmp("defaultFitZoom")) {
1189
0
      parseInteger("defaultFitZoom", &defaultFitZoom, tokens, fileName, line);
1190
0
    } else if (!cmd->cmp("zoomScaleFactor")) {
1191
0
      parseZoomScaleFactor(tokens, fileName, line);
1192
0
    } else if (!cmd->cmp("zoomValues")) {
1193
0
      parseZoomValues(tokens, fileName, line);
1194
0
    } else if (!cmd->cmp("initialDisplayMode")) {
1195
0
      parseString("initialDisplayMode", &initialDisplayMode,
1196
0
      tokens, fileName, line);
1197
0
    } else if (!cmd->cmp("initialToolbarState")) {
1198
0
      parseYesNo("initialToolbarState", &initialToolbarState,
1199
0
     tokens, fileName, line);
1200
0
    } else if (!cmd->cmp("initialSidebarState")) {
1201
0
      parseYesNo("initialSidebarState", &initialSidebarState,
1202
0
     tokens, fileName, line);
1203
0
    } else if (!cmd->cmp("initialSidebarWidth")) {
1204
0
      parseInteger("initialSidebarWidth", &initialSidebarWidth,
1205
0
       tokens, fileName, line);
1206
0
    } else if (!cmd->cmp("initialSelectMode")) {
1207
0
      parseString("initialSelectMode", &initialSelectMode,
1208
0
      tokens, fileName, line);
1209
0
    } else if (!cmd->cmp("maxTileWidth")) {
1210
0
      parseInteger("maxTileWidth", &maxTileWidth, tokens, fileName, line);
1211
0
    } else if (!cmd->cmp("maxTileHeight")) {
1212
0
      parseInteger("maxTileHeight", &maxTileHeight, tokens, fileName, line);
1213
0
    } else if (!cmd->cmp("tileCacheSize")) {
1214
0
      parseInteger("tileCacheSize", &tileCacheSize, tokens, fileName, line);
1215
0
    } else if (!cmd->cmp("workerThreads")) {
1216
0
      parseInteger("workerThreads", &workerThreads, tokens, fileName, line);
1217
0
    } else if (!cmd->cmp("enableFreeType")) {
1218
0
      parseYesNo("enableFreeType", &enableFreeType, tokens, fileName, line);
1219
0
    } else if (!cmd->cmp("disableFreeTypeHinting")) {
1220
0
      parseYesNo("disableFreeTypeHinting", &disableFreeTypeHinting,
1221
0
     tokens, fileName, line);
1222
0
    } else if (!cmd->cmp("antialias")) {
1223
0
      parseYesNo("antialias", &antialias, tokens, fileName, line);
1224
0
    } else if (!cmd->cmp("vectorAntialias")) {
1225
0
      parseYesNo("vectorAntialias", &vectorAntialias,
1226
0
     tokens, fileName, line);
1227
0
    } else if (!cmd->cmp("imageMaskAntialias")) {
1228
0
      parseYesNo("imageMaskAntialias", &imageMaskAntialias,
1229
0
     tokens, fileName, line);
1230
0
    } else if (!cmd->cmp("antialiasPrinting")) {
1231
0
      parseYesNo("antialiasPrinting", &antialiasPrinting,
1232
0
     tokens, fileName, line);
1233
0
    } else if (!cmd->cmp("strokeAdjust")) {
1234
0
      parseStrokeAdjust(tokens, fileName, line);
1235
0
    } else if (!cmd->cmp("screenType")) {
1236
0
      parseScreenType(tokens, fileName, line);
1237
0
    } else if (!cmd->cmp("screenSize")) {
1238
0
      parseInteger("screenSize", &screenSize, tokens, fileName, line);
1239
0
    } else if (!cmd->cmp("screenDotRadius")) {
1240
0
      parseInteger("screenDotRadius", &screenDotRadius,
1241
0
       tokens, fileName, line);
1242
0
    } else if (!cmd->cmp("screenGamma")) {
1243
0
      parseFloat("screenGamma", &screenGamma,
1244
0
     tokens, fileName, line);
1245
0
    } else if (!cmd->cmp("screenBlackThreshold")) {
1246
0
      parseFloat("screenBlackThreshold", &screenBlackThreshold,
1247
0
     tokens, fileName, line);
1248
0
    } else if (!cmd->cmp("screenWhiteThreshold")) {
1249
0
      parseFloat("screenWhiteThreshold", &screenWhiteThreshold,
1250
0
     tokens, fileName, line);
1251
0
    } else if (!cmd->cmp("minLineWidth")) {
1252
0
      parseFloat("minLineWidth", &minLineWidth,
1253
0
     tokens, fileName, line);
1254
0
    } else if (!cmd->cmp("enablePathSimplification")) {
1255
0
      parseYesNo("enablePathSimplification", &enablePathSimplification,
1256
0
     tokens, fileName, line);
1257
0
    } else if (!cmd->cmp("drawAnnotations")) {
1258
0
      parseYesNo("drawAnnotations", &drawAnnotations,
1259
0
     tokens, fileName, line);
1260
0
    } else if (!cmd->cmp("drawFormFields")) {
1261
0
      parseYesNo("drawFormFields", &drawFormFields,
1262
0
     tokens, fileName, line);
1263
0
    } else if (!cmd->cmp("enableXFA")) {
1264
0
      parseYesNo("enableXFA", &enableXFA,
1265
0
     tokens, fileName, line);
1266
0
    } else if (!cmd->cmp("overprintPreview")) {
1267
0
      parseYesNo("overprintPreview", &overprintPreview,
1268
0
     tokens, fileName, line);
1269
0
    } else if (!cmd->cmp("paperColor")) {
1270
0
      parseString("paperColor", &paperColor, tokens, fileName, line);
1271
0
    } else if (!cmd->cmp("matteColor")) {
1272
0
      parseString("matteColor", &matteColor, tokens, fileName, line);
1273
0
    } else if (!cmd->cmp("fullScreenMatteColor")) {
1274
0
      parseString("fullScreenMatteColor", &fullScreenMatteColor,
1275
0
      tokens, fileName, line);
1276
0
    } else if (!cmd->cmp("selectionColor")) {
1277
0
      parseString("selectionColor", &selectionColor, tokens, fileName, line);
1278
0
    } else if (!cmd->cmp("reverseVideoInvertImages")) {
1279
0
      parseYesNo("reverseVideoInvertImages", &reverseVideoInvertImages,
1280
0
     tokens, fileName, line);
1281
0
    } else if (!cmd->cmp("allowLinksToChangeZoom")) {
1282
0
      parseYesNo("allowLinksToChangeZoom", &allowLinksToChangeZoom,
1283
0
     tokens, fileName, line);
1284
0
    } else if (!cmd->cmp("launchCommand")) {
1285
0
      parseString("launchCommand", &launchCommand, tokens, fileName, line);
1286
0
    } else if (!cmd->cmp("movieCommand")) {
1287
0
      parseString("movieCommand", &movieCommand, tokens, fileName, line);
1288
0
    } else if (!cmd->cmp("defaultPrinter")) {
1289
0
      parseString("defaultPrinter", &defaultPrinter, tokens, fileName, line);
1290
0
    } else if (!cmd->cmp("mapNumericCharNames")) {
1291
0
      parseYesNo("mapNumericCharNames", &mapNumericCharNames,
1292
0
     tokens, fileName, line);
1293
0
    } else if (!cmd->cmp("mapUnknownCharNames")) {
1294
0
      parseYesNo("mapUnknownCharNames", &mapUnknownCharNames,
1295
0
     tokens, fileName, line);
1296
0
    } else if (!cmd->cmp("mapExtTrueTypeFontsViaUnicode")) {
1297
0
      parseYesNo("mapExtTrueTypeFontsViaUnicode",
1298
0
     &mapExtTrueTypeFontsViaUnicode,
1299
0
     tokens, fileName, line);
1300
0
    } else if (!cmd->cmp("useTrueTypeUnicodeMapping")) {
1301
0
      parseYesNo("useTrueTypeUnicodeMapping", &useTrueTypeUnicodeMapping,
1302
0
     tokens, fileName, line);
1303
0
    } else if (!cmd->cmp("ignoreWrongSizeToUnicode")) {
1304
0
      parseYesNo("ignoreWrongSizeToUnicode", &ignoreWrongSizeToUnicode,
1305
0
     tokens, fileName, line);
1306
0
    } else if (!cmd->cmp("dropFont")) {
1307
0
      parseDropFont(tokens, fileName, line);
1308
0
    } else if (!cmd->cmp("separateRotatedText")) {
1309
0
      parseYesNo("separateRotatedText", &separateRotatedText,
1310
0
     tokens, fileName, line);
1311
0
    } else if (!cmd->cmp("bind")) {
1312
0
      parseBind(tokens, fileName, line);
1313
0
    } else if (!cmd->cmp("unbind")) {
1314
0
      parseUnbind(tokens, fileName, line);
1315
0
    } else if (!cmd->cmp("popupMenuCmd")) {
1316
0
      parsePopupMenuCmd(tokens, fileName, line);
1317
0
    } else if (!cmd->cmp("tabStateFile")) {
1318
0
      parseString("tabStateFile", &tabStateFile, tokens, fileName, line);
1319
0
    } else if (!cmd->cmp("sessionFile")) {
1320
0
      parseString("sessionFile", &sessionFile, tokens, fileName, line);
1321
0
    } else if (!cmd->cmp("saveSessionOnQuit")) {
1322
0
      parseYesNo("saveSessionOnQuit", &saveSessionOnQuit,
1323
0
     tokens, fileName, line);
1324
0
    } else if (!cmd->cmp("savePageNumbers")) {
1325
0
      parseYesNo("savePageNumbers", &savePageNumbers, tokens, fileName, line);
1326
0
    } else if (!cmd->cmp("printCommands")) {
1327
0
      parseYesNo("printCommands", &printCommands, tokens, fileName, line);
1328
0
    } else if (!cmd->cmp("printStatusInfo")) {
1329
0
      parseYesNo("printStatusInfo", &printStatusInfo, tokens, fileName, line);
1330
0
    } else if (!cmd->cmp("errQuiet")) {
1331
0
      parseYesNo("errQuiet", &errQuiet, tokens, fileName, line);
1332
0
    } else if (!cmd->cmp("debugLogFile")) {
1333
0
      parseString("debugLogFile", &debugLogFile, tokens, fileName, line);
1334
0
    } else {
1335
0
      error(errConfig, -1, "Unknown config file command '{0:t}' ({1:t}:{2:d})",
1336
0
      cmd, fileName, line);
1337
0
      if (!cmd->cmp("displayFontX") ||
1338
0
    !cmd->cmp("displayNamedCIDFontX") ||
1339
0
    !cmd->cmp("displayCIDFontX")) {
1340
0
  error(errConfig, -1, "Xpdf no longer supports X fonts");
1341
0
      } else if (!cmd->cmp("enableT1lib")) {
1342
0
  error(errConfig, -1, "Xpdf no longer uses t1lib");
1343
0
      } else if (!cmd->cmp("t1libControl") || !cmd->cmp("freetypeControl")) {
1344
0
  error(errConfig, -1,
1345
0
        "The t1libControl and freetypeControl options have been replaced by the enableT1lib, enableFreeType, and antialias options");
1346
0
      } else if (!cmd->cmp("fontpath") || !cmd->cmp("fontmap")) {
1347
0
  error(errConfig, -1,
1348
0
        "The config file format has changed since Xpdf 0.9x");
1349
0
      }
1350
0
    }
1351
0
  }
1352
1353
0
  deleteGList(tokens, GString);
1354
0
}
1355
1356
// Split a line into a sequence of tokens.  Tokens are separated by
1357
// whitespace.  Each token is one of:
1358
//   - unquoted string, which can contain any char other than
1359
//     whitespace, and which cannot start with a single quote, double
1360
//     quote, or at-double-quote (xxxx)
1361
//   - single-quoted string, which can contain any char other than the
1362
//     single quote ('xxxx')
1363
//   - double-quoted string, which can contain any char other than the
1364
//     double quote ("xxxx")
1365
//   - at-double-quoted string, which can contain variables and escape
1366
//     chars (@"xxxx")
1367
//     - variables look like ${name}
1368
//     - special chars (${}") can be escaped with %, e.g.,
1369
//       @"foo%"bar", @"foo%$bar", @"foo%%bar"
1370
0
GList *GlobalParams::parseLineTokens(char *buf, GString *fileName, int line) {
1371
0
  GList *tokens = new GList();
1372
0
  char *p1 = buf;
1373
0
  while (*p1) {
1374
0
    for (; *p1 && isspace(*p1); ++p1) ;
1375
0
    if (!*p1) {
1376
0
      break;
1377
0
    }
1378
0
    if (*p1 == '"' || *p1 == '\'') {
1379
0
      char *p2;
1380
0
      for (p2 = p1 + 1; *p2 && *p2 != *p1; ++p2) ;
1381
0
      ++p1;
1382
0
      tokens->append(new GString(p1, (int)(p2 - p1)));
1383
0
      p1 = *p2 ? p2 + 1 : p2;
1384
0
    } else if (*p1 == '@' && p1[1] == '"') {
1385
0
      GString *token = new GString();
1386
0
      char *p2 = p1 + 2;
1387
0
      while (*p2 && *p2 != '"') {
1388
0
  if (*p2 == '%' && p2[1]) {
1389
0
    token->append(p2[1]);
1390
0
    p2 += 2;
1391
0
  } else if (*p2 == '$' && p2[1] == '{') {
1392
0
    p2 += 2;
1393
0
    char *p3;
1394
0
    for (p3 = p2; *p3 && *p3 != '}'; ++p3) ;
1395
0
    GString *varName = new GString(p2, (int)(p3 - p2));
1396
0
    GString *varValue = (GString *)configFileVars->lookup(varName);
1397
0
    if (varValue) {
1398
0
      token->append(varValue);
1399
0
    } else {
1400
0
      error(errConfig, -1, "Unknown config file variable '%t'", varName);
1401
0
    }
1402
0
    delete varName;
1403
0
    p2 = *p3 ? p3 + 1 : p3;
1404
0
  } else {
1405
0
    token->append(*p2);
1406
0
    ++p2;
1407
0
  }
1408
0
      }
1409
0
      tokens->append(token);
1410
0
      p1 = *p2 ? p2 + 1 : p2;
1411
0
    } else {
1412
0
      char *p2;
1413
0
      for (p2 = p1 + 1; *p2 && !isspace(*p2); ++p2) ;
1414
0
      tokens->append(new GString(p1, (int)(p2 - p1)));
1415
0
      p1 = p2;
1416
0
    }
1417
0
  }
1418
0
  return tokens;
1419
0
}
1420
1421
void GlobalParams::parseNameToUnicode(GList *tokens, GString *fileName,
1422
0
              int line) {
1423
0
  GString *name;
1424
0
  char *tok1, *tok2;
1425
0
  FILE *f;
1426
0
  char buf[256];
1427
0
  int line2;
1428
0
  Unicode u;
1429
1430
0
  if (tokens->getLength() != 2) {
1431
0
    error(errConfig, -1,
1432
0
    "Bad 'nameToUnicode' config file command ({0:t}:{1:d})",
1433
0
    fileName, line);
1434
0
    return;
1435
0
  }
1436
0
  name = (GString *)tokens->get(1);
1437
0
  if (!(f = openFile(name->getCString(), "r"))) {
1438
0
    error(errConfig, -1, "Couldn't open 'nameToUnicode' file '{0:t}'", name);
1439
0
    return;
1440
0
  }
1441
0
  line2 = 1;
1442
0
  while (getLine(buf, sizeof(buf), f)) {
1443
0
    tok1 = strtok(buf, " \t\r\n");
1444
0
    tok2 = strtok(NULL, " \t\r\n");
1445
0
    if (tok1 && tok2) {
1446
0
      sscanf(tok1, "%x", &u);
1447
0
      nameToUnicode->add(tok2, u);
1448
0
    } else {
1449
0
      error(errConfig, -1, "Bad line in 'nameToUnicode' file ({0:t}:{1:d})",
1450
0
      name, line2);
1451
0
    }
1452
0
    ++line2;
1453
0
  }
1454
0
  fclose(f);
1455
0
}
1456
1457
void GlobalParams::parseCIDToUnicode(GList *tokens, GString *fileName,
1458
0
             int line) {
1459
0
  GString *collection, *name, *old;
1460
1461
0
  if (tokens->getLength() != 3) {
1462
0
    error(errConfig, -1,
1463
0
    "Bad 'cidToUnicode' config file command ({0:t}:{1:d})",
1464
0
    fileName, line);
1465
0
    return;
1466
0
  }
1467
0
  collection = (GString *)tokens->get(1);
1468
0
  name = (GString *)tokens->get(2);
1469
0
  if ((old = (GString *)cidToUnicodes->remove(collection))) {
1470
0
    delete old;
1471
0
  }
1472
0
  cidToUnicodes->add(collection->copy(), name->copy());
1473
0
}
1474
1475
void GlobalParams::parseUnicodeToUnicode(GList *tokens, GString *fileName,
1476
0
           int line) {
1477
0
  GString *font, *file, *old;
1478
1479
0
  if (tokens->getLength() != 3) {
1480
0
    error(errConfig, -1,
1481
0
    "Bad 'unicodeToUnicode' config file command ({0:t}:{1:d})",
1482
0
    fileName, line);
1483
0
    return;
1484
0
  }
1485
0
  font = (GString *)tokens->get(1);
1486
0
  file = (GString *)tokens->get(2);
1487
0
  if ((old = (GString *)unicodeToUnicodes->remove(font))) {
1488
0
    delete old;
1489
0
  }
1490
0
  unicodeToUnicodes->add(font->copy(), file->copy());
1491
0
}
1492
1493
void GlobalParams::parseUnicodeMap(GList *tokens, GString *fileName,
1494
0
           int line) {
1495
0
  GString *encodingName, *name, *old;
1496
1497
0
  if (tokens->getLength() != 3) {
1498
0
    error(errConfig, -1, "Bad 'unicodeMap' config file command ({0:t}:{1:d})",
1499
0
    fileName, line);
1500
0
    return;
1501
0
  }
1502
0
  encodingName = (GString *)tokens->get(1);
1503
0
  name = (GString *)tokens->get(2);
1504
0
  if ((old = (GString *)unicodeMaps->remove(encodingName))) {
1505
0
    delete old;
1506
0
  }
1507
0
  unicodeMaps->add(encodingName->copy(), name->copy());
1508
0
}
1509
1510
0
void GlobalParams::parseCMapDir(GList *tokens, GString *fileName, int line) {
1511
0
  GString *collection, *dir;
1512
0
  GList *list;
1513
1514
0
  if (tokens->getLength() != 3) {
1515
0
    error(errConfig, -1, "Bad 'cMapDir' config file command ({0:t}:{1:d})",
1516
0
    fileName, line);
1517
0
    return;
1518
0
  }
1519
0
  collection = (GString *)tokens->get(1);
1520
0
  dir = (GString *)tokens->get(2);
1521
0
  if (!(list = (GList *)cMapDirs->lookup(collection))) {
1522
0
    list = new GList();
1523
0
    cMapDirs->add(collection->copy(), list);
1524
0
  }
1525
0
  list->append(dir->copy());
1526
0
}
1527
1528
void GlobalParams::parseToUnicodeDir(GList *tokens, GString *fileName,
1529
0
             int line) {
1530
0
  if (tokens->getLength() != 2) {
1531
0
    error(errConfig, -1,
1532
0
    "Bad 'toUnicodeDir' config file command ({0:t}:{1:d})",
1533
0
    fileName, line);
1534
0
    return;
1535
0
  }
1536
0
  toUnicodeDirs->append(((GString *)tokens->get(1))->copy());
1537
0
}
1538
1539
void GlobalParams::parseUnicodeRemapping(GList *tokens, GString *fileName,
1540
0
           int line) {
1541
0
  if (tokens->getLength() != 2) {
1542
0
    error(errConfig, -1,
1543
0
    "Bad 'unicodeRemapping' config file command ({0:t}:{1:d})",
1544
0
    fileName, line);
1545
0
    return;
1546
0
  }
1547
0
  unicodeRemapping->parseFile((GString *)tokens->get(1));
1548
0
}
1549
1550
0
void GlobalParams::parseFontFile(GList *tokens, GString *fileName, int line) {
1551
0
  if (tokens->getLength() != 3) {
1552
0
    error(errConfig, -1, "Bad 'fontFile' config file command ({0:t}:{1:d})",
1553
0
    fileName, line);
1554
0
    return;
1555
0
  }
1556
0
  fontFiles->add(((GString *)tokens->get(1))->copy(),
1557
0
     ((GString *)tokens->get(2))->copy());
1558
0
}
1559
1560
0
void GlobalParams::parseFontDir(GList *tokens, GString *fileName, int line) {
1561
0
  if (tokens->getLength() != 2) {
1562
0
    error(errConfig, -1, "Bad 'fontDir' config file command ({0:t}:{1:d})",
1563
0
    fileName, line);
1564
0
    return;
1565
0
  }
1566
0
  fontDirs->append(((GString *)tokens->get(1))->copy());
1567
0
}
1568
1569
void GlobalParams::parseFontFileCC(GList *tokens, GString *fileName,
1570
0
           int line) {
1571
0
  if (tokens->getLength() != 3) {
1572
0
    error(errConfig, -1, "Bad 'fontFileCC' config file command ({0:t}:{1:d})",
1573
0
    fileName, line);
1574
0
    return;
1575
0
  }
1576
0
  ccFontFiles->add(((GString *)tokens->get(1))->copy(),
1577
0
       ((GString *)tokens->get(2))->copy());
1578
0
}
1579
1580
void GlobalParams::parsePSPaperSize(GList *tokens, GString *fileName,
1581
0
            int line) {
1582
0
  GString *tok;
1583
1584
0
  if (tokens->getLength() == 2) {
1585
0
    tok = (GString *)tokens->get(1);
1586
0
    if (!setPSPaperSize(tok->getCString())) {
1587
0
      error(errConfig, -1,
1588
0
      "Bad 'psPaperSize' config file command ({0:s}:{1:d})",
1589
0
      fileName, line);
1590
0
    }
1591
0
  } else if (tokens->getLength() == 3) {
1592
0
    tok = (GString *)tokens->get(1);
1593
0
    psPaperWidth = atoi(tok->getCString());
1594
0
    tok = (GString *)tokens->get(2);
1595
0
    psPaperHeight = atoi(tok->getCString());
1596
0
    psImageableLLX = psImageableLLY = 0;
1597
0
    psImageableURX = psPaperWidth;
1598
0
    psImageableURY = psPaperHeight;
1599
0
  } else {
1600
0
    error(errConfig, -1, "Bad 'psPaperSize' config file command ({0:t}:{1:d})",
1601
0
    fileName, line);
1602
0
  }
1603
0
}
1604
1605
void GlobalParams::parsePSImageableArea(GList *tokens, GString *fileName,
1606
0
          int line) {
1607
0
  if (tokens->getLength() != 5) {
1608
0
    error(errConfig, -1,
1609
0
    "Bad 'psImageableArea' config file command ({0:t}:{1:d})",
1610
0
    fileName, line);
1611
0
    return;
1612
0
  }
1613
0
  psImageableLLX = atoi(((GString *)tokens->get(1))->getCString());
1614
0
  psImageableLLY = atoi(((GString *)tokens->get(2))->getCString());
1615
0
  psImageableURX = atoi(((GString *)tokens->get(3))->getCString());
1616
0
  psImageableURY = atoi(((GString *)tokens->get(4))->getCString());
1617
0
}
1618
1619
0
void GlobalParams::parsePSLevel(GList *tokens, GString *fileName, int line) {
1620
0
  GString *tok;
1621
1622
0
  if (tokens->getLength() != 2) {
1623
0
    error(errConfig, -1, "Bad 'psLevel' config file command ({0:t}:{1:d})",
1624
0
    fileName, line);
1625
0
    return;
1626
0
  }
1627
0
  tok = (GString *)tokens->get(1);
1628
0
  if (!tok->cmp("level1")) {
1629
0
    psLevel = psLevel1;
1630
0
  } else if (!tok->cmp("level1sep")) {
1631
0
    psLevel = psLevel1Sep;
1632
0
  } else if (!tok->cmp("level2")) {
1633
0
    psLevel = psLevel2;
1634
0
  } else if (!tok->cmp("level2gray")) {
1635
0
    psLevel = psLevel2Gray;
1636
0
  } else if (!tok->cmp("level2sep")) {
1637
0
    psLevel = psLevel2Sep;
1638
0
  } else if (!tok->cmp("level3")) {
1639
0
    psLevel = psLevel3;
1640
0
  } else if (!tok->cmp("level3gray")) {
1641
0
    psLevel = psLevel3Gray;
1642
0
  } else if (!tok->cmp("level3Sep")) {
1643
0
    psLevel = psLevel3Sep;
1644
0
  } else {
1645
0
    error(errConfig, -1, "Bad 'psLevel' config file command ({0:t}:{1:d})",
1646
0
    fileName, line);
1647
0
  }
1648
0
}
1649
1650
void GlobalParams::parsePSResidentFont(GList *tokens, GString *fileName,
1651
0
               int line) {
1652
0
  if (tokens->getLength() != 3) {
1653
0
    error(errConfig, -1, "Bad 'psResidentFont' config file command ({0:t}:{1:d})",
1654
0
    fileName, line);
1655
0
    return;
1656
0
  }
1657
0
  psResidentFonts->add(((GString *)tokens->get(1))->copy(),
1658
0
           ((GString *)tokens->get(2))->copy());
1659
0
}
1660
1661
void GlobalParams::parsePSResidentFont16(GList *tokens, GString *fileName,
1662
0
           int line) {
1663
0
  PSFontParam16 *param;
1664
0
  int wMode;
1665
0
  GString *tok;
1666
1667
0
  if (tokens->getLength() != 5) {
1668
0
    error(errConfig, -1, "Bad 'psResidentFont16' config file command ({0:t}:{1:d})",
1669
0
    fileName, line);
1670
0
    return;
1671
0
  }
1672
0
  tok = (GString *)tokens->get(2);
1673
0
  if (!tok->cmp("H")) {
1674
0
    wMode = 0;
1675
0
  } else if (!tok->cmp("V")) {
1676
0
    wMode = 1;
1677
0
  } else {
1678
0
    error(errConfig, -1, "Bad wMode in psResidentFont16 config file command ({1:t}:{2:d})",
1679
0
    fileName, line);
1680
0
    return;
1681
0
  }
1682
0
  param = new PSFontParam16(((GString *)tokens->get(1))->copy(),
1683
0
          wMode,
1684
0
          ((GString *)tokens->get(3))->copy(),
1685
0
          ((GString *)tokens->get(4))->copy());
1686
0
  psResidentFonts16->append(param);
1687
0
}
1688
1689
void GlobalParams::parsePSResidentFontCC(GList *tokens, GString *fileName,
1690
0
           int line) {
1691
0
  PSFontParam16 *param;
1692
0
  int wMode;
1693
0
  GString *tok;
1694
1695
0
  if (tokens->getLength() != 5) {
1696
0
    error(errConfig, -1, "Bad 'psResidentFontCC' config file command ({0:t}:{1:d})",
1697
0
    fileName, line);
1698
0
    return;
1699
0
  }
1700
0
  tok = (GString *)tokens->get(2);
1701
0
  if (!tok->cmp("H")) {
1702
0
    wMode = 0;
1703
0
  } else if (!tok->cmp("V")) {
1704
0
    wMode = 1;
1705
0
  } else {
1706
0
    error(errConfig, -1, "Bad wMode in psResidentFontCC config file command ({1:t}:{2:d})",
1707
0
    fileName, line);
1708
0
    return;
1709
0
  }
1710
0
  param = new PSFontParam16(((GString *)tokens->get(1))->copy(),
1711
0
          wMode,
1712
0
          ((GString *)tokens->get(3))->copy(),
1713
0
          ((GString *)tokens->get(4))->copy());
1714
0
  psResidentFontsCC->append(param);
1715
0
}
1716
1717
0
void GlobalParams::parseTextEOL(GList *tokens, GString *fileName, int line) {
1718
0
  GString *tok;
1719
1720
0
  if (tokens->getLength() != 2) {
1721
0
    error(errConfig, -1, "Bad 'textEOL' config file command ({0:t}:{1:d})",
1722
0
    fileName, line);
1723
0
    return;
1724
0
  }
1725
0
  tok = (GString *)tokens->get(1);
1726
0
  if (!tok->cmp("unix")) {
1727
0
    textEOL = eolUnix;
1728
0
  } else if (!tok->cmp("dos")) {
1729
0
    textEOL = eolDOS;
1730
0
  } else if (!tok->cmp("mac")) {
1731
0
    textEOL = eolMac;
1732
0
  } else {
1733
0
    error(errConfig, -1, "Bad 'textEOL' config file command ({0:t}:{1:d})",
1734
0
    fileName, line);
1735
0
  }
1736
0
}
1737
1738
void GlobalParams::parseStrokeAdjust(GList *tokens, GString *fileName,
1739
0
             int line) {
1740
0
  GString *tok;
1741
1742
0
  if (tokens->getLength() != 2) {
1743
0
    error(errConfig, -1,
1744
0
    "Bad 'strokeAdjust' config file command ({0:t}:{1:d})",
1745
0
    fileName, line);
1746
0
    return;
1747
0
  }
1748
0
  tok = (GString *)tokens->get(1);
1749
0
  if (!tok->cmp("no")) {
1750
0
    strokeAdjust = strokeAdjustOff;
1751
0
  } else if (!tok->cmp("yes")) {
1752
0
    strokeAdjust = strokeAdjustNormal;
1753
0
  } else if (!tok->cmp("cad")) {
1754
0
    strokeAdjust = strokeAdjustCAD;
1755
0
  } else {
1756
0
    error(errConfig, -1,
1757
0
    "Bad 'strokeAdjust' config file command ({0:t}:{1:d})",
1758
0
    fileName, line);
1759
0
  }
1760
0
}
1761
1762
void GlobalParams::parseScreenType(GList *tokens, GString *fileName,
1763
0
           int line) {
1764
0
  GString *tok;
1765
1766
0
  if (tokens->getLength() != 2) {
1767
0
    error(errConfig, -1, "Bad 'screenType' config file command ({0:t}:{1:d})",
1768
0
    fileName, line);
1769
0
    return;
1770
0
  }
1771
0
  tok = (GString *)tokens->get(1);
1772
0
  if (!tok->cmp("dispersed")) {
1773
0
    screenType = screenDispersed;
1774
0
  } else if (!tok->cmp("clustered")) {
1775
0
    screenType = screenClustered;
1776
0
  } else if (!tok->cmp("stochasticClustered")) {
1777
0
    screenType = screenStochasticClustered;
1778
0
  } else {
1779
0
    error(errConfig, -1, "Bad 'screenType' config file command ({0:t}:{1:d})",
1780
0
    fileName, line);
1781
0
  }
1782
0
}
1783
1784
0
void GlobalParams::parseDropFont(GList *tokens, GString *fileName, int line) {
1785
0
  if (tokens->getLength() != 2) {
1786
0
    error(errConfig, -1, "Bad 'dropFont' config file command ({0:t}:{1:d})",
1787
0
    fileName, line);
1788
0
    return;
1789
0
  }
1790
0
  droppedFonts->add(((GString *)tokens->get(1))->copy(), 1);
1791
0
}
1792
1793
0
void GlobalParams::parseBind(GList *tokens, GString *fileName, int line) {
1794
0
  KeyBinding *binding;
1795
0
  GList *cmds;
1796
0
  int code, mods, context, i;
1797
1798
0
  if (tokens->getLength() < 4) {
1799
0
    error(errConfig, -1, "Bad 'bind' config file command ({0:t}:{1:d})",
1800
0
    fileName, line);
1801
0
    return;
1802
0
  }
1803
0
  if (!parseKey((GString *)tokens->get(1), (GString *)tokens->get(2),
1804
0
    &code, &mods, &context,
1805
0
    "bind", tokens, fileName, line)) {
1806
0
    return;
1807
0
  }
1808
0
  for (i = 0; i < keyBindings->getLength(); ++i) {
1809
0
    binding = (KeyBinding *)keyBindings->get(i);
1810
0
    if (binding->code == code &&
1811
0
  binding->mods == mods &&
1812
0
  binding->context == context) {
1813
0
      delete (KeyBinding *)keyBindings->del(i);
1814
0
      break;
1815
0
    }
1816
0
  }
1817
0
  cmds = new GList();
1818
0
  for (i = 3; i < tokens->getLength(); ++i) {
1819
0
    cmds->append(((GString *)tokens->get(i))->copy());
1820
0
  }
1821
0
  keyBindings->append(new KeyBinding(code, mods, context, cmds));
1822
0
}
1823
1824
0
void GlobalParams::parseUnbind(GList *tokens, GString *fileName, int line) {
1825
0
  KeyBinding *binding;
1826
0
  int code, mods, context, i;
1827
1828
0
  if (tokens->getLength() != 3) {
1829
0
    error(errConfig, -1, "Bad 'unbind' config file command ({0:t}:{1:d})",
1830
0
    fileName, line);
1831
0
    return;
1832
0
  }
1833
0
  if (!parseKey((GString *)tokens->get(1), (GString *)tokens->get(2),
1834
0
    &code, &mods, &context,
1835
0
    "unbind", tokens, fileName, line)) {
1836
0
    return;
1837
0
  }
1838
0
  for (i = 0; i < keyBindings->getLength(); ++i) {
1839
0
    binding = (KeyBinding *)keyBindings->get(i);
1840
0
    if (binding->code == code &&
1841
0
  binding->mods == mods &&
1842
0
  binding->context == context) {
1843
0
      delete (KeyBinding *)keyBindings->del(i);
1844
0
      break;
1845
0
    }
1846
0
  }
1847
0
}
1848
1849
GBool GlobalParams::parseKey(GString *modKeyStr, GString *contextStr,
1850
           int *code, int *mods, int *context,
1851
           const char *cmdName,
1852
0
           GList *tokens, GString *fileName, int line) {
1853
0
  char *p0;
1854
0
  int btn;
1855
1856
0
  *mods = xpdfKeyModNone;
1857
0
  p0 = modKeyStr->getCString();
1858
0
  while (1) {
1859
0
    if (!strncmp(p0, "shift-", 6)) {
1860
0
      *mods |= xpdfKeyModShift;
1861
0
      p0 += 6;
1862
0
    } else if (!strncmp(p0, "ctrl-", 5)) {
1863
0
      *mods |= xpdfKeyModCtrl;
1864
0
      p0 += 5;
1865
0
    } else if (!strncmp(p0, "alt-", 4)) {
1866
0
      *mods |= xpdfKeyModAlt;
1867
0
      p0 += 4;
1868
0
    } else {
1869
0
      break;
1870
0
    }
1871
0
  }
1872
1873
0
  if (!strcmp(p0, "space")) {
1874
0
    *code = ' ';
1875
0
  } else if (!strcmp(p0, "tab")) {
1876
0
    *code = xpdfKeyCodeTab;
1877
0
  } else if (!strcmp(p0, "return")) {
1878
0
    *code = xpdfKeyCodeReturn;
1879
0
  } else if (!strcmp(p0, "enter")) {
1880
0
    *code = xpdfKeyCodeEnter;
1881
0
  } else if (!strcmp(p0, "backspace")) {
1882
0
    *code = xpdfKeyCodeBackspace;
1883
0
  } else if (!strcmp(p0, "esc")) {
1884
0
    *code = xpdfKeyCodeEsc;
1885
0
  } else if (!strcmp(p0, "insert")) {
1886
0
    *code = xpdfKeyCodeInsert;
1887
0
  } else if (!strcmp(p0, "delete")) {
1888
0
    *code = xpdfKeyCodeDelete;
1889
0
  } else if (!strcmp(p0, "home")) {
1890
0
    *code = xpdfKeyCodeHome;
1891
0
  } else if (!strcmp(p0, "end")) {
1892
0
    *code = xpdfKeyCodeEnd;
1893
0
  } else if (!strcmp(p0, "pgup")) {
1894
0
    *code = xpdfKeyCodePgUp;
1895
0
  } else if (!strcmp(p0, "pgdn")) {
1896
0
    *code = xpdfKeyCodePgDn;
1897
0
  } else if (!strcmp(p0, "left")) {
1898
0
    *code = xpdfKeyCodeLeft;
1899
0
  } else if (!strcmp(p0, "right")) {
1900
0
    *code = xpdfKeyCodeRight;
1901
0
  } else if (!strcmp(p0, "up")) {
1902
0
    *code = xpdfKeyCodeUp;
1903
0
  } else if (!strcmp(p0, "down")) {
1904
0
    *code = xpdfKeyCodeDown;
1905
0
  } else if (p0[0] == 'f' && p0[1] >= '1' && p0[1] <= '9' && !p0[2]) {
1906
0
    *code = xpdfKeyCodeF1 + (p0[1] - '1');
1907
0
  } else if (p0[0] == 'f' &&
1908
0
       ((p0[1] >= '1' && p0[1] <= '2' && p0[2] >= '0' && p0[2] <= '9') ||
1909
0
        (p0[1] == '3' && p0[2] >= '0' && p0[2] <= '5')) &&
1910
0
       !p0[3]) {
1911
0
    *code = xpdfKeyCodeF1 + 10 * (p0[1] - '0') + (p0[2] - '0') - 1;
1912
0
  } else if (!strncmp(p0, "mousePress", 10) &&
1913
0
       p0[10] >= '0' && p0[10] <= '9' &&
1914
0
       (!p0[11] || (p0[11] >= '0' && p0[11] <= '9' && !p0[12])) &&
1915
0
       (btn = atoi(p0 + 10)) >= 1 && btn <= 32) {
1916
0
    *code = xpdfKeyCodeMousePress1 + btn - 1;
1917
0
  } else if (!strncmp(p0, "mouseRelease", 12) &&
1918
0
       p0[12] >= '0' && p0[12] <= '9' &&
1919
0
       (!p0[13] || (p0[13] >= '0' && p0[13] <= '9' && !p0[14])) &&
1920
0
       (btn = atoi(p0 + 12)) >= 1 && btn <= 32) {
1921
0
    *code = xpdfKeyCodeMouseRelease1 + btn - 1;
1922
0
  } else if (!strncmp(p0, "mouseClick", 10) &&
1923
0
       p0[10] >= '0' && p0[10] <= '9' &&
1924
0
       (!p0[11] || (p0[11] >= '0' && p0[11] <= '9' && !p0[12])) &&
1925
0
       (btn = atoi(p0 + 10)) >= 1 && btn <= 32) {
1926
0
    *code = xpdfKeyCodeMouseClick1 + btn - 1;
1927
0
  } else if (!strncmp(p0, "mouseDoubleClick", 16) &&
1928
0
       p0[16] >= '0' && p0[16] <= '9' &&
1929
0
       (!p0[17] || (p0[17] >= '0' && p0[17] <= '9' && !p0[18])) &&
1930
0
       (btn = atoi(p0 + 16)) >= 1 && btn <= 32) {
1931
0
    *code = xpdfKeyCodeMouseDoubleClick1 + btn - 1;
1932
0
  } else if (!strncmp(p0, "mouseTripleClick", 16) &&
1933
0
       p0[16] >= '0' && p0[16] <= '9' &&
1934
0
       (!p0[17] || (p0[17] >= '0' && p0[17] <= '9' && !p0[18])) &&
1935
0
       (btn = atoi(p0 + 16)) >= 1 && btn <= 32) {
1936
0
    *code = xpdfKeyCodeMouseTripleClick1 + btn - 1;
1937
0
  } else if (*p0 >= 0x20 && *p0 <= 0x7e && !p0[1]) {
1938
0
    *code = (int)*p0;
1939
0
  } else {
1940
0
    error(errConfig, -1,
1941
0
    "Bad key/modifier in '{0:s}' config file command ({1:t}:{2:d})",
1942
0
    cmdName, fileName, line);
1943
0
    return gFalse;
1944
0
  }
1945
1946
0
  p0 = contextStr->getCString();
1947
0
  if (!strcmp(p0, "any")) {
1948
0
    *context = xpdfKeyContextAny;
1949
0
  } else {
1950
0
    *context = xpdfKeyContextAny;
1951
0
    while (1) {
1952
0
      if (!strncmp(p0, "fullScreen", 10)) {
1953
0
  *context |= xpdfKeyContextFullScreen;
1954
0
  p0 += 10;
1955
0
      } else if (!strncmp(p0, "window", 6)) {
1956
0
  *context |= xpdfKeyContextWindow;
1957
0
  p0 += 6;
1958
0
      } else if (!strncmp(p0, "continuous", 10)) {
1959
0
  *context |= xpdfKeyContextContinuous;
1960
0
  p0 += 10;
1961
0
      } else if (!strncmp(p0, "singlePage", 10)) {
1962
0
  *context |= xpdfKeyContextSinglePage;
1963
0
  p0 += 10;
1964
0
      } else if (!strncmp(p0, "overLink", 8)) {
1965
0
  *context |= xpdfKeyContextOverLink;
1966
0
  p0 += 8;
1967
0
      } else if (!strncmp(p0, "offLink", 7)) {
1968
0
  *context |= xpdfKeyContextOffLink;
1969
0
  p0 += 7;
1970
0
      } else if (!strncmp(p0, "outline", 7)) {
1971
0
  *context |= xpdfKeyContextOutline;
1972
0
  p0 += 7;
1973
0
      } else if (!strncmp(p0, "mainWin", 7)) {
1974
0
  *context |= xpdfKeyContextMainWin;
1975
0
  p0 += 7;
1976
0
      } else if (!strncmp(p0, "scrLockOn", 9)) {
1977
0
  *context |= xpdfKeyContextScrLockOn;
1978
0
  p0 += 9;
1979
0
      } else if (!strncmp(p0, "scrLockOff", 10)) {
1980
0
  *context |= xpdfKeyContextScrLockOff;
1981
0
  p0 += 10;
1982
0
      } else {
1983
0
  error(errConfig, -1,
1984
0
        "Bad context in '{0:s}' config file command ({1:t}:{2:d})",
1985
0
        cmdName, fileName, line);
1986
0
  return gFalse;
1987
0
      }
1988
0
      if (!*p0) {
1989
0
  break;
1990
0
      }
1991
0
      if (*p0 != ',') {
1992
0
  error(errConfig, -1,
1993
0
        "Bad context in '{0:s}' config file command ({1:t}:{2:d})",
1994
0
        cmdName, fileName, line);
1995
0
  return gFalse;
1996
0
      }
1997
0
      ++p0;
1998
0
    }
1999
0
  }
2000
2001
0
  return gTrue;
2002
0
}
2003
2004
void GlobalParams::parsePopupMenuCmd(GList *tokens,
2005
0
             GString *fileName, int line) {
2006
0
  GList *cmds;
2007
0
  int i;
2008
2009
0
  if (tokens->getLength() < 3) {
2010
0
    error(errConfig, -1,
2011
0
    "Bad 'popupMenuCmd' config file command ({0:t}:{1:d})",
2012
0
    fileName, line);
2013
0
    return;
2014
0
  }
2015
0
  cmds = new GList();
2016
0
  for (i = 2; i < tokens->getLength(); ++i) {
2017
0
    cmds->append(((GString *)tokens->get(i))->copy());
2018
0
  }
2019
0
  popupMenuCmds->append(new PopupMenuCmd(((GString *)tokens->get(1))->copy(),
2020
0
           cmds));
2021
0
}
2022
2023
void GlobalParams::parseZoomScaleFactor(GList *tokens,
2024
0
          GString *fileName, int line) {
2025
0
  if (tokens->getLength() != 2) {
2026
0
    error(errConfig, -1, "Bad 'zoomScaleFactor' config file command ({0:t}:{1:d})",
2027
0
    fileName, line);
2028
0
    return;
2029
0
  }
2030
0
  GString *tok = (GString *)tokens->get(1);
2031
0
  if (tok->getLength() == 0) {
2032
0
    error(errConfig, -1, "Bad 'zoomScaleFactor' config file command ({0:t}:{1:d})",
2033
0
    fileName, line);
2034
0
    return;
2035
0
  }
2036
0
  if (tok->cmp("actual") == 0) {
2037
0
    zoomScaleFactor = -1;
2038
0
  } else {
2039
0
    for (int i = 0; i < tok->getLength(); ++i) {
2040
0
      if (!((tok->getChar(i) >= '0' && tok->getChar(i) <= '9') ||
2041
0
      tok->getChar(i) == '.')) {
2042
0
  error(errConfig, -1, "Bad 'zoomScaleFactor' config file command ({0:t}:{1:d})",
2043
0
        fileName, line);
2044
0
  return;
2045
0
      }
2046
0
    }
2047
0
    zoomScaleFactor = atof(tok->getCString());
2048
0
  }
2049
0
}
2050
2051
void GlobalParams::parseZoomValues(GList *tokens,
2052
0
           GString *fileName, int line) {
2053
0
  if (tokens->getLength() < 2) {
2054
0
    error(errConfig, -1, "Bad 'zoomValues' config file command ({0:t}:{1:d})",
2055
0
    fileName, line);
2056
0
    return;
2057
0
  }
2058
0
  for (int i = 1; i < tokens->getLength(); ++i) {
2059
0
    GString *tok = (GString *)tokens->get(i);
2060
0
    for (int j = 0; j < tok->getLength(); ++j) {
2061
0
      if (tok->getChar(j) < '0' || tok->getChar(j) > '9') {
2062
0
  error(errConfig, -1, "Bad 'zoomValues' config file command ({0:t}:{1:d})",
2063
0
        fileName, line);
2064
0
  return;
2065
0
      }
2066
0
    }
2067
0
  }
2068
0
  deleteGList(zoomValues, GString);
2069
0
  zoomValues = new GList();
2070
0
  for (int i = 1; i < tokens->getLength(); ++i) {
2071
0
    GString *tok = (GString *)tokens->get(i);
2072
0
    zoomValues->append(tok->copy());
2073
0
  }
2074
0
}
2075
2076
void GlobalParams::parseYesNo(const char *cmdName, GBool *flag,
2077
0
            GList *tokens, GString *fileName, int line) {
2078
0
  GString *tok;
2079
2080
0
  if (tokens->getLength() != 2) {
2081
0
    error(errConfig, -1, "Bad '{0:s}' config file command ({1:t}:{2:d})",
2082
0
    cmdName, fileName, line);
2083
0
    return;
2084
0
  }
2085
0
  tok = (GString *)tokens->get(1);
2086
0
  if (!parseYesNo2(tok->getCString(), flag)) {
2087
0
    error(errConfig, -1, "Bad '{0:s}' config file command ({1:t}:{2:d})",
2088
0
    cmdName, fileName, line);
2089
0
  }
2090
0
}
2091
2092
3.17k
GBool GlobalParams::parseYesNo2(char *token, GBool *flag) {
2093
3.17k
  if (!strcmp(token, "yes")) {
2094
3.17k
    *flag = gTrue;
2095
3.17k
  } else if (!strcmp(token, "no")) {
2096
0
    *flag = gFalse;
2097
0
  } else {
2098
0
    return gFalse;
2099
0
  }
2100
3.17k
  return gTrue;
2101
3.17k
}
2102
2103
void GlobalParams::parseString(const char *cmdName, GString **s,
2104
0
             GList *tokens, GString *fileName, int line) {
2105
0
  if (tokens->getLength() != 2) {
2106
0
    error(errConfig, -1, "Bad '{0:s}' config file command ({1:t}:{2:d})",
2107
0
    cmdName, fileName, line);
2108
0
    return;
2109
0
  }
2110
0
  if (*s) {
2111
0
    delete *s;
2112
0
  }
2113
0
  *s = ((GString *)tokens->get(1))->copy();
2114
0
}
2115
2116
void GlobalParams::parseInteger(const char *cmdName, int *val,
2117
0
        GList *tokens, GString *fileName, int line) {
2118
0
  GString *tok;
2119
0
  int i;
2120
2121
0
  if (tokens->getLength() != 2) {
2122
0
    error(errConfig, -1, "Bad '{0:s}' config file command ({1:t}:{2:d})",
2123
0
    cmdName, fileName, line);
2124
0
    return;
2125
0
  }
2126
0
  tok = (GString *)tokens->get(1);
2127
0
  if (tok->getLength() == 0) {
2128
0
    error(errConfig, -1, "Bad '{0:s}' config file command ({1:t}:{2:d})",
2129
0
    cmdName, fileName, line);
2130
0
    return;
2131
0
  }
2132
0
  if (tok->getChar(0) == '-') {
2133
0
    i = 1;
2134
0
  } else {
2135
0
    i = 0;
2136
0
  }
2137
0
  for (; i < tok->getLength(); ++i) {
2138
0
    if (tok->getChar(i) < '0' || tok->getChar(i) > '9') {
2139
0
      error(errConfig, -1, "Bad '{0:s}' config file command ({1:t}:{2:d})",
2140
0
      cmdName, fileName, line);
2141
0
      return;
2142
0
    }
2143
0
  }
2144
0
  *val = atoi(tok->getCString());
2145
0
}
2146
2147
void GlobalParams::parseFloat(const char *cmdName, double *val,
2148
0
            GList *tokens, GString *fileName, int line) {
2149
0
  GString *tok;
2150
0
  int i;
2151
2152
0
  if (tokens->getLength() != 2) {
2153
0
    error(errConfig, -1, "Bad '{0:s}' config file command ({1:t}:{2:d})",
2154
0
    cmdName, fileName, line);
2155
0
    return;
2156
0
  }
2157
0
  tok = (GString *)tokens->get(1);
2158
0
  if (tok->getLength() == 0) {
2159
0
    error(errConfig, -1, "Bad '{0:s}' config file command ({1:t}:{2:d})",
2160
0
    cmdName, fileName, line);
2161
0
    return;
2162
0
  }
2163
0
  if (tok->getChar(0) == '-') {
2164
0
    i = 1;
2165
0
  } else {
2166
0
    i = 0;
2167
0
  }
2168
0
  for (; i < tok->getLength(); ++i) {
2169
0
    if (!((tok->getChar(i) >= '0' && tok->getChar(i) <= '9') ||
2170
0
    tok->getChar(i) == '.')) {
2171
0
      error(errConfig, -1, "Bad '{0:s}' config file command ({1:t}:{2:d})",
2172
0
      cmdName, fileName, line);
2173
0
      return;
2174
0
    }
2175
0
  }
2176
0
  *val = atof(tok->getCString());
2177
0
}
2178
2179
3.17k
GlobalParams::~GlobalParams() {
2180
3.17k
  GHashIter *iter;
2181
3.17k
  GString *key;
2182
3.17k
  GList *list;
2183
2184
3.17k
  freeBuiltinFontTables();
2185
2186
3.17k
  delete macRomanReverseMap;
2187
2188
3.17k
  delete baseDir;
2189
3.17k
  deleteGHash(configFileVars, GString);
2190
3.17k
  delete nameToUnicode;
2191
3.17k
  deleteGHash(cidToUnicodes, GString);
2192
3.17k
  deleteGHash(unicodeToUnicodes, GString);
2193
3.17k
  deleteGHash(residentUnicodeMaps, UnicodeMap);
2194
3.17k
  deleteGHash(unicodeMaps, GString);
2195
3.17k
  deleteGList(toUnicodeDirs, GString);
2196
3.17k
  delete unicodeRemapping;
2197
3.17k
  deleteGHash(fontFiles, GString);
2198
3.17k
  deleteGList(fontDirs, GString);
2199
3.17k
  deleteGHash(ccFontFiles, GString);
2200
3.17k
  deleteGHash(base14SysFonts, Base14FontInfo);
2201
3.17k
  delete sysFonts;
2202
3.17k
  deleteGHash(psResidentFonts, GString);
2203
3.17k
  deleteGList(psResidentFonts16, PSFontParam16);
2204
3.17k
  deleteGList(psResidentFontsCC, PSFontParam16);
2205
3.17k
  delete textEncoding;
2206
3.17k
  delete initialZoom;
2207
3.17k
  deleteGList(zoomValues, GString);
2208
3.17k
  delete initialDisplayMode;
2209
3.17k
  delete initialSelectMode;
2210
3.17k
  if (paperColor) {
2211
3.17k
    delete paperColor;
2212
3.17k
  }
2213
3.17k
  if (matteColor) {
2214
3.17k
    delete matteColor;
2215
3.17k
  }
2216
3.17k
  if (fullScreenMatteColor) {
2217
3.17k
    delete fullScreenMatteColor;
2218
3.17k
  }
2219
3.17k
  if (selectionColor) {
2220
3.17k
    delete selectionColor;
2221
3.17k
  }
2222
3.17k
  if (launchCommand) {
2223
0
    delete launchCommand;
2224
0
  }
2225
3.17k
  if (movieCommand) {
2226
0
    delete movieCommand;
2227
0
  }
2228
3.17k
  if (defaultPrinter) {
2229
0
    delete defaultPrinter;
2230
0
  }
2231
3.17k
  delete droppedFonts;
2232
3.17k
  deleteGList(keyBindings, KeyBinding);
2233
3.17k
  deleteGList(popupMenuCmds, PopupMenuCmd);
2234
3.17k
  delete pagesFile;
2235
3.17k
  delete tabStateFile;
2236
3.17k
  delete sessionFile;
2237
3.17k
  delete debugLogFile;
2238
2239
3.17k
  cMapDirs->startIter(&iter);
2240
3.17k
  while (cMapDirs->getNext(&iter, &key, (void **)&list)) {
2241
0
    deleteGList(list, GString);
2242
0
  }
2243
3.17k
  delete cMapDirs;
2244
2245
3.17k
  delete cidToUnicodeCache;
2246
3.17k
  delete unicodeToUnicodeCache;
2247
3.17k
  delete unicodeMapCache;
2248
3.17k
  delete cMapCache;
2249
2250
3.17k
#if MULTITHREADED
2251
3.17k
  gDestroyMutex(&mutex);
2252
3.17k
  gDestroyMutex(&unicodeMapCacheMutex);
2253
3.17k
  gDestroyMutex(&cMapCacheMutex);
2254
3.17k
#endif
2255
3.17k
}
2256
2257
//------------------------------------------------------------------------
2258
2259
0
void GlobalParams::setBaseDir(const char *dir) {
2260
0
  delete baseDir;
2261
0
  baseDir = new GString(dir);
2262
0
}
2263
2264
#ifdef _WIN32
2265
static void getWinFontDir(char *winFontDir) {
2266
  HMODULE shell32Lib;
2267
  BOOL (__stdcall *SHGetSpecialFolderPathFunc)(HWND hwndOwner,
2268
                 LPSTR lpszPath,
2269
                 int nFolder,
2270
                 BOOL fCreate);
2271
  char *p;
2272
  int i;
2273
2274
  // SHGetSpecialFolderPath isn't available in older versions of
2275
  // shell32.dll (Win95 and WinNT4), so do a dynamic load
2276
  winFontDir[0] = '\0';
2277
  if ((shell32Lib = LoadLibraryA("shell32.dll"))) {
2278
    if ((SHGetSpecialFolderPathFunc = 
2279
   (BOOL (__stdcall *)(HWND hwndOwner, LPSTR lpszPath,
2280
           int nFolder, BOOL fCreate))
2281
   GetProcAddress(shell32Lib, "SHGetSpecialFolderPathA"))) {
2282
      if (!(*SHGetSpecialFolderPathFunc)(NULL, winFontDir,
2283
           CSIDL_FONTS, FALSE)) {
2284
  winFontDir[0] = '\0';
2285
      }
2286
      // kludge: Terminal Server changes CSIDL_FONTS to something like
2287
      // "C:\Users\whatever\Windows\Fonts", which doesn't actually
2288
      // contain any fonts -- kill that, so we hit the fallback code
2289
      // below.
2290
      for (p = winFontDir; *p; ++p) {
2291
  if (!strncasecmp(p, "\\Users\\", 7)) {
2292
    winFontDir[0] = '\0';
2293
    break;
2294
  }
2295
      }
2296
    }
2297
    FreeLibrary(shell32Lib);
2298
  }
2299
  // if something went wrong, or we're on a Terminal Server, try using
2300
  // %SYSTEMROOT%\Fonts
2301
  if (!winFontDir[0]) {
2302
    GetSystemWindowsDirectoryA(winFontDir, MAX_PATH - 6);
2303
    winFontDir[MAX_PATH - 7] = '\0';
2304
    i = (int)strlen(winFontDir);
2305
    if (winFontDir[i-1] != '\\') {
2306
      winFontDir[i++] = '\\';
2307
    }
2308
    strcpy(winFontDir + i, "Fonts");
2309
  }
2310
}
2311
#endif
2312
2313
#ifdef __APPLE__
2314
// Apple dfonts and ttc fonts seem to randomly and interchangeably use
2315
// space and hyphen, and sometimes drop the separator entirely.
2316
static GBool macFontNameMatches(GString *name1, const char *name2) {
2317
  const char *p1, *p2;
2318
  char c1, c2;
2319
2320
  p1 = name1->getCString();
2321
  p2 = name2;
2322
  while (*p1 && *p2) {
2323
    c1 = *p1;
2324
    c2 = *p2;
2325
    if (c2 == ' ') {
2326
      // * space or hyphen matches a space in the pattern
2327
      // * separators can also be dropped, in which case we move to
2328
      //   the next char in the pattern
2329
      if (c1 == ' ' || c1 == '-') {
2330
  ++p1;
2331
      }
2332
    } else {
2333
      if (c1 != c2) {
2334
  return gFalse;
2335
      }
2336
      ++p1;
2337
    }
2338
    ++p2;
2339
  }
2340
  if (*p1 || *p2) {
2341
    return gFalse;
2342
  }
2343
  return gTrue;
2344
}
2345
#endif
2346
2347
3.17k
void GlobalParams::setupBaseFonts(const char *dir) {
2348
3.17k
  GString *fontName;
2349
3.17k
  GString *fileName;
2350
3.17k
  int fontNum;
2351
3.17k
  const char *s;
2352
3.17k
  Base14FontInfo *base14;
2353
#ifdef _WIN32
2354
  char winFontDir[MAX_PATH];
2355
#endif
2356
#ifdef __APPLE__
2357
  static const char *macFontExts[3] = { "dfont", "ttc", "ttf" };
2358
  GList *dfontFontNames;
2359
  GBool found;
2360
  int k;
2361
#endif
2362
3.17k
  FILE *f;
2363
3.17k
  int i, j;
2364
2365
#ifdef _WIN32
2366
  getWinFontDir(winFontDir);
2367
#endif
2368
#ifdef __APPLE__
2369
  dfontFontNames = NULL;
2370
#endif
2371
47.6k
  for (i = 0; displayFontTab[i].name; ++i) {
2372
44.4k
    if (fontFiles->lookup(displayFontTab[i].name)) {
2373
0
      continue;
2374
0
    }
2375
44.4k
    fontName = new GString(displayFontTab[i].name);
2376
44.4k
    fileName = NULL;
2377
44.4k
    fontNum = 0;
2378
44.4k
    if (dir) {
2379
0
      fileName = appendToPath(new GString(dir), displayFontTab[i].t1FileName);
2380
0
      if ((f = fopen(fileName->getCString(), "rb"))) {
2381
0
  fclose(f);
2382
0
      } else {
2383
0
  delete fileName;
2384
0
  fileName = NULL;
2385
0
      }
2386
0
    }
2387
#ifdef _WIN32
2388
    if (!fileName && winFontDir[0] && displayFontTab[i].ttFileName) {
2389
      fileName = appendToPath(new GString(winFontDir),
2390
            displayFontTab[i].ttFileName);
2391
      if ((f = fopen(fileName->getCString(), "rb"))) {
2392
  fclose(f);
2393
      } else {
2394
  delete fileName;
2395
  fileName = NULL;
2396
      }
2397
    }
2398
#endif
2399
#ifdef __APPLE__
2400
    // Check for Mac OS X system fonts.
2401
    s = displayFontTab[i].macFileName;
2402
    if (dfontFontNames && i > 0 &&
2403
  (!s || strcmp(s, displayFontTab[i-1].macFileName))) {
2404
      deleteGList(dfontFontNames, GString);
2405
      dfontFontNames = NULL;
2406
    }
2407
    if (!fileName && s) {
2408
      for (j = 0; j < 3; ++j) {
2409
  fileName = GString::format("{0:s}/{1:s}.{2:s}",
2410
           macSystemFontPath, s, macFontExts[j]);
2411
  if (!(f = fopen(fileName->getCString(), "rb"))) {
2412
    delete fileName;
2413
    fileName = NULL;
2414
  } else {
2415
    fclose(f);
2416
    found = gFalse;
2417
    // for .dfont or .ttc, we need to scan the font list
2418
    if (j < 2) {
2419
      if (!dfontFontNames) {
2420
        dfontFontNames =
2421
            FoFiIdentifier::getFontList(fileName->getCString());
2422
      }
2423
      if (dfontFontNames) {
2424
        for (k = 0; k < dfontFontNames->getLength(); ++k) {
2425
    if (macFontNameMatches((GString *)dfontFontNames->get(k),
2426
               displayFontTab[i].macFontName)) {
2427
      fontNum = k;
2428
      found = gTrue;
2429
      break;
2430
    }
2431
        }
2432
      }
2433
    // for .ttf, we just use the font
2434
    } else {
2435
      found = gTrue;
2436
    }
2437
    if (!found) {
2438
      delete fileName;
2439
      fileName = NULL;
2440
    }
2441
    break;
2442
  }
2443
      }
2444
    }
2445
#endif // __APPLE__
2446
    // On Linux, this checks the "standard" ghostscript font
2447
    // directories.  On Windows, it checks the "standard" system font
2448
    // directories (because SHGetSpecialFolderPath(CSIDL_FONTS)
2449
    // doesn't work on Win 2k Server or Win2003 Server, or with older
2450
    // versions of shell32.dll).
2451
#ifdef _WIN32
2452
    s = displayFontTab[i].ttFileName;
2453
#else
2454
44.4k
    s = displayFontTab[i].t1FileName;
2455
44.4k
#endif
2456
44.4k
    if (!fileName && s) {
2457
266k
      for (j = 0; !fileName && displayFontDirs[j]; ++j) {
2458
222k
  fileName = appendToPath(new GString(displayFontDirs[j]), s);
2459
222k
  if ((f = fopen(fileName->getCString(), "rb"))) {
2460
0
    fclose(f);
2461
222k
  } else {
2462
222k
    delete fileName;
2463
222k
    fileName = NULL;
2464
222k
  }
2465
222k
      }
2466
44.4k
    }
2467
44.4k
    if (!fileName) {
2468
44.4k
      delete fontName;
2469
44.4k
      continue;
2470
44.4k
    }
2471
0
    base14SysFonts->add(fontName, new Base14FontInfo(fileName, fontNum, 0));
2472
0
  }
2473
#ifdef __APPLE__
2474
  if (dfontFontNames) {
2475
    deleteGList(dfontFontNames, GString);
2476
  }
2477
#endif
2478
47.6k
  for (i = 0; displayFontTab[i].name; ++i) {
2479
44.4k
    if (!base14SysFonts->lookup(displayFontTab[i].name) &&
2480
44.4k
  !fontFiles->lookup(displayFontTab[i].name)) {
2481
44.4k
      if (displayFontTab[i].obliqueFont &&
2482
44.4k
    ((base14 = (Base14FontInfo *)base14SysFonts
2483
12.7k
                   ->lookup(displayFontTab[i].obliqueFont)))) {
2484
0
  base14SysFonts->add(
2485
0
          new GString(displayFontTab[i].name),
2486
0
    new Base14FontInfo(base14->fileName->copy(),
2487
0
           base14->fontNum,
2488
0
           displayFontTab[i].obliqueFactor));
2489
44.4k
      } else {
2490
44.4k
  error(errConfig, -1, "No display font for '{0:s}'",
2491
44.4k
        displayFontTab[i].name);
2492
44.4k
      }
2493
44.4k
    }
2494
44.4k
  }
2495
#ifdef _WIN32
2496
  if (winFontDir[0]) {
2497
    sysFonts->scanWindowsFonts(winFontDir);
2498
  }
2499
#endif
2500
#if HAVE_FONTCONFIG
2501
  sysFonts->scanFontconfigFonts();
2502
#endif
2503
3.17k
}
2504
2505
//------------------------------------------------------------------------
2506
// accessors
2507
//------------------------------------------------------------------------
2508
2509
0
CharCode GlobalParams::getMacRomanCharCode(char *charName) {
2510
  // no need to lock - macRomanReverseMap is constant
2511
0
  return macRomanReverseMap->lookup(charName);
2512
0
}
2513
2514
0
GString *GlobalParams::getBaseDir() {
2515
0
  GString *s;
2516
2517
0
  lockGlobalParams;
2518
0
  s = baseDir->copy();
2519
0
  unlockGlobalParams;
2520
0
  return s;
2521
0
}
2522
2523
0
Unicode GlobalParams::mapNameToUnicode(const char *charName) {
2524
  // no need to lock - nameToUnicode is constant
2525
0
  return nameToUnicode->lookup(charName);
2526
0
}
2527
2528
0
UnicodeMap *GlobalParams::getResidentUnicodeMap(GString *encodingName) {
2529
0
  UnicodeMap *map;
2530
2531
0
  lockGlobalParams;
2532
0
  map = (UnicodeMap *)residentUnicodeMaps->lookup(encodingName);
2533
0
  unlockGlobalParams;
2534
0
  if (map) {
2535
0
    map->incRefCnt();
2536
0
  }
2537
0
  return map;
2538
0
}
2539
2540
0
FILE *GlobalParams::getUnicodeMapFile(GString *encodingName) {
2541
0
  GString *fileName;
2542
0
  FILE *f;
2543
2544
0
  lockGlobalParams;
2545
0
  if ((fileName = (GString *)unicodeMaps->lookup(encodingName))) {
2546
0
    f = openFile(fileName->getCString(), "r");
2547
0
  } else {
2548
0
    f = NULL;
2549
0
  }
2550
0
  unlockGlobalParams;
2551
0
  return f;
2552
0
}
2553
2554
0
FILE *GlobalParams::findCMapFile(GString *collection, GString *cMapName) {
2555
0
  GList *list;
2556
0
  GString *dir;
2557
0
  GString *fileName;
2558
0
  FILE *f;
2559
0
  int i;
2560
2561
0
  lockGlobalParams;
2562
0
  if (!(list = (GList *)cMapDirs->lookup(collection))) {
2563
0
    unlockGlobalParams;
2564
0
    return NULL;
2565
0
  }
2566
0
  for (i = 0; i < list->getLength(); ++i) {
2567
0
    dir = (GString *)list->get(i);
2568
0
    fileName = appendToPath(dir->copy(), cMapName->getCString());
2569
0
    f = openFile(fileName->getCString(), "r");
2570
0
    delete fileName;
2571
0
    if (f) {
2572
0
      unlockGlobalParams;
2573
0
      return f;
2574
0
    }
2575
0
  }
2576
0
  unlockGlobalParams;
2577
0
  return NULL;
2578
0
}
2579
2580
0
FILE *GlobalParams::findToUnicodeFile(GString *name) {
2581
0
  GString *dir, *fileName;
2582
0
  FILE *f;
2583
0
  int i;
2584
2585
0
  lockGlobalParams;
2586
0
  for (i = 0; i < toUnicodeDirs->getLength(); ++i) {
2587
0
    dir = (GString *)toUnicodeDirs->get(i);
2588
0
    fileName = appendToPath(dir->copy(), name->getCString());
2589
0
    f = openFile(fileName->getCString(), "r");
2590
0
    delete fileName;
2591
0
    if (f) {
2592
0
      unlockGlobalParams;
2593
0
      return f;
2594
0
    }
2595
0
  }
2596
0
  unlockGlobalParams;
2597
0
  return NULL;
2598
0
}
2599
2600
0
UnicodeRemapping *GlobalParams::getUnicodeRemapping() {
2601
0
  return unicodeRemapping;
2602
0
}
2603
2604
0
GString *GlobalParams::findFontFile(GString *fontName) {
2605
0
  static const char *exts[] = { ".pfa", ".pfb", ".ttf", ".ttc", ".otf" };
2606
0
  GString *path, *dir;
2607
#ifdef _WIN32
2608
  GString *fontNameU;
2609
#endif
2610
0
  const char *ext;
2611
0
  FILE *f;
2612
0
  int i, j;
2613
2614
0
  lockGlobalParams;
2615
0
  if ((path = (GString *)fontFiles->lookup(fontName))) {
2616
0
    path = path->copy();
2617
0
    unlockGlobalParams;
2618
0
    return path;
2619
0
  }
2620
0
  for (i = 0; i < fontDirs->getLength(); ++i) {
2621
0
    dir = (GString *)fontDirs->get(i);
2622
0
    for (j = 0; j < (int)(sizeof(exts) / sizeof(exts[0])); ++j) {
2623
0
      ext = exts[j];
2624
#ifdef _WIN32
2625
      fontNameU = fileNameToUTF8(fontName->getCString());
2626
      path = appendToPath(dir->copy(), fontNameU->getCString());
2627
      delete fontNameU;
2628
#else
2629
0
      path = appendToPath(dir->copy(), fontName->getCString());
2630
0
#endif
2631
0
      path->append(ext);
2632
0
      if ((f = openFile(path->getCString(), "rb"))) {
2633
0
  fclose(f);
2634
0
  unlockGlobalParams;
2635
0
  return path;
2636
0
      }
2637
0
      delete path;
2638
0
    }
2639
0
  }
2640
0
  unlockGlobalParams;
2641
0
  return NULL;
2642
0
}
2643
2644
GString *GlobalParams::findBase14FontFile(GString *fontName, int *fontNum,
2645
0
            double *oblique) {
2646
0
  Base14FontInfo *fi;
2647
0
  GString *path;
2648
2649
0
  lockGlobalParams;
2650
0
  if ((fi = (Base14FontInfo *)base14SysFonts->lookup(fontName))) {
2651
0
    path = fi->fileName->copy();
2652
0
    *fontNum = fi->fontNum;
2653
0
    *oblique = fi->oblique;
2654
0
    unlockGlobalParams;
2655
0
    return path;
2656
0
  }
2657
0
  unlockGlobalParams;
2658
0
  *fontNum = 0;
2659
0
  *oblique = 0;
2660
0
  return findFontFile(fontName);
2661
0
}
2662
2663
GString *GlobalParams::findSystemFontFile(GString *fontName,
2664
            SysFontType *type,
2665
0
            int *fontNum) {
2666
0
  SysFontInfo *fi;
2667
0
  GString *path;
2668
2669
0
  path = NULL;
2670
0
  lockGlobalParams;
2671
0
  if ((fi = sysFonts->find(fontName))) {
2672
0
    path = fi->path->copy();
2673
0
    *type = fi->type;
2674
0
    *fontNum = fi->fontNum;
2675
0
  }
2676
0
  unlockGlobalParams;
2677
0
  return path;
2678
0
}
2679
2680
0
GString *GlobalParams::findCCFontFile(GString *collection) {
2681
0
  GString *path;
2682
2683
0
  lockGlobalParams;
2684
0
  if ((path = (GString *)ccFontFiles->lookup(collection))) {
2685
0
    path = path->copy();
2686
0
  }
2687
0
  unlockGlobalParams;
2688
0
  return path;
2689
0
}
2690
2691
0
int GlobalParams::getPSPaperWidth() {
2692
0
  int w;
2693
2694
0
  lockGlobalParams;
2695
0
  w = psPaperWidth;
2696
0
  unlockGlobalParams;
2697
0
  return w;
2698
0
}
2699
2700
0
int GlobalParams::getPSPaperHeight() {
2701
0
  int h;
2702
2703
0
  lockGlobalParams;
2704
0
  h = psPaperHeight;
2705
0
  unlockGlobalParams;
2706
0
  return h;
2707
0
}
2708
2709
0
void GlobalParams::getPSImageableArea(int *llx, int *lly, int *urx, int *ury) {
2710
0
  lockGlobalParams;
2711
0
  *llx = psImageableLLX;
2712
0
  *lly = psImageableLLY;
2713
0
  *urx = psImageableURX;
2714
0
  *ury = psImageableURY;
2715
0
  unlockGlobalParams;
2716
0
}
2717
2718
0
GBool GlobalParams::getPSCrop() {
2719
0
  GBool f;
2720
2721
0
  lockGlobalParams;
2722
0
  f = psCrop;
2723
0
  unlockGlobalParams;
2724
0
  return f;
2725
0
}
2726
2727
0
GBool GlobalParams::getPSUseCropBoxAsPage() {
2728
0
  GBool f;
2729
2730
0
  lockGlobalParams;
2731
0
  f = psUseCropBoxAsPage;
2732
0
  unlockGlobalParams;
2733
0
  return f;
2734
0
}
2735
2736
0
GBool GlobalParams::getPSExpandSmaller() {
2737
0
  GBool f;
2738
2739
0
  lockGlobalParams;
2740
0
  f = psExpandSmaller;
2741
0
  unlockGlobalParams;
2742
0
  return f;
2743
0
}
2744
2745
0
GBool GlobalParams::getPSShrinkLarger() {
2746
0
  GBool f;
2747
2748
0
  lockGlobalParams;
2749
0
  f = psShrinkLarger;
2750
0
  unlockGlobalParams;
2751
0
  return f;
2752
0
}
2753
2754
0
GBool GlobalParams::getPSCenter() {
2755
0
  GBool f;
2756
2757
0
  lockGlobalParams;
2758
0
  f = psCenter;
2759
0
  unlockGlobalParams;
2760
0
  return f;
2761
0
}
2762
2763
0
GBool GlobalParams::getPSDuplex() {
2764
0
  GBool d;
2765
2766
0
  lockGlobalParams;
2767
0
  d = psDuplex;
2768
0
  unlockGlobalParams;
2769
0
  return d;
2770
0
}
2771
2772
0
PSLevel GlobalParams::getPSLevel() {
2773
0
  PSLevel level;
2774
2775
0
  lockGlobalParams;
2776
0
  level = psLevel;
2777
0
  unlockGlobalParams;
2778
0
  return level;
2779
0
}
2780
2781
0
GString *GlobalParams::getPSResidentFont(GString *fontName) {
2782
0
  GString *psName;
2783
2784
0
  lockGlobalParams;
2785
0
  if ((psName = (GString *)psResidentFonts->lookup(fontName))) {
2786
0
    psName = psName->copy();
2787
0
  }
2788
0
  unlockGlobalParams;
2789
0
  return psName;
2790
0
}
2791
2792
0
GList *GlobalParams::getPSResidentFonts() {
2793
0
  GList *names;
2794
0
  GHashIter *iter;
2795
0
  GString *name;
2796
0
  GString *psName;
2797
2798
0
  names = new GList();
2799
0
  lockGlobalParams;
2800
0
  psResidentFonts->startIter(&iter);
2801
0
  while (psResidentFonts->getNext(&iter, &name, (void **)&psName)) {
2802
0
    names->append(psName->copy());
2803
0
  }
2804
0
  unlockGlobalParams;
2805
0
  return names;
2806
0
}
2807
2808
PSFontParam16 *GlobalParams::getPSResidentFont16(GString *fontName,
2809
0
             int wMode) {
2810
0
  PSFontParam16 *p;
2811
0
  int i;
2812
2813
0
  lockGlobalParams;
2814
0
  p = NULL;
2815
0
  for (i = 0; i < psResidentFonts16->getLength(); ++i) {
2816
0
    p = (PSFontParam16 *)psResidentFonts16->get(i);
2817
0
    if (!(p->name->cmp(fontName)) && p->wMode == wMode) {
2818
0
      break;
2819
0
    }
2820
0
    p = NULL;
2821
0
  }
2822
0
  unlockGlobalParams;
2823
0
  return p;
2824
0
}
2825
2826
PSFontParam16 *GlobalParams::getPSResidentFontCC(GString *collection,
2827
0
             int wMode) {
2828
0
  PSFontParam16 *p;
2829
0
  int i;
2830
2831
0
  lockGlobalParams;
2832
0
  p = NULL;
2833
0
  for (i = 0; i < psResidentFontsCC->getLength(); ++i) {
2834
0
    p = (PSFontParam16 *)psResidentFontsCC->get(i);
2835
0
    if (!(p->name->cmp(collection)) && p->wMode == wMode) {
2836
0
      break;
2837
0
    }
2838
0
    p = NULL;
2839
0
  }
2840
0
  unlockGlobalParams;
2841
0
  return p;
2842
0
}
2843
2844
0
GBool GlobalParams::getPSEmbedType1() {
2845
0
  GBool e;
2846
2847
0
  lockGlobalParams;
2848
0
  e = psEmbedType1;
2849
0
  unlockGlobalParams;
2850
0
  return e;
2851
0
}
2852
2853
0
GBool GlobalParams::getPSEmbedTrueType() {
2854
0
  GBool e;
2855
2856
0
  lockGlobalParams;
2857
0
  e = psEmbedTrueType;
2858
0
  unlockGlobalParams;
2859
0
  return e;
2860
0
}
2861
2862
0
GBool GlobalParams::getPSEmbedCIDPostScript() {
2863
0
  GBool e;
2864
2865
0
  lockGlobalParams;
2866
0
  e = psEmbedCIDPostScript;
2867
0
  unlockGlobalParams;
2868
0
  return e;
2869
0
}
2870
2871
0
GBool GlobalParams::getPSEmbedCIDTrueType() {
2872
0
  GBool e;
2873
2874
0
  lockGlobalParams;
2875
0
  e = psEmbedCIDTrueType;
2876
0
  unlockGlobalParams;
2877
0
  return e;
2878
0
}
2879
2880
0
GBool GlobalParams::getPSFontPassthrough() {
2881
0
  GBool e;
2882
2883
0
  lockGlobalParams;
2884
0
  e = psFontPassthrough;
2885
0
  unlockGlobalParams;
2886
0
  return e;
2887
0
}
2888
2889
0
GBool GlobalParams::getPSPreload() {
2890
0
  GBool preload;
2891
2892
0
  lockGlobalParams;
2893
0
  preload = psPreload;
2894
0
  unlockGlobalParams;
2895
0
  return preload;
2896
0
}
2897
2898
0
GBool GlobalParams::getPSOPI() {
2899
0
  GBool opi;
2900
2901
0
  lockGlobalParams;
2902
0
  opi = psOPI;
2903
0
  unlockGlobalParams;
2904
0
  return opi;
2905
0
}
2906
2907
0
GBool GlobalParams::getPSASCIIHex() {
2908
0
  GBool ah;
2909
2910
0
  lockGlobalParams;
2911
0
  ah = psASCIIHex;
2912
0
  unlockGlobalParams;
2913
0
  return ah;
2914
0
}
2915
2916
0
GBool GlobalParams::getPSLZW() {
2917
0
  GBool ah;
2918
2919
0
  lockGlobalParams;
2920
0
  ah = psLZW;
2921
0
  unlockGlobalParams;
2922
0
  return ah;
2923
0
}
2924
2925
0
GBool GlobalParams::getPSUncompressPreloadedImages() {
2926
0
  GBool ah;
2927
2928
0
  lockGlobalParams;
2929
0
  ah = psUncompressPreloadedImages;
2930
0
  unlockGlobalParams;
2931
0
  return ah;
2932
0
}
2933
2934
0
double GlobalParams::getPSMinLineWidth() {
2935
0
  double w;
2936
2937
0
  lockGlobalParams;
2938
0
  w = psMinLineWidth;
2939
0
  unlockGlobalParams;
2940
0
  return w;
2941
0
}
2942
2943
0
double GlobalParams::getPSRasterResolution() {
2944
0
  double res;
2945
2946
0
  lockGlobalParams;
2947
0
  res = psRasterResolution;
2948
0
  unlockGlobalParams;
2949
0
  return res;
2950
0
}
2951
2952
0
GBool GlobalParams::getPSRasterMono() {
2953
0
  GBool mono;
2954
2955
0
  lockGlobalParams;
2956
0
  mono = psRasterMono;
2957
0
  unlockGlobalParams;
2958
0
  return mono;
2959
0
}
2960
2961
0
int GlobalParams::getPSRasterSliceSize() {
2962
0
  int slice;
2963
2964
0
  lockGlobalParams;
2965
0
  slice = psRasterSliceSize;
2966
0
  unlockGlobalParams;
2967
0
  return slice;
2968
0
}
2969
2970
0
GBool GlobalParams::getPSAlwaysRasterize() {
2971
0
  GBool rast;
2972
2973
0
  lockGlobalParams;
2974
0
  rast = psAlwaysRasterize;
2975
0
  unlockGlobalParams;
2976
0
  return rast;
2977
0
}
2978
2979
0
GBool GlobalParams::getPSNeverRasterize() {
2980
0
  GBool rast;
2981
2982
0
  lockGlobalParams;
2983
0
  rast = psNeverRasterize;
2984
0
  unlockGlobalParams;
2985
0
  return rast;
2986
0
}
2987
2988
0
GString *GlobalParams::getTextEncodingName() {
2989
0
  GString *s;
2990
2991
0
  lockGlobalParams;
2992
0
  s = textEncoding->copy();
2993
0
  unlockGlobalParams;
2994
0
  return s;
2995
0
}
2996
2997
0
GList *GlobalParams::getAvailableTextEncodings() {
2998
0
  GList *list;       // [GString]
2999
0
  GHashIter *iter;
3000
0
  GString *key;
3001
0
  void *val;
3002
3003
0
  list = new GList();
3004
0
  lockGlobalParams;
3005
0
  residentUnicodeMaps->startIter(&iter);
3006
0
  while (residentUnicodeMaps->getNext(&iter, &key, &val)) {
3007
0
    list->append(key->copy());
3008
0
  }
3009
0
  unicodeMaps->startIter(&iter);
3010
0
  while (unicodeMaps->getNext(&iter, &key, &val)) {
3011
0
    list->append(key->copy());
3012
0
  }
3013
0
  unlockGlobalParams;
3014
0
  return list;
3015
0
}
3016
3017
0
EndOfLineKind GlobalParams::getTextEOL() {
3018
0
  EndOfLineKind eol;
3019
3020
0
  lockGlobalParams;
3021
0
  eol = textEOL;
3022
0
  unlockGlobalParams;
3023
0
  return eol;
3024
0
}
3025
3026
0
GBool GlobalParams::getTextPageBreaks() {
3027
0
  GBool pageBreaks;
3028
3029
0
  lockGlobalParams;
3030
0
  pageBreaks = textPageBreaks;
3031
0
  unlockGlobalParams;
3032
0
  return pageBreaks;
3033
0
}
3034
3035
0
GBool GlobalParams::getTextKeepTinyChars() {
3036
0
  GBool tiny;
3037
3038
0
  lockGlobalParams;
3039
0
  tiny = textKeepTinyChars;
3040
0
  unlockGlobalParams;
3041
0
  return tiny;
3042
0
}
3043
3044
0
GString *GlobalParams::getInitialZoom() {
3045
0
  GString *s;
3046
3047
0
  lockGlobalParams;
3048
0
  s = initialZoom->copy();
3049
0
  unlockGlobalParams;
3050
0
  return s;
3051
0
}
3052
3053
0
int GlobalParams::getDefaultFitZoom() {
3054
0
  int z;
3055
3056
0
  lockGlobalParams;
3057
0
  z = defaultFitZoom;
3058
0
  unlockGlobalParams;
3059
0
  return z;
3060
0
}
3061
3062
0
double GlobalParams::getZoomScaleFactor() {
3063
0
  double z;
3064
3065
0
  lockGlobalParams;
3066
0
  z = zoomScaleFactor;
3067
0
  unlockGlobalParams;
3068
0
  return z;
3069
0
}
3070
3071
0
GList *GlobalParams::getZoomValues() {
3072
0
  return zoomValues;
3073
0
}
3074
3075
0
GString *GlobalParams::getInitialDisplayMode() {
3076
0
  GString *s;
3077
3078
0
  lockGlobalParams;
3079
0
  s = initialDisplayMode->copy();
3080
0
  unlockGlobalParams;
3081
0
  return s;
3082
0
}
3083
3084
0
GBool GlobalParams::getInitialToolbarState() {
3085
0
  GBool state;
3086
3087
0
  lockGlobalParams;
3088
0
  state = initialToolbarState;
3089
0
  unlockGlobalParams;
3090
0
  return state;
3091
0
}
3092
3093
0
GBool GlobalParams::getInitialSidebarState() {
3094
0
  GBool state;
3095
3096
0
  lockGlobalParams;
3097
0
  state = initialSidebarState;
3098
0
  unlockGlobalParams;
3099
0
  return state;
3100
0
}
3101
3102
0
int GlobalParams::getInitialSidebarWidth() {
3103
0
  int w;
3104
3105
0
  lockGlobalParams;
3106
0
  w = initialSidebarWidth;
3107
0
  unlockGlobalParams;
3108
0
  return w;
3109
0
}
3110
3111
0
GString *GlobalParams::getInitialSelectMode() {
3112
0
  GString *s;
3113
3114
0
  lockGlobalParams;
3115
0
  s = initialSelectMode->copy();
3116
0
  unlockGlobalParams;
3117
0
  return s;
3118
0
}
3119
3120
0
int GlobalParams::getMaxTileWidth() {
3121
0
  int w;
3122
3123
0
  lockGlobalParams;
3124
0
  w = maxTileWidth;
3125
0
  unlockGlobalParams;
3126
0
  return w;
3127
0
}
3128
3129
0
int GlobalParams::getMaxTileHeight() {
3130
0
  int h;
3131
3132
0
  lockGlobalParams;
3133
0
  h = maxTileHeight;
3134
0
  unlockGlobalParams;
3135
0
  return h;
3136
0
}
3137
3138
0
int GlobalParams::getTileCacheSize() {
3139
0
  int n;
3140
3141
0
  lockGlobalParams;
3142
0
  n = tileCacheSize;
3143
0
  unlockGlobalParams;
3144
0
  return n;
3145
0
}
3146
3147
0
int GlobalParams::getWorkerThreads() {
3148
0
  int n;
3149
3150
0
  lockGlobalParams;
3151
0
  n = workerThreads;
3152
0
  unlockGlobalParams;
3153
0
  return n;
3154
0
}
3155
3156
0
GBool GlobalParams::getEnableFreeType() {
3157
0
  GBool f;
3158
3159
0
  lockGlobalParams;
3160
0
  f = enableFreeType;
3161
0
  unlockGlobalParams;
3162
0
  return f;
3163
0
}
3164
3165
0
GBool GlobalParams::getDisableFreeTypeHinting() {
3166
0
  GBool f;
3167
3168
0
  lockGlobalParams;
3169
0
  f = disableFreeTypeHinting;
3170
0
  unlockGlobalParams;
3171
0
  return f;
3172
0
}
3173
3174
3175
0
GBool GlobalParams::getAntialias() {
3176
0
  GBool f;
3177
3178
0
  lockGlobalParams;
3179
0
  f = antialias;
3180
0
  unlockGlobalParams;
3181
0
  return f;
3182
0
}
3183
3184
0
GBool GlobalParams::getVectorAntialias() {
3185
0
  GBool f;
3186
3187
0
  lockGlobalParams;
3188
0
  f = vectorAntialias;
3189
0
  unlockGlobalParams;
3190
0
  return f;
3191
0
}
3192
3193
0
GBool GlobalParams::getImageMaskAntialias() {
3194
0
  GBool f;
3195
3196
0
  lockGlobalParams;
3197
0
  f = imageMaskAntialias;
3198
0
  unlockGlobalParams;
3199
0
  return f;
3200
0
}
3201
3202
0
GBool GlobalParams::getAntialiasPrinting() {
3203
0
  GBool f;
3204
3205
0
  lockGlobalParams;
3206
0
  f = antialiasPrinting;
3207
0
  unlockGlobalParams;
3208
0
  return f;
3209
0
}
3210
3211
0
StrokeAdjustMode GlobalParams::getStrokeAdjust() {
3212
0
  StrokeAdjustMode mode;
3213
3214
0
  lockGlobalParams;
3215
0
  mode = strokeAdjust;
3216
0
  unlockGlobalParams;
3217
0
  return mode;
3218
0
}
3219
3220
0
ScreenType GlobalParams::getScreenType() {
3221
0
  ScreenType t;
3222
3223
0
  lockGlobalParams;
3224
0
  t = screenType;
3225
0
  unlockGlobalParams;
3226
0
  return t;
3227
0
}
3228
3229
0
int GlobalParams::getScreenSize() {
3230
0
  int size;
3231
3232
0
  lockGlobalParams;
3233
0
  size = screenSize;
3234
0
  unlockGlobalParams;
3235
0
  return size;
3236
0
}
3237
3238
0
int GlobalParams::getScreenDotRadius() {
3239
0
  int r;
3240
3241
0
  lockGlobalParams;
3242
0
  r = screenDotRadius;
3243
0
  unlockGlobalParams;
3244
0
  return r;
3245
0
}
3246
3247
0
double GlobalParams::getScreenGamma() {
3248
0
  double gamma;
3249
3250
0
  lockGlobalParams;
3251
0
  gamma = screenGamma;
3252
0
  unlockGlobalParams;
3253
0
  return gamma;
3254
0
}
3255
3256
0
double GlobalParams::getScreenBlackThreshold() {
3257
0
  double thresh;
3258
3259
0
  lockGlobalParams;
3260
0
  thresh = screenBlackThreshold;
3261
0
  unlockGlobalParams;
3262
0
  return thresh;
3263
0
}
3264
3265
0
double GlobalParams::getScreenWhiteThreshold() {
3266
0
  double thresh;
3267
3268
0
  lockGlobalParams;
3269
0
  thresh = screenWhiteThreshold;
3270
0
  unlockGlobalParams;
3271
0
  return thresh;
3272
0
}
3273
3274
0
double GlobalParams::getMinLineWidth() {
3275
0
  double w;
3276
3277
0
  lockGlobalParams;
3278
0
  w = minLineWidth;
3279
0
  unlockGlobalParams;
3280
0
  return w;
3281
0
}
3282
3283
0
GBool GlobalParams::getEnablePathSimplification() {
3284
0
  GBool en;
3285
3286
0
  lockGlobalParams;
3287
0
  en = enablePathSimplification;
3288
0
  unlockGlobalParams;
3289
0
  return en;
3290
0
}
3291
3292
0
GBool GlobalParams::getDrawAnnotations() {
3293
0
  GBool draw;
3294
3295
0
  lockGlobalParams;
3296
0
  draw = drawAnnotations;
3297
0
  unlockGlobalParams;
3298
0
  return draw;
3299
0
}
3300
3301
0
GBool GlobalParams::getDrawFormFields() {
3302
0
  GBool draw;
3303
3304
0
  lockGlobalParams;
3305
0
  draw = drawFormFields;
3306
0
  unlockGlobalParams;
3307
0
  return draw;
3308
0
}
3309
3310
883
GBool GlobalParams::getEnableXFA() {
3311
883
  GBool xfa;
3312
3313
883
  lockGlobalParams;
3314
883
  xfa = enableXFA;
3315
883
  unlockGlobalParams;
3316
883
  return xfa;
3317
883
}
3318
3319
3320
3321
0
GString *GlobalParams::getPaperColor() {
3322
0
  GString *s;
3323
3324
0
  lockGlobalParams;
3325
0
  s = paperColor->copy();
3326
0
  unlockGlobalParams;
3327
0
  return s;
3328
0
}
3329
3330
0
GString *GlobalParams::getMatteColor() {
3331
0
  GString *s;
3332
3333
0
  lockGlobalParams;
3334
0
  s = matteColor->copy();
3335
0
  unlockGlobalParams;
3336
0
  return s;
3337
0
}
3338
3339
0
GString *GlobalParams::getFullScreenMatteColor() {
3340
0
  GString *s;
3341
3342
0
  lockGlobalParams;
3343
0
  s = fullScreenMatteColor->copy();
3344
0
  unlockGlobalParams;
3345
0
  return s;
3346
0
}
3347
3348
0
GString *GlobalParams::getSelectionColor() {
3349
0
  GString *s;
3350
3351
0
  lockGlobalParams;
3352
0
  s = selectionColor->copy();
3353
0
  unlockGlobalParams;
3354
0
  return s;
3355
0
}
3356
3357
0
GBool GlobalParams::getReverseVideoInvertImages() {
3358
0
  GBool invert;
3359
3360
0
  lockGlobalParams;
3361
0
  invert = reverseVideoInvertImages;
3362
0
  unlockGlobalParams;
3363
0
  return invert;
3364
0
}
3365
3366
0
GBool GlobalParams::getAllowLinksToChangeZoom() {
3367
0
  GBool allow;
3368
3369
0
  lockGlobalParams;
3370
0
  allow = allowLinksToChangeZoom;
3371
0
  unlockGlobalParams;
3372
0
  return allow;
3373
0
}
3374
3375
0
GString *GlobalParams::getDefaultPrinter() {
3376
0
  GString *s;
3377
3378
0
  lockGlobalParams;
3379
0
  s = defaultPrinter ? defaultPrinter->copy() : (GString *)NULL;
3380
0
  unlockGlobalParams;
3381
0
  return s;
3382
0
}
3383
3384
0
GBool GlobalParams::getMapNumericCharNames() {
3385
0
  GBool map;
3386
3387
0
  lockGlobalParams;
3388
0
  map = mapNumericCharNames;
3389
0
  unlockGlobalParams;
3390
0
  return map;
3391
0
}
3392
3393
0
GBool GlobalParams::getMapUnknownCharNames() {
3394
0
  GBool map;
3395
3396
0
  lockGlobalParams;
3397
0
  map = mapUnknownCharNames;
3398
0
  unlockGlobalParams;
3399
0
  return map;
3400
0
}
3401
3402
0
GBool GlobalParams::getMapExtTrueTypeFontsViaUnicode() {
3403
0
  GBool map;
3404
3405
0
  lockGlobalParams;
3406
0
  map = mapExtTrueTypeFontsViaUnicode;
3407
0
  unlockGlobalParams;
3408
0
  return map;
3409
0
}
3410
3411
0
GBool GlobalParams::getUseTrueTypeUnicodeMapping() {
3412
0
  GBool use;
3413
3414
0
  lockGlobalParams;
3415
0
  use = useTrueTypeUnicodeMapping;
3416
0
  unlockGlobalParams;
3417
0
  return use;
3418
0
}
3419
3420
0
GBool GlobalParams::getIgnoreWrongSizeToUnicode() {
3421
0
  GBool ignore;
3422
3423
0
  lockGlobalParams;
3424
0
  ignore = ignoreWrongSizeToUnicode;
3425
0
  unlockGlobalParams;
3426
0
  return ignore;
3427
0
}
3428
3429
0
GBool GlobalParams::isDroppedFont(const char *fontName) {
3430
0
  GBool isDropped;
3431
3432
0
  lockGlobalParams;
3433
0
  isDropped = droppedFonts->lookupInt(fontName) != 0;
3434
0
  unlockGlobalParams;
3435
0
  return isDropped;
3436
0
}
3437
3438
0
GBool GlobalParams::getSeparateRotatedText() {
3439
0
  GBool sep;
3440
3441
0
  lockGlobalParams;
3442
0
  sep = separateRotatedText;
3443
0
  unlockGlobalParams;
3444
0
  return sep;
3445
0
}
3446
3447
0
GList *GlobalParams::getKeyBinding(int code, int mods, int context) {
3448
0
  KeyBinding *binding;
3449
0
  GList *cmds;
3450
0
  int modMask;
3451
0
  int i, j;
3452
3453
0
  lockGlobalParams;
3454
0
  cmds = NULL;
3455
  // for ASCII chars, ignore the shift modifier
3456
0
  modMask = (code >= 0x21 && code <= 0xff) ? ~xpdfKeyModShift : ~0;
3457
0
  for (i = 0; i < keyBindings->getLength(); ++i) {
3458
0
    binding = (KeyBinding *)keyBindings->get(i);
3459
0
    if (binding->code == code &&
3460
0
  (binding->mods & modMask) == (mods & modMask) &&
3461
0
  (~binding->context | context) == ~0) {
3462
0
      cmds = new GList();
3463
0
      for (j = 0; j < binding->cmds->getLength(); ++j) {
3464
0
  cmds->append(((GString *)binding->cmds->get(j))->copy());
3465
0
      }
3466
0
      break;
3467
0
    }
3468
0
  }
3469
0
  unlockGlobalParams;
3470
0
  return cmds;
3471
0
}
3472
3473
0
GList *GlobalParams::getAllKeyBindings() {
3474
0
  return keyBindings;
3475
0
}
3476
3477
0
int GlobalParams::getNumPopupMenuCmds() {
3478
0
  int n;
3479
3480
0
  lockGlobalParams;
3481
0
  n = popupMenuCmds->getLength();
3482
0
  unlockGlobalParams;
3483
0
  return n;
3484
0
}
3485
3486
0
PopupMenuCmd *GlobalParams::getPopupMenuCmd(int idx) {
3487
0
  PopupMenuCmd *cmd;
3488
3489
0
  lockGlobalParams;
3490
0
  if (idx < popupMenuCmds->getLength()) {
3491
0
    cmd = (PopupMenuCmd *)popupMenuCmds->get(idx);
3492
0
  } else {
3493
0
    cmd = NULL;
3494
0
  }
3495
0
  unlockGlobalParams;
3496
0
  return cmd;
3497
0
}
3498
3499
0
GString *GlobalParams::getPagesFile() {
3500
0
  GString *s;
3501
3502
0
  lockGlobalParams;
3503
0
  s = pagesFile->copy();
3504
0
  unlockGlobalParams;
3505
0
  return s;
3506
0
}
3507
3508
0
GString *GlobalParams::getTabStateFile() {
3509
0
  GString *s;
3510
3511
0
  lockGlobalParams;
3512
0
  s = tabStateFile->copy();
3513
0
  unlockGlobalParams;
3514
0
  return s;
3515
0
}
3516
3517
0
GString *GlobalParams::getSessionFile() {
3518
0
  GString *s;
3519
3520
0
  lockGlobalParams;
3521
0
  s = sessionFile->copy();
3522
0
  unlockGlobalParams;
3523
0
  return s;
3524
0
}
3525
3526
0
GBool GlobalParams::getSavePageNumbers() {
3527
0
  GBool s;
3528
3529
0
  lockGlobalParams;
3530
0
  s = savePageNumbers;
3531
0
  unlockGlobalParams;
3532
0
  return s;
3533
0
}
3534
3535
0
GBool GlobalParams::getSaveSessionOnQuit() {
3536
0
  GBool s;
3537
3538
0
  lockGlobalParams;
3539
0
  s = saveSessionOnQuit;
3540
0
  unlockGlobalParams;
3541
0
  return s;
3542
0
}
3543
3544
0
GBool GlobalParams::getPrintCommands() {
3545
0
  GBool p;
3546
3547
0
  lockGlobalParams;
3548
0
  p = printCommands;
3549
0
  unlockGlobalParams;
3550
0
  return p;
3551
0
}
3552
3553
0
GBool GlobalParams::getPrintStatusInfo() {
3554
0
  GBool p;
3555
3556
0
  lockGlobalParams;
3557
0
  p = printStatusInfo;
3558
0
  unlockGlobalParams;
3559
0
  return p;
3560
0
}
3561
3562
57.9M
GBool GlobalParams::getErrQuiet() {
3563
  // no locking -- this function may get called from inside a locked
3564
  // section
3565
57.9M
  return errQuiet;
3566
57.9M
}
3567
3568
0
GString *GlobalParams::getDebugLogFile() {
3569
0
  return debugLogFile;
3570
0
}
3571
3572
0
void GlobalParams::debugLogPrintf(const char *fmt, ...) {
3573
0
  GString *path;
3574
0
  FILE *f;
3575
0
  GBool needClose;
3576
0
  time_t t;
3577
0
  struct tm tm;
3578
0
  va_list args;
3579
3580
0
  if (!(path = getDebugLogFile())) {
3581
0
    return;
3582
0
  }
3583
0
  needClose = gFalse;
3584
0
  if (!path->cmp("-")) {
3585
0
    f = stdout;
3586
0
  } else if (!path->cmp("+")) {
3587
0
    f = stderr;
3588
0
  } else {
3589
0
    f = fopen(path->getCString(), "a");
3590
0
    needClose = gTrue;
3591
0
  }
3592
0
  if (!f) {
3593
0
    return;
3594
0
  }
3595
0
  t = time(NULL);
3596
#ifdef _WIN32
3597
  localtime_s(&tm, &t);
3598
#else
3599
0
  localtime_r(&t, &tm);
3600
0
#endif
3601
0
  fprintf(f, "[%04d-%02d-%02d %02d:%02d:%02d] ",
3602
0
    tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
3603
0
    tm.tm_hour, tm.tm_min, tm.tm_sec);
3604
0
  va_start(args, fmt);
3605
0
  vfprintf(f, fmt, args);
3606
0
  va_end(args);
3607
0
  fflush(f);
3608
0
  if (needClose) {
3609
0
    fclose(f);
3610
0
  }
3611
0
}
3612
3613
0
CharCodeToUnicode *GlobalParams::getCIDToUnicode(GString *collection) {
3614
0
  GString *fileName;
3615
0
  CharCodeToUnicode *ctu;
3616
3617
0
  lockGlobalParams;
3618
0
  if (!(ctu = cidToUnicodeCache->getCharCodeToUnicode(collection))) {
3619
0
    if ((fileName = (GString *)cidToUnicodes->lookup(collection)) &&
3620
0
  (ctu = CharCodeToUnicode::parseCIDToUnicode(fileName, collection))) {
3621
0
      cidToUnicodeCache->add(ctu);
3622
0
    }
3623
0
  }
3624
0
  unlockGlobalParams;
3625
0
  return ctu;
3626
0
}
3627
3628
0
CharCodeToUnicode *GlobalParams::getUnicodeToUnicode(GString *fontName) {
3629
0
  CharCodeToUnicode *ctu;
3630
0
  GHashIter *iter;
3631
0
  GString *fontPattern, *fileName;
3632
3633
0
  lockGlobalParams;
3634
0
  fileName = NULL;
3635
0
  unicodeToUnicodes->startIter(&iter);
3636
0
  while (unicodeToUnicodes->getNext(&iter, &fontPattern, (void **)&fileName)) {
3637
0
    if (strstr(fontName->getCString(), fontPattern->getCString())) {
3638
0
      unicodeToUnicodes->killIter(&iter);
3639
0
      break;
3640
0
    }
3641
0
    fileName = NULL;
3642
0
  }
3643
0
  if (fileName) {
3644
0
    if (!(ctu = unicodeToUnicodeCache->getCharCodeToUnicode(fileName))) {
3645
0
      if ((ctu = CharCodeToUnicode::parseUnicodeToUnicode(fileName))) {
3646
0
  unicodeToUnicodeCache->add(ctu);
3647
0
      }
3648
0
    }
3649
0
  } else {
3650
0
    ctu = NULL;
3651
0
  }
3652
0
  unlockGlobalParams;
3653
0
  return ctu;
3654
0
}
3655
3656
0
UnicodeMap *GlobalParams::getUnicodeMap(GString *encodingName) {
3657
0
  return getUnicodeMap2(encodingName);
3658
0
}
3659
3660
0
UnicodeMap *GlobalParams::getUnicodeMap2(GString *encodingName) {
3661
0
  UnicodeMap *map;
3662
3663
0
  if (!(map = getResidentUnicodeMap(encodingName))) {
3664
0
    lockUnicodeMapCache;
3665
0
    map = unicodeMapCache->getUnicodeMap(encodingName);
3666
0
    unlockUnicodeMapCache;
3667
0
  }
3668
0
  return map;
3669
0
}
3670
3671
0
CMap *GlobalParams::getCMap(GString *collection, GString *cMapName) {
3672
0
  CMap *cMap;
3673
3674
0
  lockCMapCache;
3675
0
  cMap = cMapCache->getCMap(collection, cMapName);
3676
0
  unlockCMapCache;
3677
0
  return cMap;
3678
0
}
3679
3680
0
UnicodeMap *GlobalParams::getTextEncoding() {
3681
0
  return getUnicodeMap2(textEncoding);
3682
0
}
3683
3684
//------------------------------------------------------------------------
3685
// functions to set parameters
3686
//------------------------------------------------------------------------
3687
3688
0
void GlobalParams::addUnicodeRemapping(Unicode in, Unicode *out, int len) {
3689
0
  unicodeRemapping->addRemapping(in, out, len);
3690
0
}
3691
3692
0
void GlobalParams::addFontFile(GString *fontName, GString *path) {
3693
0
  lockGlobalParams;
3694
0
  fontFiles->add(fontName, path);
3695
0
  unlockGlobalParams;
3696
0
}
3697
3698
0
GBool GlobalParams::setPSPaperSize(char *size) {
3699
0
  lockGlobalParams;
3700
0
  if (!strcmp(size, "match")) {
3701
0
    psPaperWidth = psPaperHeight = -1;
3702
0
  } else if (!strcmp(size, "letter")) {
3703
0
    psPaperWidth = 612;
3704
0
    psPaperHeight = 792;
3705
0
  } else if (!strcmp(size, "legal")) {
3706
0
    psPaperWidth = 612;
3707
0
    psPaperHeight = 1008;
3708
0
  } else if (!strcmp(size, "A4")) {
3709
0
    psPaperWidth = 595;
3710
0
    psPaperHeight = 842;
3711
0
  } else if (!strcmp(size, "A3")) {
3712
0
    psPaperWidth = 842;
3713
0
    psPaperHeight = 1190;
3714
0
  } else {
3715
0
    unlockGlobalParams;
3716
0
    return gFalse;
3717
0
  }
3718
0
  psImageableLLX = psImageableLLY = 0;
3719
0
  psImageableURX = psPaperWidth;
3720
0
  psImageableURY = psPaperHeight;
3721
0
  unlockGlobalParams;
3722
0
  return gTrue;
3723
0
}
3724
3725
0
void GlobalParams::setPSPaperWidth(int width) {
3726
0
  lockGlobalParams;
3727
0
  psPaperWidth = width;
3728
0
  psImageableLLX = 0;
3729
0
  psImageableURX = psPaperWidth;
3730
0
  unlockGlobalParams;
3731
0
}
3732
3733
0
void GlobalParams::setPSPaperHeight(int height) {
3734
0
  lockGlobalParams;
3735
0
  psPaperHeight = height;
3736
0
  psImageableLLY = 0;
3737
0
  psImageableURY = psPaperHeight;
3738
0
  unlockGlobalParams;
3739
0
}
3740
3741
0
void GlobalParams::setPSImageableArea(int llx, int lly, int urx, int ury) {
3742
0
  lockGlobalParams;
3743
0
  psImageableLLX = llx;
3744
0
  psImageableLLY = lly;
3745
0
  psImageableURX = urx;
3746
0
  psImageableURY = ury;
3747
0
  unlockGlobalParams;
3748
0
}
3749
3750
0
void GlobalParams::setPSCrop(GBool crop) {
3751
0
  lockGlobalParams;
3752
0
  psCrop = crop;
3753
0
  unlockGlobalParams;
3754
0
}
3755
3756
0
void GlobalParams::setPSUseCropBoxAsPage(GBool crop) {
3757
0
  lockGlobalParams;
3758
0
  psUseCropBoxAsPage = crop;
3759
0
  unlockGlobalParams;
3760
0
}
3761
3762
0
void GlobalParams::setPSExpandSmaller(GBool expand) {
3763
0
  lockGlobalParams;
3764
0
  psExpandSmaller = expand;
3765
0
  unlockGlobalParams;
3766
0
}
3767
3768
0
void GlobalParams::setPSShrinkLarger(GBool shrink) {
3769
0
  lockGlobalParams;
3770
0
  psShrinkLarger = shrink;
3771
0
  unlockGlobalParams;
3772
0
}
3773
3774
0
void GlobalParams::setPSCenter(GBool center) {
3775
0
  lockGlobalParams;
3776
0
  psCenter = center;
3777
0
  unlockGlobalParams;
3778
0
}
3779
3780
0
void GlobalParams::setPSDuplex(GBool duplex) {
3781
0
  lockGlobalParams;
3782
0
  psDuplex = duplex;
3783
0
  unlockGlobalParams;
3784
0
}
3785
3786
0
void GlobalParams::setPSLevel(PSLevel level) {
3787
0
  lockGlobalParams;
3788
0
  psLevel = level;
3789
0
  unlockGlobalParams;
3790
0
}
3791
3792
0
void GlobalParams::setPSEmbedType1(GBool embed) {
3793
0
  lockGlobalParams;
3794
0
  psEmbedType1 = embed;
3795
0
  unlockGlobalParams;
3796
0
}
3797
3798
0
void GlobalParams::setPSEmbedTrueType(GBool embed) {
3799
0
  lockGlobalParams;
3800
0
  psEmbedTrueType = embed;
3801
0
  unlockGlobalParams;
3802
0
}
3803
3804
0
void GlobalParams::setPSEmbedCIDPostScript(GBool embed) {
3805
0
  lockGlobalParams;
3806
0
  psEmbedCIDPostScript = embed;
3807
0
  unlockGlobalParams;
3808
0
}
3809
3810
0
void GlobalParams::setPSEmbedCIDTrueType(GBool embed) {
3811
0
  lockGlobalParams;
3812
0
  psEmbedCIDTrueType = embed;
3813
0
  unlockGlobalParams;
3814
0
}
3815
3816
0
void GlobalParams::setPSFontPassthrough(GBool passthrough) {
3817
0
  lockGlobalParams;
3818
0
  psFontPassthrough = passthrough;
3819
0
  unlockGlobalParams;
3820
0
}
3821
3822
0
void GlobalParams::setPSPreload(GBool preload) {
3823
0
  lockGlobalParams;
3824
0
  psPreload = preload;
3825
0
  unlockGlobalParams;
3826
0
}
3827
3828
0
void GlobalParams::setPSOPI(GBool opi) {
3829
0
  lockGlobalParams;
3830
0
  psOPI = opi;
3831
0
  unlockGlobalParams;
3832
0
}
3833
3834
0
void GlobalParams::setPSASCIIHex(GBool hex) {
3835
0
  lockGlobalParams;
3836
0
  psASCIIHex = hex;
3837
0
  unlockGlobalParams;
3838
0
}
3839
3840
0
void GlobalParams::setTextEncoding(const char *encodingName) {
3841
0
  lockGlobalParams;
3842
0
  delete textEncoding;
3843
0
  textEncoding = new GString(encodingName);
3844
0
  unlockGlobalParams;
3845
0
}
3846
3847
0
GBool GlobalParams::setTextEOL(char *s) {
3848
0
  lockGlobalParams;
3849
0
  if (!strcmp(s, "unix")) {
3850
0
    textEOL = eolUnix;
3851
0
  } else if (!strcmp(s, "dos")) {
3852
0
    textEOL = eolDOS;
3853
0
  } else if (!strcmp(s, "mac")) {
3854
0
    textEOL = eolMac;
3855
0
  } else {
3856
0
    unlockGlobalParams;
3857
0
    return gFalse;
3858
0
  }
3859
0
  unlockGlobalParams;
3860
0
  return gTrue;
3861
0
}
3862
3863
0
void GlobalParams::setTextPageBreaks(GBool pageBreaks) {
3864
0
  lockGlobalParams;
3865
0
  textPageBreaks = pageBreaks;
3866
0
  unlockGlobalParams;
3867
0
}
3868
3869
0
void GlobalParams::setTextKeepTinyChars(GBool keep) {
3870
0
  lockGlobalParams;
3871
0
  textKeepTinyChars = keep;
3872
0
  unlockGlobalParams;
3873
0
}
3874
3875
0
void GlobalParams::setInitialZoom(char *s) {
3876
0
  lockGlobalParams;
3877
0
  delete initialZoom;
3878
0
  initialZoom = new GString(s);
3879
0
  unlockGlobalParams;
3880
0
}
3881
3882
0
void GlobalParams::setDefaultFitZoom(int z) {
3883
0
  lockGlobalParams;
3884
0
  defaultFitZoom = z;
3885
0
  unlockGlobalParams;
3886
0
}
3887
3888
3.17k
GBool GlobalParams::setEnableFreeType(char *s) {
3889
3.17k
  GBool ok;
3890
3891
3.17k
  lockGlobalParams;
3892
3.17k
  ok = parseYesNo2(s, &enableFreeType);
3893
3.17k
  unlockGlobalParams;
3894
3.17k
  return ok;
3895
3.17k
}
3896
3897
3898
0
GBool GlobalParams::setAntialias(char *s) {
3899
0
  GBool ok;
3900
3901
0
  lockGlobalParams;
3902
0
  ok = parseYesNo2(s, &antialias);
3903
0
  unlockGlobalParams;
3904
0
  return ok;
3905
0
}
3906
3907
0
GBool GlobalParams::setVectorAntialias(char *s) {
3908
0
  GBool ok;
3909
3910
0
  lockGlobalParams;
3911
0
  ok = parseYesNo2(s, &vectorAntialias);
3912
0
  unlockGlobalParams;
3913
0
  return ok;
3914
0
}
3915
3916
0
void GlobalParams::setScreenType(ScreenType t) {
3917
0
  lockGlobalParams;
3918
0
  screenType = t;
3919
0
  unlockGlobalParams;
3920
0
}
3921
3922
0
void GlobalParams::setScreenSize(int size) {
3923
0
  lockGlobalParams;
3924
0
  screenSize = size;
3925
0
  unlockGlobalParams;
3926
0
}
3927
3928
0
void GlobalParams::setScreenDotRadius(int r) {
3929
0
  lockGlobalParams;
3930
0
  screenDotRadius = r;
3931
0
  unlockGlobalParams;
3932
0
}
3933
3934
0
void GlobalParams::setScreenGamma(double gamma) {
3935
0
  lockGlobalParams;
3936
0
  screenGamma = gamma;
3937
0
  unlockGlobalParams;
3938
0
}
3939
3940
0
void GlobalParams::setScreenBlackThreshold(double thresh) {
3941
0
  lockGlobalParams;
3942
0
  screenBlackThreshold = thresh;
3943
0
  unlockGlobalParams;
3944
0
}
3945
3946
0
void GlobalParams::setScreenWhiteThreshold(double thresh) {
3947
0
  lockGlobalParams;
3948
0
  screenWhiteThreshold = thresh;
3949
0
  unlockGlobalParams;
3950
0
}
3951
3952
0
void GlobalParams::setDrawFormFields(GBool draw) {
3953
0
  lockGlobalParams;
3954
0
  drawFormFields = draw;
3955
0
  unlockGlobalParams;
3956
0
}
3957
3958
0
void GlobalParams::setOverprintPreview(GBool preview) {
3959
0
  lockGlobalParams;
3960
0
  overprintPreview = preview;
3961
0
  unlockGlobalParams;
3962
0
}
3963
3964
3965
3966
0
void GlobalParams::setMapNumericCharNames(GBool map) {
3967
0
  lockGlobalParams;
3968
0
  mapNumericCharNames = map;
3969
0
  unlockGlobalParams;
3970
0
}
3971
3972
0
void GlobalParams::setMapUnknownCharNames(GBool map) {
3973
0
  lockGlobalParams;
3974
0
  mapUnknownCharNames = map;
3975
0
  unlockGlobalParams;
3976
0
}
3977
3978
0
void GlobalParams::setMapExtTrueTypeFontsViaUnicode(GBool map) {
3979
0
  lockGlobalParams;
3980
0
  mapExtTrueTypeFontsViaUnicode = map;
3981
0
  unlockGlobalParams;
3982
0
}
3983
3984
0
void GlobalParams::setTabStateFile(char *tabStateFileA) {
3985
0
  lockGlobalParams;
3986
0
  delete tabStateFile;
3987
0
  tabStateFile = new GString(tabStateFileA);
3988
0
  unlockGlobalParams;
3989
0
}
3990
3991
0
void GlobalParams::setSessionFile(char *sessionFileA) {
3992
0
  lockGlobalParams;
3993
0
  delete sessionFile;
3994
0
  sessionFile = new GString(sessionFileA);
3995
0
  unlockGlobalParams;
3996
0
}
3997
3998
0
void GlobalParams::setPrintCommands(GBool printCommandsA) {
3999
0
  lockGlobalParams;
4000
0
  printCommands = printCommandsA;
4001
0
  unlockGlobalParams;
4002
0
}
4003
4004
0
void GlobalParams::setPrintStatusInfo(GBool printStatusInfoA) {
4005
0
  lockGlobalParams;
4006
0
  printStatusInfo = printStatusInfoA;
4007
0
  unlockGlobalParams;
4008
0
}
4009
4010
6.35k
void GlobalParams::setErrQuiet(GBool errQuietA) {
4011
6.35k
  lockGlobalParams;
4012
6.35k
  errQuiet = errQuietA;
4013
6.35k
  unlockGlobalParams;
4014
6.35k
}
4015
4016
#ifdef _WIN32
4017
void GlobalParams::setWin32ErrorInfo(const char *func, DWORD code) {
4018
  XpdfWin32ErrorInfo *errorInfo;
4019
4020
  if (tlsWin32ErrorInfo == TLS_OUT_OF_INDEXES) {
4021
    return;
4022
  }
4023
  errorInfo = (XpdfWin32ErrorInfo *)TlsGetValue(tlsWin32ErrorInfo);
4024
  if (!errorInfo) {
4025
    errorInfo = new XpdfWin32ErrorInfo();
4026
    TlsSetValue(tlsWin32ErrorInfo, errorInfo);
4027
  }
4028
  errorInfo->func = func;
4029
  errorInfo->code = code;
4030
}
4031
4032
XpdfWin32ErrorInfo *GlobalParams::getWin32ErrorInfo() {
4033
  XpdfWin32ErrorInfo *errorInfo;
4034
4035
  if (tlsWin32ErrorInfo == TLS_OUT_OF_INDEXES) {
4036
    return NULL;
4037
  }
4038
  errorInfo = (XpdfWin32ErrorInfo *)TlsGetValue(tlsWin32ErrorInfo);
4039
  if (!errorInfo) {
4040
    errorInfo = new XpdfWin32ErrorInfo();
4041
    TlsSetValue(tlsWin32ErrorInfo, errorInfo);
4042
    errorInfo->func = NULL;
4043
    errorInfo->code = 0;
4044
  }
4045
  return errorInfo;
4046
}
4047
#endif