Coverage Report

Created: 2026-04-04 06:05

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