Coverage Report

Created: 2022-03-21 07:20

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