Coverage Report

Created: 2023-11-19 06:22

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