~ubuntu-branches/ubuntu/saucy/xpdf/saucy

« back to all changes in this revision

Viewing changes to .pc/fix-invalid-conversions.patch/xpdf/GlobalParams.cc

  • Committer: Package Import Robot
  • Author(s): Dmitry Shachnev
  • Date: 2013-09-04 15:30:10 UTC
  • Revision ID: package-import@ubuntu.com-20130904153010-buld78nmv8wd6xgt
Tags: 3.03-11ubuntu4
* Remove duplicate hunk from poppler-params.patch.
* Remove all remaining patches/hunks that touch GlobalParams code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//========================================================================
2
 
//
3
 
// GlobalParams.cc
4
 
//
5
 
// Copyright 2001-2003 Glyph & Cog, LLC
6
 
//
7
 
//========================================================================
8
 
 
9
 
#include <aconf.h>
10
 
 
11
 
#ifdef USE_GCC_PRAGMAS
12
 
#pragma implementation
13
 
#endif
14
 
 
15
 
#include <string.h>
16
 
#include <stdio.h>
17
 
#include <ctype.h>
18
 
#ifdef ENABLE_PLUGINS
19
 
#  ifndef WIN32
20
 
#    include <dlfcn.h>
21
 
#  endif
22
 
#endif
23
 
#ifdef WIN32
24
 
#  include <shlobj.h>
25
 
#endif
26
 
#if HAVE_PAPER_H
27
 
#include <paper.h>
28
 
#endif
29
 
#include "gmem.h"
30
 
#include "GString.h"
31
 
#include "GList.h"
32
 
#include "GHash.h"
33
 
#include "gfile.h"
34
 
#include "Error.h"
35
 
#include "NameToCharCode.h"
36
 
#include "CharCodeToUnicode.h"
37
 
#include "UnicodeMap.h"
38
 
#include "CMap.h"
39
 
#include "BuiltinFontTables.h"
40
 
#include "FontEncodingTables.h"
41
 
#ifdef ENABLE_PLUGINS
42
 
#  include "XpdfPluginAPI.h"
43
 
#endif
44
 
#include "GlobalParams.h"
45
 
 
46
 
#ifdef WIN32
47
 
#  define strcasecmp stricmp
48
 
#endif
49
 
 
50
 
#if MULTITHREADED
51
 
#  define lockGlobalParams            gLockMutex(&mutex)
52
 
#  define lockUnicodeMapCache         gLockMutex(&unicodeMapCacheMutex)
53
 
#  define lockCMapCache               gLockMutex(&cMapCacheMutex)
54
 
#  define unlockGlobalParams          gUnlockMutex(&mutex)
55
 
#  define unlockUnicodeMapCache       gUnlockMutex(&unicodeMapCacheMutex)
56
 
#  define unlockCMapCache             gUnlockMutex(&cMapCacheMutex)
57
 
#else
58
 
#  define lockGlobalParams
59
 
#  define lockUnicodeMapCache
60
 
#  define lockCMapCache
61
 
#  define unlockGlobalParams
62
 
#  define unlockUnicodeMapCache
63
 
#  define unlockCMapCache
64
 
#endif
65
 
 
66
 
#include "NameToUnicodeTable.h"
67
 
#include "UnicodeMapTables.h"
68
 
#include "UTF8.h"
69
 
 
70
 
#ifdef ENABLE_PLUGINS
71
 
#  ifdef WIN32
72
 
extern XpdfPluginVecTable xpdfPluginVecTable;
73
 
#  endif
74
 
#endif
75
 
 
76
 
//------------------------------------------------------------------------
77
 
 
78
 
#define cidToUnicodeCacheSize     4
79
 
#define unicodeToUnicodeCacheSize 4
80
 
 
81
 
//------------------------------------------------------------------------
82
 
 
83
 
static struct {
84
 
  const char *name;
85
 
  const char *t1FileName;
86
 
  const char *ttFileName;
87
 
} displayFontTab[] = {
88
 
  {"Courier",               "n022003l.pfb", "cour.ttf"},
89
 
  {"Courier-Bold",          "n022004l.pfb", "courbd.ttf"},
90
 
  {"Courier-BoldOblique",   "n022024l.pfb", "courbi.ttf"},
91
 
  {"Courier-Oblique",       "n022023l.pfb", "couri.ttf"},
92
 
  {"Helvetica",             "n019003l.pfb", "arial.ttf"},
93
 
  {"Helvetica-Bold",        "n019004l.pfb", "arialbd.ttf"},
94
 
  {"Helvetica-BoldOblique", "n019024l.pfb", "arialbi.ttf"},
95
 
  {"Helvetica-Oblique",     "n019023l.pfb", "ariali.ttf"},
96
 
  {"Symbol",                "s050000l.pfb", NULL},
97
 
  {"Times-Bold",            "n021004l.pfb", "timesbd.ttf"},
98
 
  {"Times-BoldItalic",      "n021024l.pfb", "timesbi.ttf"},
99
 
  {"Times-Italic",          "n021023l.pfb", "timesi.ttf"},
100
 
  {"Times-Roman",           "n021003l.pfb", "times.ttf"},
101
 
  {"ZapfDingbats",          "d050000l.pfb", NULL},
102
 
  {NULL}
103
 
};
104
 
 
105
 
#ifdef WIN32
106
 
static const char *displayFontDirs[] = {
107
 
  "c:/windows/fonts",
108
 
  "c:/winnt/fonts",
109
 
  NULL
110
 
};
111
 
#else
112
 
static const char *displayFontDirs[] = {
113
 
  "/usr/share/ghostscript/fonts",
114
 
  "/usr/local/share/ghostscript/fonts",
115
 
  "/usr/share/fonts/default/Type1",
116
 
  "/usr/share/fonts/default/ghostscript",
117
 
  "/usr/share/fonts/type1/gsfonts",
118
 
  NULL
119
 
};
120
 
#endif
121
 
 
122
 
//------------------------------------------------------------------------
123
 
 
124
 
GlobalParams *globalParams = NULL;
125
 
 
126
 
//------------------------------------------------------------------------
127
 
// PSFontParam16
128
 
//------------------------------------------------------------------------
129
 
 
130
 
PSFontParam16::PSFontParam16(GString *nameA, int wModeA,
131
 
                             GString *psFontNameA, GString *encodingA) {
132
 
  name = nameA;
133
 
  wMode = wModeA;
134
 
  psFontName = psFontNameA;
135
 
  encoding = encodingA;
136
 
}
137
 
 
138
 
PSFontParam16::~PSFontParam16() {
139
 
  delete name;
140
 
  delete psFontName;
141
 
  delete encoding;
142
 
}
143
 
 
144
 
//------------------------------------------------------------------------
145
 
// SysFontInfo
146
 
//------------------------------------------------------------------------
147
 
 
148
 
class SysFontInfo {
149
 
public:
150
 
 
151
 
  GString *name;
152
 
  GBool bold;
153
 
  GBool italic;
154
 
  GString *path;
155
 
  SysFontType type;
156
 
  int fontNum;                  // for TrueType collections
157
 
 
158
 
  SysFontInfo(GString *nameA, GBool boldA, GBool italicA,
159
 
              GString *pathA, SysFontType typeA, int fontNumA);
160
 
  ~SysFontInfo();
161
 
  GBool match(SysFontInfo *fi);
162
 
  GBool match(GString *nameA, GBool boldA, GBool italicA);
163
 
};
164
 
 
165
 
SysFontInfo::SysFontInfo(GString *nameA, GBool boldA, GBool italicA,
166
 
                         GString *pathA, SysFontType typeA, int fontNumA) {
167
 
  name = nameA;
168
 
  bold = boldA;
169
 
  italic = italicA;
170
 
  path = pathA;
171
 
  type = typeA;
172
 
  fontNum = fontNumA;
173
 
}
174
 
 
175
 
SysFontInfo::~SysFontInfo() {
176
 
  delete name;
177
 
  delete path;
178
 
}
179
 
 
180
 
GBool SysFontInfo::match(SysFontInfo *fi) {
181
 
  return !strcasecmp(name->getCString(), fi->name->getCString()) &&
182
 
         bold == fi->bold && italic == fi->italic;
183
 
}
184
 
 
185
 
GBool SysFontInfo::match(GString *nameA, GBool boldA, GBool italicA) {
186
 
  return !strcasecmp(name->getCString(), nameA->getCString()) &&
187
 
         bold == boldA && italic == italicA;
188
 
}
189
 
 
190
 
//------------------------------------------------------------------------
191
 
// SysFontList
192
 
//------------------------------------------------------------------------
193
 
 
194
 
class SysFontList {
195
 
public:
196
 
 
197
 
  SysFontList();
198
 
  ~SysFontList();
199
 
  SysFontInfo *find(GString *name);
200
 
 
201
 
#ifdef WIN32
202
 
  void scanWindowsFonts(char *winFontDir);
203
 
#endif
204
 
 
205
 
private:
206
 
 
207
 
#ifdef WIN32
208
 
  SysFontInfo *makeWindowsFont(char *name, int fontNum,
209
 
                               char *path);
210
 
#endif
211
 
 
212
 
  GList *fonts;                 // [SysFontInfo]
213
 
};
214
 
 
215
 
SysFontList::SysFontList() {
216
 
  fonts = new GList();
217
 
}
218
 
 
219
 
SysFontList::~SysFontList() {
220
 
  deleteGList(fonts, SysFontInfo);
221
 
}
222
 
 
223
 
SysFontInfo *SysFontList::find(GString *name) {
224
 
  GString *name2;
225
 
  GBool bold, italic;
226
 
  SysFontInfo *fi;
227
 
  char c;
228
 
  int n, i;
229
 
 
230
 
  name2 = name->copy();
231
 
 
232
 
  // remove space, comma, dash chars
233
 
  i = 0;
234
 
  while (i < name2->getLength()) {
235
 
    c = name2->getChar(i);
236
 
    if (c == ' ' || c == ',' || c == '-') {
237
 
      name2->del(i);
238
 
    } else {
239
 
      ++i;
240
 
    }
241
 
  }
242
 
  n = name2->getLength();
243
 
 
244
 
  // remove trailing "MT" (Foo-MT, Foo-BoldMT, etc.)
245
 
  if (n > 2 && !strcmp(name2->getCString() + n - 2, "MT")) {
246
 
    name2->del(n - 2, 2);
247
 
    n -= 2;
248
 
  }
249
 
 
250
 
  // look for "Regular"
251
 
  if (n > 7 && !strcmp(name2->getCString() + n - 7, "Regular")) {
252
 
    name2->del(n - 7, 7);
253
 
    n -= 7;
254
 
  }
255
 
 
256
 
  // look for "Italic"
257
 
  if (n > 6 && !strcmp(name2->getCString() + n - 6, "Italic")) {
258
 
    name2->del(n - 6, 6);
259
 
    italic = gTrue;
260
 
    n -= 6;
261
 
  } else {
262
 
    italic = gFalse;
263
 
  }
264
 
 
265
 
  // look for "Bold"
266
 
  if (n > 4 && !strcmp(name2->getCString() + n - 4, "Bold")) {
267
 
    name2->del(n - 4, 4);
268
 
    bold = gTrue;
269
 
    n -= 4;
270
 
  } else {
271
 
    bold = gFalse;
272
 
  }
273
 
 
274
 
  // remove trailing "MT" (FooMT-Bold, etc.)
275
 
  if (n > 2 && !strcmp(name2->getCString() + n - 2, "MT")) {
276
 
    name2->del(n - 2, 2);
277
 
    n -= 2;
278
 
  }
279
 
 
280
 
  // remove trailing "PS"
281
 
  if (n > 2 && !strcmp(name2->getCString() + n - 2, "PS")) {
282
 
    name2->del(n - 2, 2);
283
 
    n -= 2;
284
 
  }
285
 
 
286
 
  // remove trailing "IdentityH"
287
 
  if (n > 9 && !strcmp(name2->getCString() + n - 9, "IdentityH")) {
288
 
    name2->del(n - 9, 9);
289
 
    n -= 9;
290
 
  }
291
 
 
292
 
  // search for the font
293
 
  fi = NULL;
294
 
  for (i = 0; i < fonts->getLength(); ++i) {
295
 
    fi = (SysFontInfo *)fonts->get(i);
296
 
    if (fi->match(name2, bold, italic)) {
297
 
      break;
298
 
    }
299
 
    fi = NULL;
300
 
  }
301
 
  if (!fi && bold) {
302
 
    // try ignoring the bold flag
303
 
    for (i = 0; i < fonts->getLength(); ++i) {
304
 
      fi = (SysFontInfo *)fonts->get(i);
305
 
      if (fi->match(name2, gFalse, italic)) {
306
 
        break;
307
 
      }
308
 
      fi = NULL;
309
 
    }
310
 
  }
311
 
  if (!fi && (bold || italic)) {
312
 
    // try ignoring the bold and italic flags
313
 
    for (i = 0; i < fonts->getLength(); ++i) {
314
 
      fi = (SysFontInfo *)fonts->get(i);
315
 
      if (fi->match(name2, gFalse, gFalse)) {
316
 
        break;
317
 
      }
318
 
      fi = NULL;
319
 
    }
320
 
  }
321
 
 
322
 
  delete name2;
323
 
  return fi;
324
 
}
325
 
 
326
 
#ifdef WIN32
327
 
void SysFontList::scanWindowsFonts(char *winFontDir) {
328
 
  OSVERSIONINFO version;
329
 
  char *path;
330
 
  DWORD idx, valNameLen, dataLen, type;
331
 
  HKEY regKey;
332
 
  char valName[1024], data[1024];
333
 
  int n, fontNum;
334
 
  char *p0, *p1;
335
 
  GString *fontPath;
336
 
 
337
 
  version.dwOSVersionInfoSize = sizeof(version);
338
 
  GetVersionEx(&version);
339
 
  if (version.dwPlatformId == VER_PLATFORM_WIN32_NT) {
340
 
    path = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts\\";
341
 
  } else {
342
 
    path = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Fonts\\";
343
 
  }
344
 
  if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, path, 0,
345
 
                   KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS,
346
 
                   &regKey) == ERROR_SUCCESS) {
347
 
    idx = 0;
348
 
    while (1) {
349
 
      valNameLen = sizeof(valName) - 1;
350
 
      dataLen = sizeof(data) - 1;
351
 
      if (RegEnumValue(regKey, idx, valName, &valNameLen, NULL,
352
 
                       &type, (LPBYTE)data, &dataLen) != ERROR_SUCCESS) {
353
 
        break;
354
 
      }
355
 
      if (type == REG_SZ &&
356
 
          valNameLen > 0 && valNameLen < sizeof(valName) &&
357
 
          dataLen > 0 && dataLen < sizeof(data)) {
358
 
        valName[valNameLen] = '\0';
359
 
        data[dataLen] = '\0';
360
 
        n = strlen(data);
361
 
        if (!strcasecmp(data + n - 4, ".ttf") ||
362
 
            !strcasecmp(data + n - 4, ".ttc")) {
363
 
          fontPath = new GString(data);
364
 
          if (!(dataLen >= 3 && data[1] == ':' && data[2] == '\\')) {
365
 
            fontPath->insert(0, '\\');
366
 
            fontPath->insert(0, winFontDir);
367
 
          }
368
 
          p0 = valName;
369
 
          fontNum = 0;
370
 
          while (*p0) {
371
 
            p1 = strstr(p0, " & ");
372
 
            if (p1) {
373
 
              *p1 = '\0';
374
 
              p1 = p1 + 3;
375
 
            } else {
376
 
              p1 = p0 + strlen(p0);
377
 
            }
378
 
            fonts->append(makeWindowsFont(p0, fontNum,
379
 
                                          fontPath->getCString()));
380
 
            p0 = p1;
381
 
            ++fontNum;
382
 
          }
383
 
          delete fontPath;
384
 
        }
385
 
      }
386
 
      ++idx;
387
 
    }
388
 
    RegCloseKey(regKey);
389
 
  }
390
 
}
391
 
 
392
 
SysFontInfo *SysFontList::makeWindowsFont(char *name, int fontNum,
393
 
                                          char *path) {
394
 
  int n;
395
 
  GBool bold, italic;
396
 
  GString *s;
397
 
  char c;
398
 
  int i;
399
 
  SysFontType type;
400
 
 
401
 
  n = strlen(name);
402
 
  bold = italic = gFalse;
403
 
 
404
 
  // remove trailing ' (TrueType)'
405
 
  if (n > 11 && !strncmp(name + n - 11, " (TrueType)", 11)) {
406
 
    n -= 11;
407
 
  }
408
 
 
409
 
  // remove trailing ' Italic'
410
 
  if (n > 7 && !strncmp(name + n - 7, " Italic", 7)) {
411
 
    n -= 7;
412
 
    italic = gTrue;
413
 
  }
414
 
 
415
 
  // remove trailing ' Bold'
416
 
  if (n > 5 && !strncmp(name + n - 5, " Bold", 5)) {
417
 
    n -= 5;
418
 
    bold = gTrue;
419
 
  }
420
 
 
421
 
  // remove trailing ' Regular'
422
 
  if (n > 5 && !strncmp(name + n - 8, " Regular", 8)) {
423
 
    n -= 8;
424
 
  }
425
 
 
426
 
  //----- normalize the font name
427
 
  s = new GString(name, n);
428
 
  i = 0;
429
 
  while (i < s->getLength()) {
430
 
    c = s->getChar(i);
431
 
    if (c == ' ' || c == ',' || c == '-') {
432
 
      s->del(i);
433
 
    } else {
434
 
      ++i;
435
 
    }
436
 
  }
437
 
 
438
 
  if (!strcasecmp(path + strlen(path) - 4, ".ttc")) {
439
 
    type = sysFontTTC;
440
 
  } else {
441
 
    type = sysFontTTF;
442
 
  }
443
 
  return new SysFontInfo(s, bold, italic, new GString(path), type, fontNum);
444
 
}
445
 
#endif
446
 
 
447
 
//------------------------------------------------------------------------
448
 
// KeyBinding
449
 
//------------------------------------------------------------------------
450
 
 
451
 
KeyBinding::KeyBinding(int codeA, int modsA, int contextA, const char *cmd0) {
452
 
  code = codeA;
453
 
  mods = modsA;
454
 
  context = contextA;
455
 
  cmds = new GList();
456
 
  cmds->append(new GString(cmd0));
457
 
}
458
 
 
459
 
KeyBinding::KeyBinding(int codeA, int modsA, int contextA,
460
 
                       const char *cmd0, const char *cmd1) {
461
 
  code = codeA;
462
 
  mods = modsA;
463
 
  context = contextA;
464
 
  cmds = new GList();
465
 
  cmds->append(new GString(cmd0));
466
 
  cmds->append(new GString(cmd1));
467
 
}
468
 
 
469
 
KeyBinding::KeyBinding(int codeA, int modsA, int contextA, GList *cmdsA) {
470
 
  code = codeA;
471
 
  mods = modsA;
472
 
  context = contextA;
473
 
  cmds = cmdsA;
474
 
}
475
 
 
476
 
KeyBinding::~KeyBinding() {
477
 
  deleteGList(cmds, GString);
478
 
}
479
 
 
480
 
#ifdef ENABLE_PLUGINS
481
 
//------------------------------------------------------------------------
482
 
// Plugin
483
 
//------------------------------------------------------------------------
484
 
 
485
 
class Plugin {
486
 
public:
487
 
 
488
 
  static Plugin *load(char *type, char *name);
489
 
  ~Plugin();
490
 
 
491
 
private:
492
 
 
493
 
#ifdef WIN32
494
 
  Plugin(HMODULE libA);
495
 
  HMODULE lib;
496
 
#else
497
 
  Plugin(void *dlA);
498
 
  void *dl;
499
 
#endif
500
 
};
501
 
 
502
 
Plugin *Plugin::load(char *type, char *name) {
503
 
  GString *path;
504
 
  Plugin *plugin;
505
 
  XpdfPluginVecTable *vt;
506
 
  XpdfBool (*xpdfInitPlugin)(void);
507
 
#ifdef WIN32
508
 
  HMODULE libA;
509
 
#else
510
 
  void *dlA;
511
 
#endif
512
 
 
513
 
  path = globalParams->getBaseDir();
514
 
  appendToPath(path, "plugins");
515
 
  appendToPath(path, type);
516
 
  appendToPath(path, name);
517
 
 
518
 
#ifdef WIN32
519
 
  path->append(".dll");
520
 
  if (!(libA = LoadLibrary(path->getCString()))) {
521
 
    error(errIO, -1, "Failed to load plugin '{0:t}'", path);
522
 
    goto err1;
523
 
  }
524
 
  if (!(vt = (XpdfPluginVecTable *)
525
 
                 GetProcAddress(libA, "xpdfPluginVecTable"))) {
526
 
    error(errIO, -1, "Failed to find xpdfPluginVecTable in plugin '{0:t}'",
527
 
          path);
528
 
    goto err2;
529
 
  }
530
 
#else
531
 
  //~ need to deal with other extensions here
532
 
  path->append(".so");
533
 
  if (!(dlA = dlopen(path->getCString(), RTLD_NOW))) {
534
 
    error(errIO, -1, "Failed to load plugin '{0:t}': {1:s}",
535
 
          path, dlerror());
536
 
    goto err1;
537
 
  }
538
 
  if (!(vt = (XpdfPluginVecTable *)dlsym(dlA, "xpdfPluginVecTable"))) {
539
 
    error(errIO, -1, "Failed to find xpdfPluginVecTable in plugin '{0:t}'",
540
 
          path);
541
 
    goto err2;
542
 
  }
543
 
#endif
544
 
 
545
 
  if (vt->version != xpdfPluginVecTable.version) {
546
 
    error(errIO, -1, "Plugin '{0:t}' is wrong version", path);
547
 
    goto err2;
548
 
  }
549
 
  memcpy(vt, &xpdfPluginVecTable, sizeof(xpdfPluginVecTable));
550
 
 
551
 
#ifdef WIN32
552
 
  if (!(xpdfInitPlugin = (XpdfBool (*)(void))
553
 
                             GetProcAddress(libA, "xpdfInitPlugin"))) {
554
 
    error(errIO, -1, "Failed to find xpdfInitPlugin in plugin '{0:t}'",
555
 
          path);
556
 
    goto err2;
557
 
  }
558
 
#else
559
 
  if (!(xpdfInitPlugin = (XpdfBool (*)(void))dlsym(dlA, "xpdfInitPlugin"))) {
560
 
    error(errIO, -1, "Failed to find xpdfInitPlugin in plugin '{0:t}'",
561
 
          path);
562
 
    goto err2;
563
 
  }
564
 
#endif
565
 
 
566
 
  if (!(*xpdfInitPlugin)()) {
567
 
    error(errIO, -1, "Initialization of plugin '{0:t}' failed", path);
568
 
    goto err2;
569
 
  }
570
 
 
571
 
#ifdef WIN32
572
 
  plugin = new Plugin(libA);
573
 
#else
574
 
  plugin = new Plugin(dlA);
575
 
#endif
576
 
 
577
 
  delete path;
578
 
  return plugin;
579
 
 
580
 
 err2:
581
 
#ifdef WIN32
582
 
  FreeLibrary(libA);
583
 
#else
584
 
  dlclose(dlA);
585
 
#endif
586
 
 err1:
587
 
  delete path;
588
 
  return NULL;
589
 
}
590
 
 
591
 
#ifdef WIN32
592
 
Plugin::Plugin(HMODULE libA) {
593
 
  lib = libA;
594
 
}
595
 
#else
596
 
Plugin::Plugin(void *dlA) {
597
 
  dl = dlA;
598
 
}
599
 
#endif
600
 
 
601
 
Plugin::~Plugin() {
602
 
  void (*xpdfFreePlugin)(void);
603
 
 
604
 
#ifdef WIN32
605
 
  if ((xpdfFreePlugin = (void (*)(void))
606
 
                            GetProcAddress(lib, "xpdfFreePlugin"))) {
607
 
    (*xpdfFreePlugin)();
608
 
  }
609
 
  FreeLibrary(lib);
610
 
#else
611
 
  if ((xpdfFreePlugin = (void (*)(void))dlsym(dl, "xpdfFreePlugin"))) {
612
 
    (*xpdfFreePlugin)();
613
 
  }
614
 
  dlclose(dl);
615
 
#endif
616
 
}
617
 
 
618
 
#endif // ENABLE_PLUGINS
619
 
 
620
 
//------------------------------------------------------------------------
621
 
// parsing
622
 
//------------------------------------------------------------------------
623
 
 
624
 
GlobalParams::GlobalParams(char *cfgFileName) {
625
 
  UnicodeMap *map;
626
 
  GString *fileName;
627
 
  FILE *f;
628
 
  int i;
629
 
 
630
 
#if MULTITHREADED
631
 
  gInitMutex(&mutex);
632
 
  gInitMutex(&unicodeMapCacheMutex);
633
 
  gInitMutex(&cMapCacheMutex);
634
 
#endif
635
 
 
636
 
  initBuiltinFontTables();
637
 
 
638
 
  // scan the encoding in reverse because we want the lowest-numbered
639
 
  // index for each char name ('space' is encoded twice)
640
 
  macRomanReverseMap = new NameToCharCode();
641
 
  for (i = 255; i >= 0; --i) {
642
 
    if (macRomanEncoding[i]) {
643
 
      macRomanReverseMap->add(macRomanEncoding[i], (CharCode)i);
644
 
    }
645
 
  }
646
 
 
647
 
#ifdef WIN32
648
 
  // baseDir will be set by a call to setBaseDir
649
 
  baseDir = new GString();
650
 
#else
651
 
  baseDir = appendToPath(getHomeDir(), ".xpdf");
652
 
#endif
653
 
  nameToUnicode = new NameToCharCode();
654
 
  cidToUnicodes = new GHash(gTrue);
655
 
  unicodeToUnicodes = new GHash(gTrue);
656
 
  residentUnicodeMaps = new GHash();
657
 
  unicodeMaps = new GHash(gTrue);
658
 
  cMapDirs = new GHash(gTrue);
659
 
  toUnicodeDirs = new GList();
660
 
  fontFiles = new GHash(gTrue);
661
 
  fontDirs = new GList();
662
 
  ccFontFiles = new GHash(gTrue);
663
 
  sysFonts = new SysFontList();
664
 
#if HAVE_PAPER_H
665
 
  char *paperName;
666
 
  const struct paper *paperType;
667
 
  paperinit();
668
 
  if ((paperName = systempapername())) {
669
 
    paperType = paperinfo(paperName);
670
 
    psPaperWidth = (int)paperpswidth(paperType);
671
 
    psPaperHeight = (int)paperpsheight(paperType);
672
 
  } else {
673
 
    error(errConfig, -1, "No paper information available - using defaults");
674
 
    psPaperWidth = defPaperWidth;
675
 
    psPaperHeight = defPaperHeight;
676
 
  }
677
 
  paperdone();
678
 
#else
679
 
  psPaperWidth = defPaperWidth;
680
 
  psPaperHeight = defPaperHeight;
681
 
#endif
682
 
  psImageableLLX = psImageableLLY = 0;
683
 
  psImageableURX = psPaperWidth;
684
 
  psImageableURY = psPaperHeight;
685
 
  psCrop = gTrue;
686
 
  psExpandSmaller = gFalse;
687
 
  psShrinkLarger = gTrue;
688
 
  psCenter = gTrue;
689
 
  psDuplex = gFalse;
690
 
  psLevel = psLevel2;
691
 
  psFile = NULL;
692
 
  psResidentFonts = new GHash(gTrue);
693
 
  psResidentFonts16 = new GList();
694
 
  psResidentFontsCC = new GList();
695
 
  psEmbedType1 = gTrue;
696
 
  psEmbedTrueType = gTrue;
697
 
  psEmbedCIDPostScript = gTrue;
698
 
  psEmbedCIDTrueType = gTrue;
699
 
  psFontPassthrough = gFalse;
700
 
  psPreload = gFalse;
701
 
  psOPI = gFalse;
702
 
  psASCIIHex = gFalse;
703
 
  psUncompressPreloadedImages = gFalse;
704
 
  psRasterResolution = 300;
705
 
  psRasterMono = gFalse;
706
 
  psAlwaysRasterize = gFalse;
707
 
  textEncoding = new GString("Latin1");
708
 
#if defined(WIN32)
709
 
  textEOL = eolDOS;
710
 
#elif defined(MACOS)
711
 
  textEOL = eolMac;
712
 
#else
713
 
  textEOL = eolUnix;
714
 
#endif
715
 
  textPageBreaks = gTrue;
716
 
  textKeepTinyChars = gFalse;
717
 
  initialZoom = new GString("125");
718
 
  continuousView = gFalse;
719
 
  enableT1lib = gTrue;
720
 
  enableFreeType = gTrue;
721
 
  disableFreeTypeHinting = gFalse;
722
 
  antialias = gTrue;
723
 
  vectorAntialias = gTrue;
724
 
  antialiasPrinting = gFalse;
725
 
  strokeAdjust = gTrue;
726
 
  screenType = screenUnset;
727
 
  screenSize = -1;
728
 
  screenDotRadius = -1;
729
 
  screenGamma = 1.0;
730
 
  screenBlackThreshold = 0.0;
731
 
  screenWhiteThreshold = 1.0;
732
 
  minLineWidth = 0.0;
733
 
  drawAnnotations = gTrue;
734
 
  overprintPreview = gFalse;
735
 
  launchCommand = NULL;
736
 
  urlCommand = NULL;
737
 
  movieCommand = NULL;
738
 
  mapNumericCharNames = gTrue;
739
 
  mapUnknownCharNames = gFalse;
740
 
  createDefaultKeyBindings();
741
 
  printCommands = gFalse;
742
 
  errQuiet = gFalse;
743
 
 
744
 
  cidToUnicodeCache = new CharCodeToUnicodeCache(cidToUnicodeCacheSize);
745
 
  unicodeToUnicodeCache =
746
 
      new CharCodeToUnicodeCache(unicodeToUnicodeCacheSize);
747
 
  unicodeMapCache = new UnicodeMapCache();
748
 
  cMapCache = new CMapCache();
749
 
 
750
 
#ifdef ENABLE_PLUGINS
751
 
  plugins = new GList();
752
 
  securityHandlers = new GList();
753
 
#endif
754
 
 
755
 
  // set up the initial nameToUnicode table
756
 
  for (i = 0; nameToUnicodeTab[i].name; ++i) {
757
 
    nameToUnicode->add(nameToUnicodeTab[i].name, nameToUnicodeTab[i].u);
758
 
  }
759
 
 
760
 
  // set up the residentUnicodeMaps table
761
 
  map = new UnicodeMap("Latin1", gFalse,
762
 
                       latin1UnicodeMapRanges, latin1UnicodeMapLen);
763
 
  residentUnicodeMaps->add(map->getEncodingName(), map);
764
 
  map = new UnicodeMap("ASCII7", gFalse,
765
 
                       ascii7UnicodeMapRanges, ascii7UnicodeMapLen);
766
 
  residentUnicodeMaps->add(map->getEncodingName(), map);
767
 
  map = new UnicodeMap("Symbol", gFalse,
768
 
                       symbolUnicodeMapRanges, symbolUnicodeMapLen);
769
 
  residentUnicodeMaps->add(map->getEncodingName(), map);
770
 
  map = new UnicodeMap("ZapfDingbats", gFalse, zapfDingbatsUnicodeMapRanges,
771
 
                       zapfDingbatsUnicodeMapLen);
772
 
  residentUnicodeMaps->add(map->getEncodingName(), map);
773
 
  map = new UnicodeMap("UTF-8", gTrue, &mapUTF8);
774
 
  residentUnicodeMaps->add(map->getEncodingName(), map);
775
 
  map = new UnicodeMap("UCS-2", gTrue, &mapUCS2);
776
 
  residentUnicodeMaps->add(map->getEncodingName(), map);
777
 
 
778
 
  // look for a user config file, then a system-wide config file
779
 
  f = NULL;
780
 
  fileName = NULL;
781
 
  if (cfgFileName && cfgFileName[0]) {
782
 
    fileName = new GString(cfgFileName);
783
 
    if (!(f = fopen(fileName->getCString(), "r"))) {
784
 
      delete fileName;
785
 
    }
786
 
  }
787
 
  if (!f) {
788
 
    fileName = appendToPath(getHomeDir(), xpdfUserConfigFile);
789
 
    if (!(f = fopen(fileName->getCString(), "r"))) {
790
 
      delete fileName;
791
 
    }
792
 
  }
793
 
  if (!f) {
794
 
#ifdef WIN32
795
 
    char buf[512];
796
 
    i = GetModuleFileName(NULL, buf, sizeof(buf));
797
 
    if (i <= 0 || i >= sizeof(buf)) {
798
 
      // error or path too long for buffer - just use the current dir
799
 
      buf[0] = '\0';
800
 
    }
801
 
    fileName = grabPath(buf);
802
 
    appendToPath(fileName, xpdfSysConfigFile);
803
 
#else
804
 
    fileName = new GString(xpdfSysConfigFile);
805
 
#endif
806
 
    if (!(f = fopen(fileName->getCString(), "r"))) {
807
 
      delete fileName;
808
 
    }
809
 
  }
810
 
  if (f) {
811
 
    parseFile(fileName, f);
812
 
    delete fileName;
813
 
    fclose(f);
814
 
  }
815
 
}
816
 
 
817
 
void GlobalParams::createDefaultKeyBindings() {
818
 
  keyBindings = new GList();
819
 
 
820
 
  //----- mouse buttons
821
 
  keyBindings->append(new KeyBinding(xpdfKeyCodeMousePress1, xpdfKeyModNone,
822
 
                                     xpdfKeyContextAny, "startSelection"));
823
 
  keyBindings->append(new KeyBinding(xpdfKeyCodeMouseRelease1, xpdfKeyModNone,
824
 
                                     xpdfKeyContextAny, "endSelection",
825
 
                                     "followLinkNoSel"));
826
 
  keyBindings->append(new KeyBinding(xpdfKeyCodeMousePress2, xpdfKeyModNone,
827
 
                                     xpdfKeyContextAny, "startPan"));
828
 
  keyBindings->append(new KeyBinding(xpdfKeyCodeMouseRelease2, xpdfKeyModNone,
829
 
                                     xpdfKeyContextAny, "endPan"));
830
 
  keyBindings->append(new KeyBinding(xpdfKeyCodeMousePress3, xpdfKeyModNone,
831
 
                                     xpdfKeyContextAny, "postPopupMenu"));
832
 
  keyBindings->append(new KeyBinding(xpdfKeyCodeMousePress4, xpdfKeyModNone,
833
 
                                     xpdfKeyContextAny,
834
 
                                     "scrollUpPrevPage(16)"));
835
 
  keyBindings->append(new KeyBinding(xpdfKeyCodeMousePress5, xpdfKeyModNone,
836
 
                                     xpdfKeyContextAny,
837
 
                                     "scrollDownNextPage(16)"));
838
 
  keyBindings->append(new KeyBinding(xpdfKeyCodeMousePress6, xpdfKeyModNone,
839
 
                                     xpdfKeyContextAny, "scrollLeft(16)"));
840
 
  keyBindings->append(new KeyBinding(xpdfKeyCodeMousePress7, xpdfKeyModNone,
841
 
                                     xpdfKeyContextAny, "scrollRight(16)"));
842
 
 
843
 
  //----- keys
844
 
  keyBindings->append(new KeyBinding(xpdfKeyCodeHome, xpdfKeyModCtrl,
845
 
                                     xpdfKeyContextAny, "gotoPage(1)"));
846
 
  keyBindings->append(new KeyBinding(xpdfKeyCodeHome, xpdfKeyModNone,
847
 
                                     xpdfKeyContextAny, "scrollToTopLeft"));
848
 
  keyBindings->append(new KeyBinding(xpdfKeyCodeEnd, xpdfKeyModCtrl,
849
 
                                     xpdfKeyContextAny, "gotoLastPage"));
850
 
  keyBindings->append(new KeyBinding(xpdfKeyCodeEnd, xpdfKeyModNone,
851
 
                                     xpdfKeyContextAny,
852
 
                                     "scrollToBottomRight"));
853
 
  keyBindings->append(new KeyBinding(xpdfKeyCodePgUp, xpdfKeyModNone,
854
 
                                     xpdfKeyContextAny, "pageUp"));
855
 
  keyBindings->append(new KeyBinding(xpdfKeyCodeBackspace, xpdfKeyModNone,
856
 
                                     xpdfKeyContextAny, "pageUp"));
857
 
  keyBindings->append(new KeyBinding(xpdfKeyCodeDelete, xpdfKeyModNone,
858
 
                                     xpdfKeyContextAny, "pageUp"));
859
 
  keyBindings->append(new KeyBinding(xpdfKeyCodePgDn, xpdfKeyModNone,
860
 
                                     xpdfKeyContextAny, "pageDown"));
861
 
  keyBindings->append(new KeyBinding(' ', xpdfKeyModNone,
862
 
                                     xpdfKeyContextAny, "pageDown"));
863
 
  keyBindings->append(new KeyBinding(xpdfKeyCodeLeft, xpdfKeyModNone,
864
 
                                     xpdfKeyContextAny, "scrollLeft(16)"));
865
 
  keyBindings->append(new KeyBinding(xpdfKeyCodeRight, xpdfKeyModNone,
866
 
                                     xpdfKeyContextAny, "scrollRight(16)"));
867
 
  keyBindings->append(new KeyBinding(xpdfKeyCodeUp, xpdfKeyModNone,
868
 
                                     xpdfKeyContextAny, "scrollUp(16)"));
869
 
  keyBindings->append(new KeyBinding(xpdfKeyCodeDown, xpdfKeyModNone,
870
 
                                     xpdfKeyContextAny, "scrollDown(16)"));
871
 
  keyBindings->append(new KeyBinding('o', xpdfKeyModNone,
872
 
                                     xpdfKeyContextAny, "open"));
873
 
  keyBindings->append(new KeyBinding('O', xpdfKeyModNone,
874
 
                                     xpdfKeyContextAny, "open"));
875
 
  keyBindings->append(new KeyBinding('r', xpdfKeyModNone,
876
 
                                     xpdfKeyContextAny, "reload"));
877
 
  keyBindings->append(new KeyBinding('R', xpdfKeyModNone,
878
 
                                     xpdfKeyContextAny, "reload"));
879
 
  keyBindings->append(new KeyBinding('f', xpdfKeyModNone,
880
 
                                     xpdfKeyContextAny, "find"));
881
 
  keyBindings->append(new KeyBinding('F', xpdfKeyModNone,
882
 
                                     xpdfKeyContextAny, "find"));
883
 
  keyBindings->append(new KeyBinding('f', xpdfKeyModCtrl,
884
 
                                     xpdfKeyContextAny, "find"));
885
 
  keyBindings->append(new KeyBinding('g', xpdfKeyModCtrl,
886
 
                                     xpdfKeyContextAny, "findNext"));
887
 
  keyBindings->append(new KeyBinding('p', xpdfKeyModCtrl,
888
 
                                     xpdfKeyContextAny, "print"));
889
 
  keyBindings->append(new KeyBinding('n', xpdfKeyModNone,
890
 
                                     xpdfKeyContextScrLockOff, "nextPage"));
891
 
  keyBindings->append(new KeyBinding('N', xpdfKeyModNone,
892
 
                                     xpdfKeyContextScrLockOff, "nextPage"));
893
 
  keyBindings->append(new KeyBinding('n', xpdfKeyModNone,
894
 
                                     xpdfKeyContextScrLockOn,
895
 
                                     "nextPageNoScroll"));
896
 
  keyBindings->append(new KeyBinding('N', xpdfKeyModNone,
897
 
                                     xpdfKeyContextScrLockOn,
898
 
                                     "nextPageNoScroll"));
899
 
  keyBindings->append(new KeyBinding('p', xpdfKeyModNone,
900
 
                                     xpdfKeyContextScrLockOff, "prevPage"));
901
 
  keyBindings->append(new KeyBinding('P', xpdfKeyModNone,
902
 
                                     xpdfKeyContextScrLockOff, "prevPage"));
903
 
  keyBindings->append(new KeyBinding('p', xpdfKeyModNone,
904
 
                                     xpdfKeyContextScrLockOn,
905
 
                                     "prevPageNoScroll"));
906
 
  keyBindings->append(new KeyBinding('P', xpdfKeyModNone,
907
 
                                     xpdfKeyContextScrLockOn,
908
 
                                     "prevPageNoScroll"));
909
 
  keyBindings->append(new KeyBinding('v', xpdfKeyModNone,
910
 
                                     xpdfKeyContextAny, "goForward"));
911
 
  keyBindings->append(new KeyBinding('b', xpdfKeyModNone,
912
 
                                     xpdfKeyContextAny, "goBackward"));
913
 
  keyBindings->append(new KeyBinding('g', xpdfKeyModNone,
914
 
                                     xpdfKeyContextAny, "focusToPageNum"));
915
 
  keyBindings->append(new KeyBinding('0', xpdfKeyModNone,
916
 
                                     xpdfKeyContextAny, "zoomPercent(125)"));
917
 
  keyBindings->append(new KeyBinding('+', xpdfKeyModNone,
918
 
                                     xpdfKeyContextAny, "zoomIn"));
919
 
  keyBindings->append(new KeyBinding('-', xpdfKeyModNone,
920
 
                                     xpdfKeyContextAny, "zoomOut"));
921
 
  keyBindings->append(new KeyBinding('z', xpdfKeyModNone,
922
 
                                     xpdfKeyContextAny, "zoomFitPage"));
923
 
  keyBindings->append(new KeyBinding('w', xpdfKeyModNone,
924
 
                                     xpdfKeyContextAny, "zoomFitWidth"));
925
 
  keyBindings->append(new KeyBinding('h', xpdfKeyModNone,
926
 
                                     xpdfKeyContextAny, "zoomFitHeight"));
927
 
  keyBindings->append(new KeyBinding('f', xpdfKeyModAlt,
928
 
                                     xpdfKeyContextAny,
929
 
                                     "toggleFullScreenMode"));
930
 
  keyBindings->append(new KeyBinding('l', xpdfKeyModCtrl,
931
 
                                     xpdfKeyContextAny, "redraw"));
932
 
  keyBindings->append(new KeyBinding('w', xpdfKeyModCtrl,
933
 
                                     xpdfKeyContextAny, "closeWindow"));
934
 
  keyBindings->append(new KeyBinding('?', xpdfKeyModNone,
935
 
                                     xpdfKeyContextAny, "about"));
936
 
  keyBindings->append(new KeyBinding('q', xpdfKeyModNone,
937
 
                                     xpdfKeyContextAny, "quit"));
938
 
  keyBindings->append(new KeyBinding('Q', xpdfKeyModNone,
939
 
                                     xpdfKeyContextAny, "quit"));
940
 
}
941
 
 
942
 
void GlobalParams::parseFile(GString *fileName, FILE *f) {
943
 
  int line;
944
 
  char buf[512];
945
 
 
946
 
  line = 1;
947
 
  while (getLine(buf, sizeof(buf) - 1, f)) {
948
 
    parseLine(buf, fileName, line);
949
 
    ++line;
950
 
  }
951
 
}
952
 
 
953
 
void GlobalParams::parseLine(char *buf, GString *fileName, int line) {
954
 
  GList *tokens;
955
 
  GString *cmd, *incFile;
956
 
  char *p1, *p2;
957
 
  FILE *f2;
958
 
 
959
 
  // break the line into tokens
960
 
  tokens = new GList();
961
 
  p1 = buf;
962
 
  while (*p1) {
963
 
    for (; *p1 && isspace(*p1); ++p1) ;
964
 
    if (!*p1) {
965
 
      break;
966
 
    }
967
 
    if (*p1 == '"' || *p1 == '\'') {
968
 
      for (p2 = p1 + 1; *p2 && *p2 != *p1; ++p2) ;
969
 
      ++p1;
970
 
    } else {
971
 
      for (p2 = p1 + 1; *p2 && !isspace(*p2); ++p2) ;
972
 
    }
973
 
    tokens->append(new GString(p1, (int)(p2 - p1)));
974
 
    p1 = *p2 ? p2 + 1 : p2;
975
 
  }
976
 
 
977
 
  // parse the line
978
 
  if (tokens->getLength() > 0 &&
979
 
      ((GString *)tokens->get(0))->getChar(0) != '#') {
980
 
    cmd = (GString *)tokens->get(0);
981
 
    if (!cmd->cmp("include")) {
982
 
      if (tokens->getLength() == 2) {
983
 
        incFile = (GString *)tokens->get(1);
984
 
        if ((f2 = openFile(incFile->getCString(), "r"))) {
985
 
          parseFile(incFile, f2);
986
 
          fclose(f2);
987
 
        } else {
988
 
          error(errConfig, -1,
989
 
                "Couldn't find included config file: '{0:t}' ({1:t}:{2:d})",
990
 
                incFile, fileName, line);
991
 
        }
992
 
      } else {
993
 
        error(errConfig, -1, "Bad 'include' config file command ({0:t}:{1:d})",
994
 
              fileName, line);
995
 
      }
996
 
    } else if (!cmd->cmp("nameToUnicode")) {
997
 
      parseNameToUnicode(tokens, fileName, line);
998
 
    } else if (!cmd->cmp("cidToUnicode")) {
999
 
      parseCIDToUnicode(tokens, fileName, line);
1000
 
    } else if (!cmd->cmp("unicodeToUnicode")) {
1001
 
      parseUnicodeToUnicode(tokens, fileName, line);
1002
 
    } else if (!cmd->cmp("unicodeMap")) {
1003
 
      parseUnicodeMap(tokens, fileName, line);
1004
 
    } else if (!cmd->cmp("cMapDir")) {
1005
 
      parseCMapDir(tokens, fileName, line);
1006
 
    } else if (!cmd->cmp("toUnicodeDir")) {
1007
 
      parseToUnicodeDir(tokens, fileName, line);
1008
 
    } else if (!cmd->cmp("fontFile")) {
1009
 
      parseFontFile(tokens, fileName, line);
1010
 
    } else if (!cmd->cmp("fontDir")) {
1011
 
      parseFontDir(tokens, fileName, line);
1012
 
    } else if (!cmd->cmp("fontFileCC")) {
1013
 
      parseFontFileCC(tokens, fileName, line);
1014
 
    } else if (!cmd->cmp("psFile")) {
1015
 
      parsePSFile(tokens, fileName, line);
1016
 
    } else if (!cmd->cmp("psPaperSize")) {
1017
 
      parsePSPaperSize(tokens, fileName, line);
1018
 
    } else if (!cmd->cmp("psImageableArea")) {
1019
 
      parsePSImageableArea(tokens, fileName, line);
1020
 
    } else if (!cmd->cmp("psCrop")) {
1021
 
      parseYesNo("psCrop", &psCrop, tokens, fileName, line);
1022
 
    } else if (!cmd->cmp("psExpandSmaller")) {
1023
 
      parseYesNo("psExpandSmaller", &psExpandSmaller,
1024
 
                 tokens, fileName, line);
1025
 
    } else if (!cmd->cmp("psShrinkLarger")) {
1026
 
      parseYesNo("psShrinkLarger", &psShrinkLarger, tokens, fileName, line);
1027
 
    } else if (!cmd->cmp("psCenter")) {
1028
 
      parseYesNo("psCenter", &psCenter, tokens, fileName, line);
1029
 
    } else if (!cmd->cmp("psDuplex")) {
1030
 
      parseYesNo("psDuplex", &psDuplex, tokens, fileName, line);
1031
 
    } else if (!cmd->cmp("psLevel")) {
1032
 
      parsePSLevel(tokens, fileName, line);
1033
 
    } else if (!cmd->cmp("psResidentFont")) {
1034
 
      parsePSResidentFont(tokens, fileName, line);
1035
 
    } else if (!cmd->cmp("psResidentFont16")) {
1036
 
      parsePSResidentFont16(tokens, fileName, line);
1037
 
    } else if (!cmd->cmp("psResidentFontCC")) {
1038
 
      parsePSResidentFontCC(tokens, fileName, line);
1039
 
    } else if (!cmd->cmp("psEmbedType1Fonts")) {
1040
 
      parseYesNo("psEmbedType1", &psEmbedType1, tokens, fileName, line);
1041
 
    } else if (!cmd->cmp("psEmbedTrueTypeFonts")) {
1042
 
      parseYesNo("psEmbedTrueType", &psEmbedTrueType,
1043
 
                 tokens, fileName, line);
1044
 
    } else if (!cmd->cmp("psEmbedCIDPostScriptFonts")) {
1045
 
      parseYesNo("psEmbedCIDPostScript", &psEmbedCIDPostScript,
1046
 
                 tokens, fileName, line);
1047
 
    } else if (!cmd->cmp("psEmbedCIDTrueTypeFonts")) {
1048
 
      parseYesNo("psEmbedCIDTrueType", &psEmbedCIDTrueType,
1049
 
                 tokens, fileName, line);
1050
 
    } else if (!cmd->cmp("psFontPassthrough")) {
1051
 
      parseYesNo("psFontPassthrough", &psFontPassthrough,
1052
 
                 tokens, fileName, line);
1053
 
    } else if (!cmd->cmp("psPreload")) {
1054
 
      parseYesNo("psPreload", &psPreload, tokens, fileName, line);
1055
 
    } else if (!cmd->cmp("psOPI")) {
1056
 
      parseYesNo("psOPI", &psOPI, tokens, fileName, line);
1057
 
    } else if (!cmd->cmp("psASCIIHex")) {
1058
 
      parseYesNo("psASCIIHex", &psASCIIHex, tokens, fileName, line);
1059
 
    } else if (!cmd->cmp("psUncompressPreloadedImages")) {
1060
 
      parseYesNo("psUncompressPreloadedImages", &psUncompressPreloadedImages,
1061
 
                 tokens, fileName, line);
1062
 
    } else if (!cmd->cmp("psRasterResolution")) {
1063
 
      parseFloat("psRasterResolution", &psRasterResolution,
1064
 
                 tokens, fileName, line);
1065
 
    } else if (!cmd->cmp("psRasterMono")) {
1066
 
      parseYesNo("psRasterMono", &psRasterMono, tokens, fileName, line);
1067
 
    } else if (!cmd->cmp("psAlwaysRasterize")) {
1068
 
      parseYesNo("psAlwaysRasterize", &psAlwaysRasterize,
1069
 
                 tokens, fileName, line);
1070
 
    } else if (!cmd->cmp("textEncoding")) {
1071
 
      parseTextEncoding(tokens, fileName, line);
1072
 
    } else if (!cmd->cmp("textEOL")) {
1073
 
      parseTextEOL(tokens, fileName, line);
1074
 
    } else if (!cmd->cmp("textPageBreaks")) {
1075
 
      parseYesNo("textPageBreaks", &textPageBreaks,
1076
 
                 tokens, fileName, line);
1077
 
    } else if (!cmd->cmp("textKeepTinyChars")) {
1078
 
      parseYesNo("textKeepTinyChars", &textKeepTinyChars,
1079
 
                 tokens, fileName, line);
1080
 
    } else if (!cmd->cmp("initialZoom")) {
1081
 
      parseInitialZoom(tokens, fileName, line);
1082
 
    } else if (!cmd->cmp("continuousView")) {
1083
 
      parseYesNo("continuousView", &continuousView, tokens, fileName, line);
1084
 
    } else if (!cmd->cmp("enableT1lib")) {
1085
 
      parseYesNo("enableT1lib", &enableT1lib, tokens, fileName, line);
1086
 
    } else if (!cmd->cmp("enableFreeType")) {
1087
 
      parseYesNo("enableFreeType", &enableFreeType, tokens, fileName, line);
1088
 
    } else if (!cmd->cmp("disableFreeTypeHinting")) {
1089
 
      parseYesNo("disableFreeTypeHinting", &disableFreeTypeHinting,
1090
 
                 tokens, fileName, line);
1091
 
    } else if (!cmd->cmp("antialias")) {
1092
 
      parseYesNo("antialias", &antialias, tokens, fileName, line);
1093
 
    } else if (!cmd->cmp("vectorAntialias")) {
1094
 
      parseYesNo("vectorAntialias", &vectorAntialias,
1095
 
                 tokens, fileName, line);
1096
 
    } else if (!cmd->cmp("antialiasPrinting")) {
1097
 
      parseYesNo("antialiasPrinting", &antialiasPrinting,
1098
 
                 tokens, fileName, line);
1099
 
    } else if (!cmd->cmp("strokeAdjust")) {
1100
 
      parseYesNo("strokeAdjust", &strokeAdjust, tokens, fileName, line);
1101
 
    } else if (!cmd->cmp("screenType")) {
1102
 
      parseScreenType(tokens, fileName, line);
1103
 
    } else if (!cmd->cmp("screenSize")) {
1104
 
      parseInteger("screenSize", &screenSize, tokens, fileName, line);
1105
 
    } else if (!cmd->cmp("screenDotRadius")) {
1106
 
      parseInteger("screenDotRadius", &screenDotRadius,
1107
 
                   tokens, fileName, line);
1108
 
    } else if (!cmd->cmp("screenGamma")) {
1109
 
      parseFloat("screenGamma", &screenGamma,
1110
 
                 tokens, fileName, line);
1111
 
    } else if (!cmd->cmp("screenBlackThreshold")) {
1112
 
      parseFloat("screenBlackThreshold", &screenBlackThreshold,
1113
 
                 tokens, fileName, line);
1114
 
    } else if (!cmd->cmp("screenWhiteThreshold")) {
1115
 
      parseFloat("screenWhiteThreshold", &screenWhiteThreshold,
1116
 
                 tokens, fileName, line);
1117
 
    } else if (!cmd->cmp("minLineWidth")) {
1118
 
      parseFloat("minLineWidth", &minLineWidth,
1119
 
                 tokens, fileName, line);
1120
 
    } else if (!cmd->cmp("drawAnnotations")) {
1121
 
      parseYesNo("drawAnnotations", &drawAnnotations,
1122
 
                 tokens, fileName, line);
1123
 
    } else if (!cmd->cmp("overprintPreview")) {
1124
 
      parseYesNo("overprintPreview", &overprintPreview,
1125
 
                 tokens, fileName, line);
1126
 
    } else if (!cmd->cmp("launchCommand")) {
1127
 
      parseCommand("launchCommand", &launchCommand, tokens, fileName, line);
1128
 
    } else if (!cmd->cmp("urlCommand")) {
1129
 
      parseCommand("urlCommand", &urlCommand, tokens, fileName, line);
1130
 
    } else if (!cmd->cmp("movieCommand")) {
1131
 
      parseCommand("movieCommand", &movieCommand, tokens, fileName, line);
1132
 
    } else if (!cmd->cmp("mapNumericCharNames")) {
1133
 
      parseYesNo("mapNumericCharNames", &mapNumericCharNames,
1134
 
                 tokens, fileName, line);
1135
 
    } else if (!cmd->cmp("mapUnknownCharNames")) {
1136
 
      parseYesNo("mapUnknownCharNames", &mapUnknownCharNames,
1137
 
                 tokens, fileName, line);
1138
 
    } else if (!cmd->cmp("bind")) {
1139
 
      parseBind(tokens, fileName, line);
1140
 
    } else if (!cmd->cmp("unbind")) {
1141
 
      parseUnbind(tokens, fileName, line);
1142
 
    } else if (!cmd->cmp("printCommands")) {
1143
 
      parseYesNo("printCommands", &printCommands, tokens, fileName, line);
1144
 
    } else if (!cmd->cmp("errQuiet")) {
1145
 
      parseYesNo("errQuiet", &errQuiet, tokens, fileName, line);
1146
 
    } else {
1147
 
      error(errConfig, -1, "Unknown config file command '{0:t}' ({1:t}:{2:d})",
1148
 
            cmd, fileName, line);
1149
 
      if (!cmd->cmp("displayFontX") ||
1150
 
          !cmd->cmp("displayNamedCIDFontX") ||
1151
 
          !cmd->cmp("displayCIDFontX")) {
1152
 
        error(errConfig, -1, "Xpdf no longer supports X fonts");
1153
 
      } else if (!cmd->cmp("t1libControl") || !cmd->cmp("freetypeControl")) {
1154
 
        error(errConfig, -1,
1155
 
              "The t1libControl and freetypeControl options have been replaced by the enableT1lib, enableFreeType, and antialias options");
1156
 
      } else if (!cmd->cmp("fontpath") || !cmd->cmp("fontmap")) {
1157
 
        error(errConfig, -1,
1158
 
              "The config file format has changed since Xpdf 0.9x");
1159
 
      }
1160
 
    }
1161
 
  }
1162
 
 
1163
 
  deleteGList(tokens, GString);
1164
 
}
1165
 
 
1166
 
void GlobalParams::parseNameToUnicode(GList *tokens, GString *fileName,
1167
 
                                      int line) {
1168
 
  GString *name;
1169
 
  char *tok1, *tok2;
1170
 
  FILE *f;
1171
 
  char buf[256];
1172
 
  int line2;
1173
 
  Unicode u;
1174
 
 
1175
 
  if (tokens->getLength() != 2) {
1176
 
    error(errConfig, -1,
1177
 
          "Bad 'nameToUnicode' config file command ({0:t}:{1:d})",
1178
 
          fileName, line);
1179
 
    return;
1180
 
  }
1181
 
  name = (GString *)tokens->get(1);
1182
 
  if (!(f = openFile(name->getCString(), "r"))) {
1183
 
    error(errConfig, -1, "Couldn't open 'nameToUnicode' file '{0:t}'", name);
1184
 
    return;
1185
 
  }
1186
 
  line2 = 1;
1187
 
  while (getLine(buf, sizeof(buf), f)) {
1188
 
    tok1 = strtok(buf, " \t\r\n");
1189
 
    tok2 = strtok(NULL, " \t\r\n");
1190
 
    if (tok1 && tok2) {
1191
 
      sscanf(tok1, "%x", &u);
1192
 
      nameToUnicode->add(tok2, u);
1193
 
    } else {
1194
 
      error(errConfig, -1, "Bad line in 'nameToUnicode' file ({0:t}:{1:d})",
1195
 
            name, line2);
1196
 
    }
1197
 
    ++line2;
1198
 
  }
1199
 
  fclose(f);
1200
 
}
1201
 
 
1202
 
void GlobalParams::parseCIDToUnicode(GList *tokens, GString *fileName,
1203
 
                                     int line) {
1204
 
  GString *collection, *name, *old;
1205
 
 
1206
 
  if (tokens->getLength() != 3) {
1207
 
    error(errConfig, -1,
1208
 
          "Bad 'cidToUnicode' config file command ({0:t}:{1:d})",
1209
 
          fileName, line);
1210
 
    return;
1211
 
  }
1212
 
  collection = (GString *)tokens->get(1);
1213
 
  name = (GString *)tokens->get(2);
1214
 
  if ((old = (GString *)cidToUnicodes->remove(collection))) {
1215
 
    delete old;
1216
 
  }
1217
 
  cidToUnicodes->add(collection->copy(), name->copy());
1218
 
}
1219
 
 
1220
 
void GlobalParams::parseUnicodeToUnicode(GList *tokens, GString *fileName,
1221
 
                                         int line) {
1222
 
  GString *font, *file, *old;
1223
 
 
1224
 
  if (tokens->getLength() != 3) {
1225
 
    error(errConfig, -1,
1226
 
          "Bad 'unicodeToUnicode' config file command ({0:t}:{1:d})",
1227
 
          fileName, line);
1228
 
    return;
1229
 
  }
1230
 
  font = (GString *)tokens->get(1);
1231
 
  file = (GString *)tokens->get(2);
1232
 
  if ((old = (GString *)unicodeToUnicodes->remove(font))) {
1233
 
    delete old;
1234
 
  }
1235
 
  unicodeToUnicodes->add(font->copy(), file->copy());
1236
 
}
1237
 
 
1238
 
void GlobalParams::parseUnicodeMap(GList *tokens, GString *fileName,
1239
 
                                   int line) {
1240
 
  GString *encodingName, *name, *old;
1241
 
 
1242
 
  if (tokens->getLength() != 3) {
1243
 
    error(errConfig, -1, "Bad 'unicodeMap' config file command ({0:t}:{1:d})",
1244
 
          fileName, line);
1245
 
    return;
1246
 
  }
1247
 
  encodingName = (GString *)tokens->get(1);
1248
 
  name = (GString *)tokens->get(2);
1249
 
  if ((old = (GString *)unicodeMaps->remove(encodingName))) {
1250
 
    delete old;
1251
 
  }
1252
 
  unicodeMaps->add(encodingName->copy(), name->copy());
1253
 
}
1254
 
 
1255
 
void GlobalParams::parseCMapDir(GList *tokens, GString *fileName, int line) {
1256
 
  GString *collection, *dir;
1257
 
  GList *list;
1258
 
 
1259
 
  if (tokens->getLength() != 3) {
1260
 
    error(errConfig, -1, "Bad 'cMapDir' config file command ({0:t}:{1:d})",
1261
 
          fileName, line);
1262
 
    return;
1263
 
  }
1264
 
  collection = (GString *)tokens->get(1);
1265
 
  dir = (GString *)tokens->get(2);
1266
 
  if (!(list = (GList *)cMapDirs->lookup(collection))) {
1267
 
    list = new GList();
1268
 
    cMapDirs->add(collection->copy(), list);
1269
 
  }
1270
 
  list->append(dir->copy());
1271
 
}
1272
 
 
1273
 
void GlobalParams::parseToUnicodeDir(GList *tokens, GString *fileName,
1274
 
                                     int line) {
1275
 
  if (tokens->getLength() != 2) {
1276
 
    error(errConfig, -1,
1277
 
          "Bad 'toUnicodeDir' config file command ({0:t}:{1:d})",
1278
 
          fileName, line);
1279
 
    return;
1280
 
  }
1281
 
  toUnicodeDirs->append(((GString *)tokens->get(1))->copy());
1282
 
}
1283
 
 
1284
 
void GlobalParams::parseFontFile(GList *tokens, GString *fileName, int line) {
1285
 
  if (tokens->getLength() != 3) {
1286
 
    error(errConfig, -1, "Bad 'fontFile' config file command ({0:t}:{1:d})",
1287
 
          fileName, line);
1288
 
    return;
1289
 
  }
1290
 
  fontFiles->add(((GString *)tokens->get(1))->copy(),
1291
 
                 ((GString *)tokens->get(2))->copy());
1292
 
}
1293
 
 
1294
 
void GlobalParams::parseFontDir(GList *tokens, GString *fileName, int line) {
1295
 
  if (tokens->getLength() != 2) {
1296
 
    error(errConfig, -1, "Bad 'fontDir' config file command ({0:t}:{1:d})",
1297
 
          fileName, line);
1298
 
    return;
1299
 
  }
1300
 
  fontDirs->append(((GString *)tokens->get(1))->copy());
1301
 
}
1302
 
 
1303
 
void GlobalParams::parseFontFileCC(GList *tokens, GString *fileName,
1304
 
                                   int line) {
1305
 
  if (tokens->getLength() != 3) {
1306
 
    error(errConfig, -1, "Bad 'fontFileCC' config file command ({0:t}:{1:d})",
1307
 
          fileName, line);
1308
 
    return;
1309
 
  }
1310
 
  ccFontFiles->add(((GString *)tokens->get(1))->copy(),
1311
 
                   ((GString *)tokens->get(2))->copy());
1312
 
}
1313
 
 
1314
 
void GlobalParams::parsePSFile(GList *tokens, GString *fileName, int line) {
1315
 
  if (tokens->getLength() != 2) {
1316
 
    error(errConfig, -1, "Bad 'psFile' config file command ({0:t}:{1:d})",
1317
 
          fileName, line);
1318
 
    return;
1319
 
  }
1320
 
  if (psFile) {
1321
 
    delete psFile;
1322
 
  }
1323
 
  psFile = ((GString *)tokens->get(1))->copy();
1324
 
}
1325
 
 
1326
 
void GlobalParams::parsePSPaperSize(GList *tokens, GString *fileName,
1327
 
                                    int line) {
1328
 
  GString *tok;
1329
 
 
1330
 
  if (tokens->getLength() == 2) {
1331
 
    tok = (GString *)tokens->get(1);
1332
 
    if (!setPSPaperSize(tok->getCString())) {
1333
 
      error(errConfig, -1,
1334
 
            "Bad 'psPaperSize' config file command ({0:s}:{1:d})",
1335
 
            fileName, line);
1336
 
    }
1337
 
  } else if (tokens->getLength() == 3) {
1338
 
    tok = (GString *)tokens->get(1);
1339
 
    psPaperWidth = atoi(tok->getCString());
1340
 
    tok = (GString *)tokens->get(2);
1341
 
    psPaperHeight = atoi(tok->getCString());
1342
 
    psImageableLLX = psImageableLLY = 0;
1343
 
    psImageableURX = psPaperWidth;
1344
 
    psImageableURY = psPaperHeight;
1345
 
  } else {
1346
 
    error(errConfig, -1, "Bad 'psPaperSize' config file command ({0:t}:{1:d})",
1347
 
          fileName, line);
1348
 
  }
1349
 
}
1350
 
 
1351
 
void GlobalParams::parsePSImageableArea(GList *tokens, GString *fileName,
1352
 
                                        int line) {
1353
 
  if (tokens->getLength() != 5) {
1354
 
    error(errConfig, -1,
1355
 
          "Bad 'psImageableArea' config file command ({0:t}:{1:d})",
1356
 
          fileName, line);
1357
 
    return;
1358
 
  }
1359
 
  psImageableLLX = atoi(((GString *)tokens->get(1))->getCString());
1360
 
  psImageableLLY = atoi(((GString *)tokens->get(2))->getCString());
1361
 
  psImageableURX = atoi(((GString *)tokens->get(3))->getCString());
1362
 
  psImageableURY = atoi(((GString *)tokens->get(4))->getCString());
1363
 
}
1364
 
 
1365
 
void GlobalParams::parsePSLevel(GList *tokens, GString *fileName, int line) {
1366
 
  GString *tok;
1367
 
 
1368
 
  if (tokens->getLength() != 2) {
1369
 
    error(errConfig, -1, "Bad 'psLevel' config file command ({0:t}:{1:d})",
1370
 
          fileName, line);
1371
 
    return;
1372
 
  }
1373
 
  tok = (GString *)tokens->get(1);
1374
 
  if (!tok->cmp("level1")) {
1375
 
    psLevel = psLevel1;
1376
 
  } else if (!tok->cmp("level1sep")) {
1377
 
    psLevel = psLevel1Sep;
1378
 
  } else if (!tok->cmp("level2")) {
1379
 
    psLevel = psLevel2;
1380
 
  } else if (!tok->cmp("level2sep")) {
1381
 
    psLevel = psLevel2Sep;
1382
 
  } else if (!tok->cmp("level3")) {
1383
 
    psLevel = psLevel3;
1384
 
  } else if (!tok->cmp("level3Sep")) {
1385
 
    psLevel = psLevel3Sep;
1386
 
  } else {
1387
 
    error(errConfig, -1, "Bad 'psLevel' config file command ({0:t}:{1:d})",
1388
 
          fileName, line);
1389
 
  }
1390
 
}
1391
 
 
1392
 
void GlobalParams::parsePSResidentFont(GList *tokens, GString *fileName,
1393
 
                                       int line) {
1394
 
  if (tokens->getLength() != 3) {
1395
 
    error(errConfig, -1, "Bad 'psResidentFont' config file command ({0:t}:{1:d})",
1396
 
          fileName, line);
1397
 
    return;
1398
 
  }
1399
 
  psResidentFonts->add(((GString *)tokens->get(1))->copy(),
1400
 
                       ((GString *)tokens->get(2))->copy());
1401
 
}
1402
 
 
1403
 
void GlobalParams::parsePSResidentFont16(GList *tokens, GString *fileName,
1404
 
                                         int line) {
1405
 
  PSFontParam16 *param;
1406
 
  int wMode;
1407
 
  GString *tok;
1408
 
 
1409
 
  if (tokens->getLength() != 5) {
1410
 
    error(errConfig, -1, "Bad 'psResidentFont16' config file command ({0:t}:{1:d})",
1411
 
          fileName, line);
1412
 
    return;
1413
 
  }
1414
 
  tok = (GString *)tokens->get(2);
1415
 
  if (!tok->cmp("H")) {
1416
 
    wMode = 0;
1417
 
  } else if (!tok->cmp("V")) {
1418
 
    wMode = 1;
1419
 
  } else {
1420
 
    error(errConfig, -1, "Bad wMode in psResidentFont16 config file command ({1:t}:{2:d})",
1421
 
          fileName, line);
1422
 
    return;
1423
 
  }
1424
 
  param = new PSFontParam16(((GString *)tokens->get(1))->copy(),
1425
 
                            wMode,
1426
 
                            ((GString *)tokens->get(3))->copy(),
1427
 
                            ((GString *)tokens->get(4))->copy());
1428
 
  psResidentFonts16->append(param);
1429
 
}
1430
 
 
1431
 
void GlobalParams::parsePSResidentFontCC(GList *tokens, GString *fileName,
1432
 
                                         int line) {
1433
 
  PSFontParam16 *param;
1434
 
  int wMode;
1435
 
  GString *tok;
1436
 
 
1437
 
  if (tokens->getLength() != 5) {
1438
 
    error(errConfig, -1, "Bad 'psResidentFontCC' config file command ({0:t}:{1:d})",
1439
 
          fileName, line);
1440
 
    return;
1441
 
  }
1442
 
  tok = (GString *)tokens->get(2);
1443
 
  if (!tok->cmp("H")) {
1444
 
    wMode = 0;
1445
 
  } else if (!tok->cmp("V")) {
1446
 
    wMode = 1;
1447
 
  } else {
1448
 
    error(errConfig, -1, "Bad wMode in psResidentFontCC config file command ({1:t}:{2:d})",
1449
 
          fileName, line);
1450
 
    return;
1451
 
  }
1452
 
  param = new PSFontParam16(((GString *)tokens->get(1))->copy(),
1453
 
                            wMode,
1454
 
                            ((GString *)tokens->get(3))->copy(),
1455
 
                            ((GString *)tokens->get(4))->copy());
1456
 
  psResidentFontsCC->append(param);
1457
 
}
1458
 
 
1459
 
void GlobalParams::parseTextEncoding(GList *tokens, GString *fileName,
1460
 
                                     int line) {
1461
 
  if (tokens->getLength() != 2) {
1462
 
    error(errConfig, -1,
1463
 
          "Bad 'textEncoding' config file command ({0:s}:{1:d})",
1464
 
          fileName, line);
1465
 
    return;
1466
 
  }
1467
 
  delete textEncoding;
1468
 
  textEncoding = ((GString *)tokens->get(1))->copy();
1469
 
}
1470
 
 
1471
 
void GlobalParams::parseTextEOL(GList *tokens, GString *fileName, int line) {
1472
 
  GString *tok;
1473
 
 
1474
 
  if (tokens->getLength() != 2) {
1475
 
    error(errConfig, -1, "Bad 'textEOL' config file command ({0:t}:{1:d})",
1476
 
          fileName, line);
1477
 
    return;
1478
 
  }
1479
 
  tok = (GString *)tokens->get(1);
1480
 
  if (!tok->cmp("unix")) {
1481
 
    textEOL = eolUnix;
1482
 
  } else if (!tok->cmp("dos")) {
1483
 
    textEOL = eolDOS;
1484
 
  } else if (!tok->cmp("mac")) {
1485
 
    textEOL = eolMac;
1486
 
  } else {
1487
 
    error(errConfig, -1, "Bad 'textEOL' config file command ({0:t}:{1:d})",
1488
 
          fileName, line);
1489
 
  }
1490
 
}
1491
 
 
1492
 
void GlobalParams::parseInitialZoom(GList *tokens,
1493
 
                                    GString *fileName, int line) {
1494
 
  if (tokens->getLength() != 2) {
1495
 
    error(errConfig, -1, "Bad 'initialZoom' config file command ({0:t}:{1:d})",
1496
 
          fileName, line);
1497
 
    return;
1498
 
  }
1499
 
  delete initialZoom;
1500
 
  initialZoom = ((GString *)tokens->get(1))->copy();
1501
 
}
1502
 
 
1503
 
void GlobalParams::parseScreenType(GList *tokens, GString *fileName,
1504
 
                                   int line) {
1505
 
  GString *tok;
1506
 
 
1507
 
  if (tokens->getLength() != 2) {
1508
 
    error(errConfig, -1, "Bad 'screenType' config file command ({0:t}:{1:d})",
1509
 
          fileName, line);
1510
 
    return;
1511
 
  }
1512
 
  tok = (GString *)tokens->get(1);
1513
 
  if (!tok->cmp("dispersed")) {
1514
 
    screenType = screenDispersed;
1515
 
  } else if (!tok->cmp("clustered")) {
1516
 
    screenType = screenClustered;
1517
 
  } else if (!tok->cmp("stochasticClustered")) {
1518
 
    screenType = screenStochasticClustered;
1519
 
  } else {
1520
 
    error(errConfig, -1, "Bad 'screenType' config file command ({0:t}:{1:d})",
1521
 
          fileName, line);
1522
 
  }
1523
 
}
1524
 
 
1525
 
void GlobalParams::parseBind(GList *tokens, GString *fileName, int line) {
1526
 
  KeyBinding *binding;
1527
 
  GList *cmds;
1528
 
  int code, mods, context, i;
1529
 
 
1530
 
  if (tokens->getLength() < 4) {
1531
 
    error(errConfig, -1, "Bad 'bind' config file command ({0:t}:{1:d})",
1532
 
          fileName, line);
1533
 
    return;
1534
 
  }
1535
 
  if (!parseKey((GString *)tokens->get(1), (GString *)tokens->get(2),
1536
 
                &code, &mods, &context,
1537
 
                "bind", tokens, fileName, line)) {
1538
 
    return;
1539
 
  }
1540
 
  for (i = 0; i < keyBindings->getLength(); ++i) {
1541
 
    binding = (KeyBinding *)keyBindings->get(i);
1542
 
    if (binding->code == code &&
1543
 
        binding->mods == mods &&
1544
 
        binding->context == context) {
1545
 
      delete (KeyBinding *)keyBindings->del(i);
1546
 
      break;
1547
 
    }
1548
 
  }
1549
 
  cmds = new GList();
1550
 
  for (i = 3; i < tokens->getLength(); ++i) {
1551
 
    cmds->append(((GString *)tokens->get(i))->copy());
1552
 
  }
1553
 
  keyBindings->append(new KeyBinding(code, mods, context, cmds));
1554
 
}
1555
 
 
1556
 
void GlobalParams::parseUnbind(GList *tokens, GString *fileName, int line) {
1557
 
  KeyBinding *binding;
1558
 
  int code, mods, context, i;
1559
 
 
1560
 
  if (tokens->getLength() != 3) {
1561
 
    error(errConfig, -1, "Bad 'unbind' config file command ({0:t}:{1:d})",
1562
 
          fileName, line);
1563
 
    return;
1564
 
  }
1565
 
  if (!parseKey((GString *)tokens->get(1), (GString *)tokens->get(2),
1566
 
                &code, &mods, &context,
1567
 
                "unbind", tokens, fileName, line)) {
1568
 
    return;
1569
 
  }
1570
 
  for (i = 0; i < keyBindings->getLength(); ++i) {
1571
 
    binding = (KeyBinding *)keyBindings->get(i);
1572
 
    if (binding->code == code &&
1573
 
        binding->mods == mods &&
1574
 
        binding->context == context) {
1575
 
      delete (KeyBinding *)keyBindings->del(i);
1576
 
      break;
1577
 
    }
1578
 
  }
1579
 
}
1580
 
 
1581
 
GBool GlobalParams::parseKey(GString *modKeyStr, GString *contextStr,
1582
 
                             int *code, int *mods, int *context,
1583
 
                             const char *cmdName,
1584
 
                             GList *tokens, GString *fileName, int line) {
1585
 
  char *p0;
1586
 
  int btn;
1587
 
 
1588
 
  *mods = xpdfKeyModNone;
1589
 
  p0 = modKeyStr->getCString();
1590
 
  while (1) {
1591
 
    if (!strncmp(p0, "shift-", 6)) {
1592
 
      *mods |= xpdfKeyModShift;
1593
 
      p0 += 6;
1594
 
    } else if (!strncmp(p0, "ctrl-", 5)) {
1595
 
      *mods |= xpdfKeyModCtrl;
1596
 
      p0 += 5;
1597
 
    } else if (!strncmp(p0, "alt-", 4)) {
1598
 
      *mods |= xpdfKeyModAlt;
1599
 
      p0 += 4;
1600
 
    } else {
1601
 
      break;
1602
 
    }
1603
 
  }
1604
 
 
1605
 
  if (!strcmp(p0, "space")) {
1606
 
    *code = ' ';
1607
 
  } else if (!strcmp(p0, "tab")) {
1608
 
    *code = xpdfKeyCodeTab;
1609
 
  } else if (!strcmp(p0, "return")) {
1610
 
    *code = xpdfKeyCodeReturn;
1611
 
  } else if (!strcmp(p0, "enter")) {
1612
 
    *code = xpdfKeyCodeEnter;
1613
 
  } else if (!strcmp(p0, "backspace")) {
1614
 
    *code = xpdfKeyCodeBackspace;
1615
 
  } else if (!strcmp(p0, "insert")) {
1616
 
    *code = xpdfKeyCodeInsert;
1617
 
  } else if (!strcmp(p0, "delete")) {
1618
 
    *code = xpdfKeyCodeDelete;
1619
 
  } else if (!strcmp(p0, "home")) {
1620
 
    *code = xpdfKeyCodeHome;
1621
 
  } else if (!strcmp(p0, "end")) {
1622
 
    *code = xpdfKeyCodeEnd;
1623
 
  } else if (!strcmp(p0, "pgup")) {
1624
 
    *code = xpdfKeyCodePgUp;
1625
 
  } else if (!strcmp(p0, "pgdn")) {
1626
 
    *code = xpdfKeyCodePgDn;
1627
 
  } else if (!strcmp(p0, "left")) {
1628
 
    *code = xpdfKeyCodeLeft;
1629
 
  } else if (!strcmp(p0, "right")) {
1630
 
    *code = xpdfKeyCodeRight;
1631
 
  } else if (!strcmp(p0, "up")) {
1632
 
    *code = xpdfKeyCodeUp;
1633
 
  } else if (!strcmp(p0, "down")) {
1634
 
    *code = xpdfKeyCodeDown;
1635
 
  } else if (p0[0] == 'f' && p0[1] >= '1' && p0[1] <= '9' && !p0[2]) {
1636
 
    *code = xpdfKeyCodeF1 + (p0[1] - '1');
1637
 
  } else if (p0[0] == 'f' &&
1638
 
             ((p0[1] >= '1' && p0[1] <= '2' && p0[2] >= '0' && p0[2] <= '9') ||
1639
 
              (p0[1] == '3' && p0[2] >= '0' && p0[2] <= '5')) &&
1640
 
             !p0[3]) {
1641
 
    *code = xpdfKeyCodeF1 + 10 * (p0[1] - '0') + (p0[2] - '0') - 1;
1642
 
  } else if (!strncmp(p0, "mousePress", 10) &&
1643
 
             p0[10] >= '0' && p0[10] <= '9' &&
1644
 
             (!p0[11] || (p0[11] >= '0' && p0[11] <= '9' && !p0[12])) &&
1645
 
             (btn = atoi(p0 + 10)) >= 1 && btn <= 32) {
1646
 
    *code = xpdfKeyCodeMousePress1 + btn - 1;
1647
 
  } else if (!strncmp(p0, "mouseRelease", 12) &&
1648
 
             p0[12] >= '0' && p0[12] <= '9' &&
1649
 
             (!p0[13] || (p0[13] >= '0' && p0[13] <= '9' && !p0[14])) &&
1650
 
             (btn = atoi(p0 + 12)) >= 1 && btn <= 32) {
1651
 
    *code = xpdfKeyCodeMouseRelease1 + btn - 1;
1652
 
  } else if (*p0 >= 0x20 && *p0 <= 0x7e && !p0[1]) {
1653
 
    *code = (int)*p0;
1654
 
  } else {
1655
 
    error(errConfig, -1,
1656
 
          "Bad key/modifier in '{0:s}' config file command ({1:t}:{2:d})",
1657
 
          cmdName, fileName, line);
1658
 
    return gFalse;
1659
 
  }
1660
 
 
1661
 
  p0 = contextStr->getCString();
1662
 
  if (!strcmp(p0, "any")) {
1663
 
    *context = xpdfKeyContextAny;
1664
 
  } else {
1665
 
    *context = xpdfKeyContextAny;
1666
 
    while (1) {
1667
 
      if (!strncmp(p0, "fullScreen", 10)) {
1668
 
        *context |= xpdfKeyContextFullScreen;
1669
 
        p0 += 10;
1670
 
      } else if (!strncmp(p0, "window", 6)) {
1671
 
        *context |= xpdfKeyContextWindow;
1672
 
        p0 += 6;
1673
 
      } else if (!strncmp(p0, "continuous", 10)) {
1674
 
        *context |= xpdfKeyContextContinuous;
1675
 
        p0 += 10;
1676
 
      } else if (!strncmp(p0, "singlePage", 10)) {
1677
 
        *context |= xpdfKeyContextSinglePage;
1678
 
        p0 += 10;
1679
 
      } else if (!strncmp(p0, "overLink", 8)) {
1680
 
        *context |= xpdfKeyContextOverLink;
1681
 
        p0 += 8;
1682
 
      } else if (!strncmp(p0, "offLink", 7)) {
1683
 
        *context |= xpdfKeyContextOffLink;
1684
 
        p0 += 7;
1685
 
      } else if (!strncmp(p0, "outline", 7)) {
1686
 
        *context |= xpdfKeyContextOutline;
1687
 
        p0 += 7;
1688
 
      } else if (!strncmp(p0, "mainWin", 7)) {
1689
 
        *context |= xpdfKeyContextMainWin;
1690
 
        p0 += 7;
1691
 
      } else if (!strncmp(p0, "scrLockOn", 9)) {
1692
 
        *context |= xpdfKeyContextScrLockOn;
1693
 
        p0 += 9;
1694
 
      } else if (!strncmp(p0, "scrLockOff", 10)) {
1695
 
        *context |= xpdfKeyContextScrLockOff;
1696
 
        p0 += 10;
1697
 
      } else {
1698
 
        error(errConfig, -1,
1699
 
              "Bad context in '{0:s}' config file command ({1:t}:{2:d})",
1700
 
              cmdName, fileName, line);
1701
 
        return gFalse;
1702
 
      }
1703
 
      if (!*p0) {
1704
 
        break;
1705
 
      }
1706
 
      if (*p0 != ',') {
1707
 
        error(errConfig, -1,
1708
 
              "Bad context in '{0:s}' config file command ({1:t}:{2:d})",
1709
 
              cmdName, fileName, line);
1710
 
        return gFalse;
1711
 
      }
1712
 
      ++p0;
1713
 
    }
1714
 
  }
1715
 
 
1716
 
  return gTrue;
1717
 
}
1718
 
 
1719
 
void GlobalParams::parseCommand(const char *cmdName, GString **val,
1720
 
                                GList *tokens, GString *fileName, int line) {
1721
 
  if (tokens->getLength() != 2) {
1722
 
    error(errConfig, -1, "Bad '{0:s}' config file command ({1:t}:{2:d})",
1723
 
          cmdName, fileName, line);
1724
 
    return;
1725
 
  }
1726
 
  if (*val) {
1727
 
    delete *val;
1728
 
  }
1729
 
  *val = ((GString *)tokens->get(1))->copy();
1730
 
}
1731
 
 
1732
 
void GlobalParams::parseYesNo(const char *cmdName, GBool *flag,
1733
 
                              GList *tokens, GString *fileName, int line) {
1734
 
  GString *tok;
1735
 
 
1736
 
  if (tokens->getLength() != 2) {
1737
 
    error(errConfig, -1, "Bad '{0:s}' config file command ({1:t}:{2:d})",
1738
 
          cmdName, fileName, line);
1739
 
    return;
1740
 
  }
1741
 
  tok = (GString *)tokens->get(1);
1742
 
  if (!parseYesNo2(tok->getCString(), flag)) {
1743
 
    error(errConfig, -1, "Bad '{0:s}' config file command ({1:t}:{2:d})",
1744
 
          cmdName, fileName, line);
1745
 
  }
1746
 
}
1747
 
 
1748
 
GBool GlobalParams::parseYesNo2(char *token, GBool *flag) {
1749
 
  if (!strcmp(token, "yes")) {
1750
 
    *flag = gTrue;
1751
 
  } else if (!strcmp(token, "no")) {
1752
 
    *flag = gFalse;
1753
 
  } else {
1754
 
    return gFalse;
1755
 
  }
1756
 
  return gTrue;
1757
 
}
1758
 
 
1759
 
void GlobalParams::parseInteger(const char *cmdName, int *val,
1760
 
                                GList *tokens, GString *fileName, int line) {
1761
 
  GString *tok;
1762
 
  int i;
1763
 
 
1764
 
  if (tokens->getLength() != 2) {
1765
 
    error(errConfig, -1, "Bad '{0:s}' config file command ({1:t}:{2:d})",
1766
 
          cmdName, fileName, line);
1767
 
    return;
1768
 
  }
1769
 
  tok = (GString *)tokens->get(1);
1770
 
  if (tok->getLength() == 0) {
1771
 
    error(errConfig, -1, "Bad '{0:s}' config file command ({1:t}:{2:d})",
1772
 
          cmdName, fileName, line);
1773
 
    return;
1774
 
  }
1775
 
  if (tok->getChar(0) == '-') {
1776
 
    i = 1;
1777
 
  } else {
1778
 
    i = 0;
1779
 
  }
1780
 
  for (; i < tok->getLength(); ++i) {
1781
 
    if (tok->getChar(i) < '0' || tok->getChar(i) > '9') {
1782
 
      error(errConfig, -1, "Bad '{0:s}' config file command ({1:t}:{2:d})",
1783
 
            cmdName, fileName, line);
1784
 
      return;
1785
 
    }
1786
 
  }
1787
 
  *val = atoi(tok->getCString());
1788
 
}
1789
 
 
1790
 
void GlobalParams::parseFloat(const char *cmdName, double *val,
1791
 
                              GList *tokens, GString *fileName, int line) {
1792
 
  GString *tok;
1793
 
  int i;
1794
 
 
1795
 
  if (tokens->getLength() != 2) {
1796
 
    error(errConfig, -1, "Bad '{0:s}' config file command ({1:t}:{2:d})",
1797
 
          cmdName, fileName, line);
1798
 
    return;
1799
 
  }
1800
 
  tok = (GString *)tokens->get(1);
1801
 
  if (tok->getLength() == 0) {
1802
 
    error(errConfig, -1, "Bad '{0:s}' config file command ({1:t}:{2:d})",
1803
 
          cmdName, fileName, line);
1804
 
    return;
1805
 
  }
1806
 
  if (tok->getChar(0) == '-') {
1807
 
    i = 1;
1808
 
  } else {
1809
 
    i = 0;
1810
 
  }
1811
 
  for (; i < tok->getLength(); ++i) {
1812
 
    if (!((tok->getChar(i) >= '0' && tok->getChar(i) <= '9') ||
1813
 
          tok->getChar(i) == '.')) {
1814
 
      error(errConfig, -1, "Bad '{0:s}' config file command ({1:t}:{2:d})",
1815
 
            cmdName, fileName, line);
1816
 
      return;
1817
 
    }
1818
 
  }
1819
 
  *val = atof(tok->getCString());
1820
 
}
1821
 
 
1822
 
GlobalParams::~GlobalParams() {
1823
 
  GHashIter *iter;
1824
 
  GString *key;
1825
 
  GList *list;
1826
 
 
1827
 
  freeBuiltinFontTables();
1828
 
 
1829
 
  delete macRomanReverseMap;
1830
 
 
1831
 
  delete baseDir;
1832
 
  delete nameToUnicode;
1833
 
  deleteGHash(cidToUnicodes, GString);
1834
 
  deleteGHash(unicodeToUnicodes, GString);
1835
 
  deleteGHash(residentUnicodeMaps, UnicodeMap);
1836
 
  deleteGHash(unicodeMaps, GString);
1837
 
  deleteGList(toUnicodeDirs, GString);
1838
 
  deleteGHash(fontFiles, GString);
1839
 
  deleteGList(fontDirs, GString);
1840
 
  deleteGHash(ccFontFiles, GString);
1841
 
  delete sysFonts;
1842
 
  if (psFile) {
1843
 
    delete psFile;
1844
 
  }
1845
 
  deleteGHash(psResidentFonts, GString);
1846
 
  deleteGList(psResidentFonts16, PSFontParam16);
1847
 
  deleteGList(psResidentFontsCC, PSFontParam16);
1848
 
  delete textEncoding;
1849
 
  delete initialZoom;
1850
 
  if (launchCommand) {
1851
 
    delete launchCommand;
1852
 
  }
1853
 
  if (urlCommand) {
1854
 
    delete urlCommand;
1855
 
  }
1856
 
  if (movieCommand) {
1857
 
    delete movieCommand;
1858
 
  }
1859
 
  deleteGList(keyBindings, KeyBinding);
1860
 
 
1861
 
  cMapDirs->startIter(&iter);
1862
 
  while (cMapDirs->getNext(&iter, &key, (void **)&list)) {
1863
 
    deleteGList(list, GString);
1864
 
  }
1865
 
  delete cMapDirs;
1866
 
 
1867
 
  delete cidToUnicodeCache;
1868
 
  delete unicodeToUnicodeCache;
1869
 
  delete unicodeMapCache;
1870
 
  delete cMapCache;
1871
 
 
1872
 
#ifdef ENABLE_PLUGINS
1873
 
  delete securityHandlers;
1874
 
  deleteGList(plugins, Plugin);
1875
 
#endif
1876
 
 
1877
 
#if MULTITHREADED
1878
 
  gDestroyMutex(&mutex);
1879
 
  gDestroyMutex(&unicodeMapCacheMutex);
1880
 
  gDestroyMutex(&cMapCacheMutex);
1881
 
#endif
1882
 
}
1883
 
 
1884
 
//------------------------------------------------------------------------
1885
 
 
1886
 
void GlobalParams::setBaseDir(char *dir) {
1887
 
  delete baseDir;
1888
 
  baseDir = new GString(dir);
1889
 
}
1890
 
 
1891
 
void GlobalParams::setupBaseFonts(char *dir) {
1892
 
  GString *fontName;
1893
 
  GString *fileName;
1894
 
#ifdef WIN32
1895
 
  HMODULE shell32Lib;
1896
 
  BOOL (__stdcall *SHGetSpecialFolderPathFunc)(HWND hwndOwner,
1897
 
                                               LPTSTR lpszPath,
1898
 
                                               int nFolder,
1899
 
                                               BOOL fCreate);
1900
 
  char winFontDir[MAX_PATH];
1901
 
#endif
1902
 
  FILE *f;
1903
 
  int i, j;
1904
 
 
1905
 
#ifdef WIN32
1906
 
  // SHGetSpecialFolderPath isn't available in older versions of
1907
 
  // shell32.dll (Win95 and WinNT4), so do a dynamic load
1908
 
  winFontDir[0] = '\0';
1909
 
  if ((shell32Lib = LoadLibrary("shell32.dll"))) {
1910
 
    if ((SHGetSpecialFolderPathFunc = 
1911
 
         (BOOL (__stdcall *)(HWND hwndOwner, LPTSTR lpszPath,
1912
 
                             int nFolder, BOOL fCreate))
1913
 
         GetProcAddress(shell32Lib, "SHGetSpecialFolderPathA"))) {
1914
 
      if (!(*SHGetSpecialFolderPathFunc)(NULL, winFontDir,
1915
 
                                         CSIDL_FONTS, FALSE)) {
1916
 
        winFontDir[0] = '\0';
1917
 
      }
1918
 
    }
1919
 
  }
1920
 
#endif
1921
 
  for (i = 0; displayFontTab[i].name; ++i) {
1922
 
    if (fontFiles->lookup(displayFontTab[i].name)) {
1923
 
      continue;
1924
 
    }
1925
 
    fontName = new GString(displayFontTab[i].name);
1926
 
    fileName = NULL;
1927
 
    if (dir) {
1928
 
      fileName = appendToPath(new GString(dir), displayFontTab[i].t1FileName);
1929
 
      if ((f = fopen(fileName->getCString(), "rb"))) {
1930
 
        fclose(f);
1931
 
      } else {
1932
 
        delete fileName;
1933
 
        fileName = NULL;
1934
 
      }
1935
 
    }
1936
 
#ifdef WIN32
1937
 
    if (!fileName && winFontDir[0] && displayFontTab[i].ttFileName) {
1938
 
      fileName = appendToPath(new GString(winFontDir),
1939
 
                              displayFontTab[i].ttFileName);
1940
 
      if ((f = fopen(fileName->getCString(), "rb"))) {
1941
 
        fclose(f);
1942
 
      } else {
1943
 
        delete fileName;
1944
 
        fileName = NULL;
1945
 
      }
1946
 
    }
1947
 
    // SHGetSpecialFolderPath(CSIDL_FONTS) doesn't work on Win 2k Server
1948
 
    // or Win2003 Server, or with older versions of shell32.dll, so check
1949
 
    // the "standard" directories
1950
 
    if (displayFontTab[i].ttFileName) {
1951
 
      for (j = 0; !fileName && displayFontDirs[j]; ++j) {
1952
 
        fileName = appendToPath(new GString(displayFontDirs[j]),
1953
 
                                displayFontTab[i].ttFileName);
1954
 
        if ((f = fopen(fileName->getCString(), "rb"))) {
1955
 
          fclose(f);
1956
 
        } else {
1957
 
          delete fileName;
1958
 
          fileName = NULL;
1959
 
        }
1960
 
      }
1961
 
    }
1962
 
#else // WIN32
1963
 
    for (j = 0; !fileName && displayFontDirs[j]; ++j) {
1964
 
      fileName = appendToPath(new GString(displayFontDirs[j]),
1965
 
                              displayFontTab[i].t1FileName);
1966
 
      if ((f = fopen(fileName->getCString(), "rb"))) {
1967
 
        fclose(f);
1968
 
      } else {
1969
 
        delete fileName;
1970
 
        fileName = NULL;
1971
 
      }
1972
 
    }
1973
 
#endif // WIN32
1974
 
    if (!fileName) {
1975
 
      error(errConfig, -1, "No display font for '{0:s}'",
1976
 
            displayFontTab[i].name);
1977
 
      delete fontName;
1978
 
      continue;
1979
 
    }
1980
 
    addFontFile(fontName, fileName);
1981
 
  }
1982
 
 
1983
 
#ifdef WIN32
1984
 
  if (winFontDir[0]) {
1985
 
    sysFonts->scanWindowsFonts(winFontDir);
1986
 
  }
1987
 
#endif
1988
 
}
1989
 
 
1990
 
//------------------------------------------------------------------------
1991
 
// accessors
1992
 
//------------------------------------------------------------------------
1993
 
 
1994
 
CharCode GlobalParams::getMacRomanCharCode(char *charName) {
1995
 
  // no need to lock - macRomanReverseMap is constant
1996
 
  return macRomanReverseMap->lookup(charName);
1997
 
}
1998
 
 
1999
 
GString *GlobalParams::getBaseDir() {
2000
 
  GString *s;
2001
 
 
2002
 
  lockGlobalParams;
2003
 
  s = baseDir->copy();
2004
 
  unlockGlobalParams;
2005
 
  return s;
2006
 
}
2007
 
 
2008
 
Unicode GlobalParams::mapNameToUnicode(const char *charName) {
2009
 
  // no need to lock - nameToUnicode is constant
2010
 
  return nameToUnicode->lookup(charName);
2011
 
}
2012
 
 
2013
 
UnicodeMap *GlobalParams::getResidentUnicodeMap(GString *encodingName) {
2014
 
  UnicodeMap *map;
2015
 
 
2016
 
  lockGlobalParams;
2017
 
  map = (UnicodeMap *)residentUnicodeMaps->lookup(encodingName);
2018
 
  unlockGlobalParams;
2019
 
  if (map) {
2020
 
    map->incRefCnt();
2021
 
  }
2022
 
  return map;
2023
 
}
2024
 
 
2025
 
FILE *GlobalParams::getUnicodeMapFile(GString *encodingName) {
2026
 
  GString *fileName;
2027
 
  FILE *f;
2028
 
 
2029
 
  lockGlobalParams;
2030
 
  if ((fileName = (GString *)unicodeMaps->lookup(encodingName))) {
2031
 
    f = openFile(fileName->getCString(), "r");
2032
 
  } else {
2033
 
    f = NULL;
2034
 
  }
2035
 
  unlockGlobalParams;
2036
 
  return f;
2037
 
}
2038
 
 
2039
 
FILE *GlobalParams::findCMapFile(GString *collection, GString *cMapName) {
2040
 
  GList *list;
2041
 
  GString *dir;
2042
 
  GString *fileName;
2043
 
  FILE *f;
2044
 
  int i;
2045
 
 
2046
 
  lockGlobalParams;
2047
 
  if (!(list = (GList *)cMapDirs->lookup(collection))) {
2048
 
    unlockGlobalParams;
2049
 
    return NULL;
2050
 
  }
2051
 
  for (i = 0; i < list->getLength(); ++i) {
2052
 
    dir = (GString *)list->get(i);
2053
 
    fileName = appendToPath(dir->copy(), cMapName->getCString());
2054
 
    f = openFile(fileName->getCString(), "r");
2055
 
    delete fileName;
2056
 
    if (f) {
2057
 
      unlockGlobalParams;
2058
 
      return f;
2059
 
    }
2060
 
  }
2061
 
  unlockGlobalParams;
2062
 
  return NULL;
2063
 
}
2064
 
 
2065
 
FILE *GlobalParams::findToUnicodeFile(GString *name) {
2066
 
  GString *dir, *fileName;
2067
 
  FILE *f;
2068
 
  int i;
2069
 
 
2070
 
  lockGlobalParams;
2071
 
  for (i = 0; i < toUnicodeDirs->getLength(); ++i) {
2072
 
    dir = (GString *)toUnicodeDirs->get(i);
2073
 
    fileName = appendToPath(dir->copy(), name->getCString());
2074
 
    f = openFile(fileName->getCString(), "r");
2075
 
    delete fileName;
2076
 
    if (f) {
2077
 
      unlockGlobalParams;
2078
 
      return f;
2079
 
    }
2080
 
  }
2081
 
  unlockGlobalParams;
2082
 
  return NULL;
2083
 
}
2084
 
 
2085
 
GString *GlobalParams::findFontFile(GString *fontName, char** throwaway) {
2086
 
  static const char *exts[] = { ".pfa", ".pfb", ".ttf", ".ttc" };
2087
 
  GString *path, *dir;
2088
 
#ifdef WIN32
2089
 
  GString *fontNameU;
2090
 
#endif
2091
 
  const char *ext;
2092
 
  FILE *f;
2093
 
  int i, j;
2094
 
 
2095
 
  return NULL;
2096
 
  lockGlobalParams;
2097
 
  if ((path = (GString *)fontFiles->lookup(fontName))) {
2098
 
    path = path->copy();
2099
 
    unlockGlobalParams;
2100
 
    return path;
2101
 
  }
2102
 
  for (i = 0; i < fontDirs->getLength(); ++i) {
2103
 
    dir = (GString *)fontDirs->get(i);
2104
 
    for (j = 0; j < (int)(sizeof(exts) / sizeof(exts[0])); ++j) {
2105
 
      ext = exts[j];
2106
 
#ifdef WIN32
2107
 
      fontNameU = fileNameToUTF8(fontName->getCString());
2108
 
      path = appendToPath(dir->copy(), fontNameU->getCString());
2109
 
      delete fontNameU;
2110
 
#else
2111
 
      path = appendToPath(dir->copy(), fontName->getCString());
2112
 
#endif
2113
 
      path->append(ext);
2114
 
      if ((f = openFile(path->getCString(), "rb"))) {
2115
 
        fclose(f);
2116
 
        unlockGlobalParams;
2117
 
        return path;
2118
 
      }
2119
 
      delete path;
2120
 
    }
2121
 
  }
2122
 
  unlockGlobalParams;
2123
 
  return NULL;
2124
 
}
2125
 
 
2126
 
GString *GlobalParams::findSystemFontFile(GString *fontName,
2127
 
                                          SysFontType *type,
2128
 
                                          int *fontNum) {
2129
 
  SysFontInfo *fi;
2130
 
  GString *path;
2131
 
 
2132
 
  path = NULL;
2133
 
  lockGlobalParams;
2134
 
  if ((fi = sysFonts->find(fontName))) {
2135
 
    path = fi->path->copy();
2136
 
    *type = fi->type;
2137
 
    *fontNum = fi->fontNum;
2138
 
  }
2139
 
  unlockGlobalParams;
2140
 
  return path;
2141
 
}
2142
 
 
2143
 
GString *GlobalParams::findCCFontFile(GString *collection) {
2144
 
  GString *path;
2145
 
 
2146
 
  lockGlobalParams;
2147
 
  if ((path = (GString *)ccFontFiles->lookup(collection))) {
2148
 
    path = path->copy();
2149
 
  }
2150
 
  unlockGlobalParams;
2151
 
  return path;
2152
 
}
2153
 
 
2154
 
GString *GlobalParams::getPSFile() {
2155
 
  GString *s;
2156
 
 
2157
 
  lockGlobalParams;
2158
 
  s = psFile ? psFile->copy() : (GString *)NULL;
2159
 
  unlockGlobalParams;
2160
 
  return s;
2161
 
}
2162
 
 
2163
 
int GlobalParams::getPSPaperWidth() {
2164
 
  int w;
2165
 
 
2166
 
  lockGlobalParams;
2167
 
  w = psPaperWidth;
2168
 
  unlockGlobalParams;
2169
 
  return w;
2170
 
}
2171
 
 
2172
 
int GlobalParams::getPSPaperHeight() {
2173
 
  int h;
2174
 
 
2175
 
  lockGlobalParams;
2176
 
  h = psPaperHeight;
2177
 
  unlockGlobalParams;
2178
 
  return h;
2179
 
}
2180
 
 
2181
 
void GlobalParams::getPSImageableArea(int *llx, int *lly, int *urx, int *ury) {
2182
 
  lockGlobalParams;
2183
 
  *llx = psImageableLLX;
2184
 
  *lly = psImageableLLY;
2185
 
  *urx = psImageableURX;
2186
 
  *ury = psImageableURY;
2187
 
  unlockGlobalParams;
2188
 
}
2189
 
 
2190
 
GBool GlobalParams::getPSCrop() {
2191
 
  GBool f;
2192
 
 
2193
 
  lockGlobalParams;
2194
 
  f = psCrop;
2195
 
  unlockGlobalParams;
2196
 
  return f;
2197
 
}
2198
 
 
2199
 
GBool GlobalParams::getPSExpandSmaller() {
2200
 
  GBool f;
2201
 
 
2202
 
  lockGlobalParams;
2203
 
  f = psExpandSmaller;
2204
 
  unlockGlobalParams;
2205
 
  return f;
2206
 
}
2207
 
 
2208
 
GBool GlobalParams::getPSShrinkLarger() {
2209
 
  GBool f;
2210
 
 
2211
 
  lockGlobalParams;
2212
 
  f = psShrinkLarger;
2213
 
  unlockGlobalParams;
2214
 
  return f;
2215
 
}
2216
 
 
2217
 
GBool GlobalParams::getPSCenter() {
2218
 
  GBool f;
2219
 
 
2220
 
  lockGlobalParams;
2221
 
  f = psCenter;
2222
 
  unlockGlobalParams;
2223
 
  return f;
2224
 
}
2225
 
 
2226
 
GBool GlobalParams::getPSDuplex() {
2227
 
  GBool d;
2228
 
 
2229
 
  lockGlobalParams;
2230
 
  d = psDuplex;
2231
 
  unlockGlobalParams;
2232
 
  return d;
2233
 
}
2234
 
 
2235
 
PSLevel GlobalParams::getPSLevel() {
2236
 
  PSLevel level;
2237
 
 
2238
 
  lockGlobalParams;
2239
 
  level = psLevel;
2240
 
  unlockGlobalParams;
2241
 
  return level;
2242
 
}
2243
 
 
2244
 
GString *GlobalParams::getPSResidentFont(GString *fontName) {
2245
 
  GString *psName;
2246
 
 
2247
 
  lockGlobalParams;
2248
 
  psName = (GString *)psResidentFonts->lookup(fontName);
2249
 
  unlockGlobalParams;
2250
 
  return psName;
2251
 
}
2252
 
 
2253
 
GList *GlobalParams::getPSResidentFonts() {
2254
 
  GList *names;
2255
 
  GHashIter *iter;
2256
 
  GString *name;
2257
 
  GString *psName;
2258
 
 
2259
 
  names = new GList();
2260
 
  lockGlobalParams;
2261
 
  psResidentFonts->startIter(&iter);
2262
 
  while (psResidentFonts->getNext(&iter, &name, (void **)&psName)) {
2263
 
    names->append(psName->copy());
2264
 
  }
2265
 
  unlockGlobalParams;
2266
 
  return names;
2267
 
}
2268
 
 
2269
 
PSFontParam16 *GlobalParams::getPSResidentFont16(GString *fontName,
2270
 
                                                 int wMode) {
2271
 
  PSFontParam16 *p;
2272
 
  int i;
2273
 
 
2274
 
  lockGlobalParams;
2275
 
  p = NULL;
2276
 
  for (i = 0; i < psResidentFonts16->getLength(); ++i) {
2277
 
    p = (PSFontParam16 *)psResidentFonts16->get(i);
2278
 
    if (!(p->name->cmp(fontName)) && p->wMode == wMode) {
2279
 
      break;
2280
 
    }
2281
 
    p = NULL;
2282
 
  }
2283
 
  unlockGlobalParams;
2284
 
  return p;
2285
 
}
2286
 
 
2287
 
PSFontParam16 *GlobalParams::getPSResidentFontCC(GString *collection,
2288
 
                                                 int wMode) {
2289
 
  PSFontParam16 *p;
2290
 
  int i;
2291
 
 
2292
 
  lockGlobalParams;
2293
 
  p = NULL;
2294
 
  for (i = 0; i < psResidentFontsCC->getLength(); ++i) {
2295
 
    p = (PSFontParam16 *)psResidentFontsCC->get(i);
2296
 
    if (!(p->name->cmp(collection)) && p->wMode == wMode) {
2297
 
      break;
2298
 
    }
2299
 
    p = NULL;
2300
 
  }
2301
 
  unlockGlobalParams;
2302
 
  return p;
2303
 
}
2304
 
 
2305
 
GBool GlobalParams::getPSEmbedType1() {
2306
 
  GBool e;
2307
 
 
2308
 
  lockGlobalParams;
2309
 
  e = psEmbedType1;
2310
 
  unlockGlobalParams;
2311
 
  return e;
2312
 
}
2313
 
 
2314
 
GBool GlobalParams::getPSEmbedTrueType() {
2315
 
  GBool e;
2316
 
 
2317
 
  lockGlobalParams;
2318
 
  e = psEmbedTrueType;
2319
 
  unlockGlobalParams;
2320
 
  return e;
2321
 
}
2322
 
 
2323
 
GBool GlobalParams::getPSEmbedCIDPostScript() {
2324
 
  GBool e;
2325
 
 
2326
 
  lockGlobalParams;
2327
 
  e = psEmbedCIDPostScript;
2328
 
  unlockGlobalParams;
2329
 
  return e;
2330
 
}
2331
 
 
2332
 
GBool GlobalParams::getPSEmbedCIDTrueType() {
2333
 
  GBool e;
2334
 
 
2335
 
  lockGlobalParams;
2336
 
  e = psEmbedCIDTrueType;
2337
 
  unlockGlobalParams;
2338
 
  return e;
2339
 
}
2340
 
 
2341
 
GBool GlobalParams::getPSFontPassthrough() {
2342
 
  GBool e;
2343
 
 
2344
 
  lockGlobalParams;
2345
 
  e = psFontPassthrough;
2346
 
  unlockGlobalParams;
2347
 
  return e;
2348
 
}
2349
 
 
2350
 
GBool GlobalParams::getPSPreload() {
2351
 
  GBool preload;
2352
 
 
2353
 
  lockGlobalParams;
2354
 
  preload = psPreload;
2355
 
  unlockGlobalParams;
2356
 
  return preload;
2357
 
}
2358
 
 
2359
 
GBool GlobalParams::getPSOPI() {
2360
 
  GBool opi;
2361
 
 
2362
 
  lockGlobalParams;
2363
 
  opi = psOPI;
2364
 
  unlockGlobalParams;
2365
 
  return opi;
2366
 
}
2367
 
 
2368
 
GBool GlobalParams::getPSASCIIHex() {
2369
 
  GBool ah;
2370
 
 
2371
 
  lockGlobalParams;
2372
 
  ah = psASCIIHex;
2373
 
  unlockGlobalParams;
2374
 
  return ah;
2375
 
}
2376
 
 
2377
 
GBool GlobalParams::getPSUncompressPreloadedImages() {
2378
 
  GBool ah;
2379
 
 
2380
 
  lockGlobalParams;
2381
 
  ah = psUncompressPreloadedImages;
2382
 
  unlockGlobalParams;
2383
 
  return ah;
2384
 
}
2385
 
 
2386
 
double GlobalParams::getPSRasterResolution() {
2387
 
  double res;
2388
 
 
2389
 
  lockGlobalParams;
2390
 
  res = psRasterResolution;
2391
 
  unlockGlobalParams;
2392
 
  return res;
2393
 
}
2394
 
 
2395
 
GBool GlobalParams::getPSRasterMono() {
2396
 
  GBool mono;
2397
 
 
2398
 
  lockGlobalParams;
2399
 
  mono = psRasterMono;
2400
 
  unlockGlobalParams;
2401
 
  return mono;
2402
 
}
2403
 
 
2404
 
GBool GlobalParams::getPSAlwaysRasterize() {
2405
 
  GBool rast;
2406
 
 
2407
 
  lockGlobalParams;
2408
 
  rast = psAlwaysRasterize;
2409
 
  unlockGlobalParams;
2410
 
  return rast;
2411
 
}
2412
 
 
2413
 
GString *GlobalParams::getTextEncodingName() {
2414
 
  GString *s;
2415
 
 
2416
 
  lockGlobalParams;
2417
 
  s = textEncoding->copy();
2418
 
  unlockGlobalParams;
2419
 
  return s;
2420
 
}
2421
 
 
2422
 
EndOfLineKind GlobalParams::getTextEOL() {
2423
 
  EndOfLineKind eol;
2424
 
 
2425
 
  lockGlobalParams;
2426
 
  eol = textEOL;
2427
 
  unlockGlobalParams;
2428
 
  return eol;
2429
 
}
2430
 
 
2431
 
GBool GlobalParams::getTextPageBreaks() {
2432
 
  GBool pageBreaks;
2433
 
 
2434
 
  lockGlobalParams;
2435
 
  pageBreaks = textPageBreaks;
2436
 
  unlockGlobalParams;
2437
 
  return pageBreaks;
2438
 
}
2439
 
 
2440
 
GBool GlobalParams::getTextKeepTinyChars() {
2441
 
  GBool tiny;
2442
 
 
2443
 
  lockGlobalParams;
2444
 
  tiny = textKeepTinyChars;
2445
 
  unlockGlobalParams;
2446
 
  return tiny;
2447
 
}
2448
 
 
2449
 
GString *GlobalParams::getInitialZoom() {
2450
 
  GString *s;
2451
 
 
2452
 
  lockGlobalParams;
2453
 
  s = initialZoom->copy();
2454
 
  unlockGlobalParams;
2455
 
  return s;
2456
 
}
2457
 
 
2458
 
GBool GlobalParams::getContinuousView() {
2459
 
  GBool f;
2460
 
 
2461
 
  lockGlobalParams;
2462
 
  f = continuousView;
2463
 
  unlockGlobalParams;
2464
 
  return f;
2465
 
}
2466
 
 
2467
 
GBool GlobalParams::getEnableT1lib() {
2468
 
  GBool f;
2469
 
 
2470
 
  lockGlobalParams;
2471
 
  f = enableT1lib;
2472
 
  unlockGlobalParams;
2473
 
  return f;
2474
 
}
2475
 
 
2476
 
GBool GlobalParams::getEnableFreeType() {
2477
 
  GBool f;
2478
 
 
2479
 
  lockGlobalParams;
2480
 
  f = enableFreeType;
2481
 
  unlockGlobalParams;
2482
 
  return f;
2483
 
}
2484
 
 
2485
 
GBool GlobalParams::getDisableFreeTypeHinting() {
2486
 
  GBool f;
2487
 
 
2488
 
  lockGlobalParams;
2489
 
  f = disableFreeTypeHinting;
2490
 
  unlockGlobalParams;
2491
 
  return f;
2492
 
}
2493
 
 
2494
 
 
2495
 
GBool GlobalParams::getAntialias() {
2496
 
  GBool f;
2497
 
 
2498
 
  lockGlobalParams;
2499
 
  f = antialias;
2500
 
  unlockGlobalParams;
2501
 
  return f;
2502
 
}
2503
 
 
2504
 
GBool GlobalParams::getVectorAntialias() {
2505
 
  GBool f;
2506
 
 
2507
 
  lockGlobalParams;
2508
 
  f = vectorAntialias;
2509
 
  unlockGlobalParams;
2510
 
  return f;
2511
 
}
2512
 
 
2513
 
GBool GlobalParams::getAntialiasPrinting() {
2514
 
  GBool f;
2515
 
 
2516
 
  lockGlobalParams;
2517
 
  f = antialiasPrinting;
2518
 
  unlockGlobalParams;
2519
 
  return f;
2520
 
}
2521
 
 
2522
 
GBool GlobalParams::getStrokeAdjust() {
2523
 
  GBool f;
2524
 
 
2525
 
  lockGlobalParams;
2526
 
  f = strokeAdjust;
2527
 
  unlockGlobalParams;
2528
 
  return f;
2529
 
}
2530
 
 
2531
 
ScreenType GlobalParams::getScreenType() {
2532
 
  ScreenType t;
2533
 
 
2534
 
  lockGlobalParams;
2535
 
  t = screenType;
2536
 
  unlockGlobalParams;
2537
 
  return t;
2538
 
}
2539
 
 
2540
 
int GlobalParams::getScreenSize() {
2541
 
  int size;
2542
 
 
2543
 
  lockGlobalParams;
2544
 
  size = screenSize;
2545
 
  unlockGlobalParams;
2546
 
  return size;
2547
 
}
2548
 
 
2549
 
int GlobalParams::getScreenDotRadius() {
2550
 
  int r;
2551
 
 
2552
 
  lockGlobalParams;
2553
 
  r = screenDotRadius;
2554
 
  unlockGlobalParams;
2555
 
  return r;
2556
 
}
2557
 
 
2558
 
double GlobalParams::getScreenGamma() {
2559
 
  double gamma;
2560
 
 
2561
 
  lockGlobalParams;
2562
 
  gamma = screenGamma;
2563
 
  unlockGlobalParams;
2564
 
  return gamma;
2565
 
}
2566
 
 
2567
 
double GlobalParams::getScreenBlackThreshold() {
2568
 
  double thresh;
2569
 
 
2570
 
  lockGlobalParams;
2571
 
  thresh = screenBlackThreshold;
2572
 
  unlockGlobalParams;
2573
 
  return thresh;
2574
 
}
2575
 
 
2576
 
double GlobalParams::getScreenWhiteThreshold() {
2577
 
  double thresh;
2578
 
 
2579
 
  lockGlobalParams;
2580
 
  thresh = screenWhiteThreshold;
2581
 
  unlockGlobalParams;
2582
 
  return thresh;
2583
 
}
2584
 
 
2585
 
double GlobalParams::getMinLineWidth() {
2586
 
  double w;
2587
 
 
2588
 
  lockGlobalParams;
2589
 
  w = minLineWidth;
2590
 
  unlockGlobalParams;
2591
 
  return w;
2592
 
}
2593
 
 
2594
 
GBool GlobalParams::getDrawAnnotations() {
2595
 
  GBool draw;
2596
 
 
2597
 
  lockGlobalParams;
2598
 
  draw = drawAnnotations;
2599
 
  unlockGlobalParams;
2600
 
  return draw;
2601
 
}
2602
 
 
2603
 
GBool GlobalParams::getMapNumericCharNames() {
2604
 
  GBool map;
2605
 
 
2606
 
  lockGlobalParams;
2607
 
  map = mapNumericCharNames;
2608
 
  unlockGlobalParams;
2609
 
  return map;
2610
 
}
2611
 
 
2612
 
GBool GlobalParams::getMapUnknownCharNames() {
2613
 
  GBool map;
2614
 
 
2615
 
  lockGlobalParams;
2616
 
  map = mapUnknownCharNames;
2617
 
  unlockGlobalParams;
2618
 
  return map;
2619
 
}
2620
 
 
2621
 
GList *GlobalParams::getKeyBinding(int code, int mods, int context) {
2622
 
  KeyBinding *binding;
2623
 
  GList *cmds;
2624
 
  int modMask;
2625
 
  int i, j;
2626
 
 
2627
 
  lockGlobalParams;
2628
 
  cmds = NULL;
2629
 
  // for ASCII chars, ignore the shift modifier
2630
 
  modMask = code <= 0xff ? ~xpdfKeyModShift : ~0;
2631
 
  for (i = 0; i < keyBindings->getLength(); ++i) {
2632
 
    binding = (KeyBinding *)keyBindings->get(i);
2633
 
    if (binding->code == code &&
2634
 
        (binding->mods & modMask) == (mods & modMask) &&
2635
 
        (~binding->context | context) == ~0) {
2636
 
      cmds = new GList();
2637
 
      for (j = 0; j < binding->cmds->getLength(); ++j) {
2638
 
        cmds->append(((GString *)binding->cmds->get(j))->copy());
2639
 
      }
2640
 
      break;
2641
 
    }
2642
 
  }
2643
 
  unlockGlobalParams;
2644
 
  return cmds;
2645
 
}
2646
 
 
2647
 
GBool GlobalParams::getPrintCommands() {
2648
 
  GBool p;
2649
 
 
2650
 
  lockGlobalParams;
2651
 
  p = printCommands;
2652
 
  unlockGlobalParams;
2653
 
  return p;
2654
 
}
2655
 
 
2656
 
GBool GlobalParams::getErrQuiet() {
2657
 
  // no locking -- this function may get called from inside a locked
2658
 
  // section
2659
 
  return errQuiet;
2660
 
}
2661
 
 
2662
 
CharCodeToUnicode *GlobalParams::getCIDToUnicode(GString *collection) {
2663
 
  GString *fileName;
2664
 
  CharCodeToUnicode *ctu;
2665
 
 
2666
 
  lockGlobalParams;
2667
 
  if (!(ctu = cidToUnicodeCache->getCharCodeToUnicode(collection))) {
2668
 
    if ((fileName = (GString *)cidToUnicodes->lookup(collection)) &&
2669
 
        (ctu = CharCodeToUnicode::parseCIDToUnicode(fileName, collection))) {
2670
 
      cidToUnicodeCache->add(ctu);
2671
 
    }
2672
 
  }
2673
 
  unlockGlobalParams;
2674
 
  return ctu;
2675
 
}
2676
 
 
2677
 
CharCodeToUnicode *GlobalParams::getUnicodeToUnicode(GString *fontName) {
2678
 
  CharCodeToUnicode *ctu;
2679
 
  GHashIter *iter;
2680
 
  GString *fontPattern, *fileName;
2681
 
 
2682
 
  lockGlobalParams;
2683
 
  fileName = NULL;
2684
 
  unicodeToUnicodes->startIter(&iter);
2685
 
  while (unicodeToUnicodes->getNext(&iter, &fontPattern, (void **)&fileName)) {
2686
 
    if (strstr(fontName->getCString(), fontPattern->getCString())) {
2687
 
      unicodeToUnicodes->killIter(&iter);
2688
 
      break;
2689
 
    }
2690
 
    fileName = NULL;
2691
 
  }
2692
 
  if (fileName) {
2693
 
    if (!(ctu = unicodeToUnicodeCache->getCharCodeToUnicode(fileName))) {
2694
 
      if ((ctu = CharCodeToUnicode::parseUnicodeToUnicode(fileName))) {
2695
 
        unicodeToUnicodeCache->add(ctu);
2696
 
      }
2697
 
    }
2698
 
  } else {
2699
 
    ctu = NULL;
2700
 
  }
2701
 
  unlockGlobalParams;
2702
 
  return ctu;
2703
 
}
2704
 
 
2705
 
UnicodeMap *GlobalParams::getUnicodeMap(GString *encodingName) {
2706
 
  return getUnicodeMap2(encodingName);
2707
 
}
2708
 
 
2709
 
UnicodeMap *GlobalParams::getUnicodeMap2(GString *encodingName) {
2710
 
  UnicodeMap *map;
2711
 
 
2712
 
  if (!(map = getResidentUnicodeMap(encodingName))) {
2713
 
    lockUnicodeMapCache;
2714
 
    map = unicodeMapCache->getUnicodeMap(encodingName);
2715
 
    unlockUnicodeMapCache;
2716
 
  }
2717
 
  return map;
2718
 
}
2719
 
 
2720
 
CMap *GlobalParams::getCMap(GString *collection, GString *cMapName, Stream *stream) {
2721
 
  CMap *cMap;
2722
 
 
2723
 
  lockCMapCache;
2724
 
  cMap = cMapCache->getCMap(collection, cMapName, stream);
2725
 
  unlockCMapCache;
2726
 
  return cMap;
2727
 
}
2728
 
 
2729
 
UnicodeMap *GlobalParams::getTextEncoding() {
2730
 
  return getUnicodeMap2(textEncoding);
2731
 
}
2732
 
 
2733
 
//------------------------------------------------------------------------
2734
 
// functions to set parameters
2735
 
//------------------------------------------------------------------------
2736
 
 
2737
 
void GlobalParams::addFontFile(GString *fontName, GString *path) {
2738
 
  lockGlobalParams;
2739
 
  fontFiles->add(fontName, path);
2740
 
  unlockGlobalParams;
2741
 
}
2742
 
 
2743
 
void GlobalParams::setPSFile(char *file) {
2744
 
  lockGlobalParams;
2745
 
  if (psFile) {
2746
 
    delete psFile;
2747
 
  }
2748
 
  psFile = new GString(file);
2749
 
  unlockGlobalParams;
2750
 
}
2751
 
 
2752
 
GBool GlobalParams::setPSPaperSize(char *size) {
2753
 
  lockGlobalParams;
2754
 
  if (!strcmp(size, "match")) {
2755
 
    psPaperWidth = psPaperHeight = -1;
2756
 
  } else if (!strcmp(size, "letter")) {
2757
 
    psPaperWidth = 612;
2758
 
    psPaperHeight = 792;
2759
 
  } else if (!strcmp(size, "legal")) {
2760
 
    psPaperWidth = 612;
2761
 
    psPaperHeight = 1008;
2762
 
  } else if (!strcmp(size, "A4")) {
2763
 
    psPaperWidth = 595;
2764
 
    psPaperHeight = 842;
2765
 
  } else if (!strcmp(size, "A3")) {
2766
 
    psPaperWidth = 842;
2767
 
    psPaperHeight = 1190;
2768
 
  } else {
2769
 
    unlockGlobalParams;
2770
 
    return gFalse;
2771
 
  }
2772
 
  psImageableLLX = psImageableLLY = 0;
2773
 
  psImageableURX = psPaperWidth;
2774
 
  psImageableURY = psPaperHeight;
2775
 
  unlockGlobalParams;
2776
 
  return gTrue;
2777
 
}
2778
 
 
2779
 
void GlobalParams::setPSPaperWidth(int width) {
2780
 
  lockGlobalParams;
2781
 
  psPaperWidth = width;
2782
 
  psImageableLLX = 0;
2783
 
  psImageableURX = psPaperWidth;
2784
 
  unlockGlobalParams;
2785
 
}
2786
 
 
2787
 
void GlobalParams::setPSPaperHeight(int height) {
2788
 
  lockGlobalParams;
2789
 
  psPaperHeight = height;
2790
 
  psImageableLLY = 0;
2791
 
  psImageableURY = psPaperHeight;
2792
 
  unlockGlobalParams;
2793
 
}
2794
 
 
2795
 
void GlobalParams::setPSImageableArea(int llx, int lly, int urx, int ury) {
2796
 
  lockGlobalParams;
2797
 
  psImageableLLX = llx;
2798
 
  psImageableLLY = lly;
2799
 
  psImageableURX = urx;
2800
 
  psImageableURY = ury;
2801
 
  unlockGlobalParams;
2802
 
}
2803
 
 
2804
 
void GlobalParams::setPSCrop(GBool crop) {
2805
 
  lockGlobalParams;
2806
 
  psCrop = crop;
2807
 
  unlockGlobalParams;
2808
 
}
2809
 
 
2810
 
void GlobalParams::setPSExpandSmaller(GBool expand) {
2811
 
  lockGlobalParams;
2812
 
  psExpandSmaller = expand;
2813
 
  unlockGlobalParams;
2814
 
}
2815
 
 
2816
 
void GlobalParams::setPSShrinkLarger(GBool shrink) {
2817
 
  lockGlobalParams;
2818
 
  psShrinkLarger = shrink;
2819
 
  unlockGlobalParams;
2820
 
}
2821
 
 
2822
 
void GlobalParams::setPSCenter(GBool center) {
2823
 
  lockGlobalParams;
2824
 
  psCenter = center;
2825
 
  unlockGlobalParams;
2826
 
}
2827
 
 
2828
 
void GlobalParams::setPSDuplex(GBool duplex) {
2829
 
  lockGlobalParams;
2830
 
  psDuplex = duplex;
2831
 
  unlockGlobalParams;
2832
 
}
2833
 
 
2834
 
void GlobalParams::setPSLevel(PSLevel level) {
2835
 
  lockGlobalParams;
2836
 
  psLevel = level;
2837
 
  unlockGlobalParams;
2838
 
}
2839
 
 
2840
 
void GlobalParams::setPSEmbedType1(GBool embed) {
2841
 
  lockGlobalParams;
2842
 
  psEmbedType1 = embed;
2843
 
  unlockGlobalParams;
2844
 
}
2845
 
 
2846
 
void GlobalParams::setPSEmbedTrueType(GBool embed) {
2847
 
  lockGlobalParams;
2848
 
  psEmbedTrueType = embed;
2849
 
  unlockGlobalParams;
2850
 
}
2851
 
 
2852
 
void GlobalParams::setPSEmbedCIDPostScript(GBool embed) {
2853
 
  lockGlobalParams;
2854
 
  psEmbedCIDPostScript = embed;
2855
 
  unlockGlobalParams;
2856
 
}
2857
 
 
2858
 
void GlobalParams::setPSEmbedCIDTrueType(GBool embed) {
2859
 
  lockGlobalParams;
2860
 
  psEmbedCIDTrueType = embed;
2861
 
  unlockGlobalParams;
2862
 
}
2863
 
 
2864
 
void GlobalParams::setPSFontPassthrough(GBool passthrough) {
2865
 
  lockGlobalParams;
2866
 
  psFontPassthrough = passthrough;
2867
 
  unlockGlobalParams;
2868
 
}
2869
 
 
2870
 
void GlobalParams::setPSPreload(GBool preload) {
2871
 
  lockGlobalParams;
2872
 
  psPreload = preload;
2873
 
  unlockGlobalParams;
2874
 
}
2875
 
 
2876
 
void GlobalParams::setPSOPI(GBool opi) {
2877
 
  lockGlobalParams;
2878
 
  psOPI = opi;
2879
 
  unlockGlobalParams;
2880
 
}
2881
 
 
2882
 
void GlobalParams::setPSASCIIHex(GBool hex) {
2883
 
  lockGlobalParams;
2884
 
  psASCIIHex = hex;
2885
 
  unlockGlobalParams;
2886
 
}
2887
 
 
2888
 
void GlobalParams::setTextEncoding(char *encodingName) {
2889
 
  lockGlobalParams;
2890
 
  delete textEncoding;
2891
 
  textEncoding = new GString(encodingName);
2892
 
  unlockGlobalParams;
2893
 
}
2894
 
 
2895
 
GBool GlobalParams::setTextEOL(char *s) {
2896
 
  lockGlobalParams;
2897
 
  if (!strcmp(s, "unix")) {
2898
 
    textEOL = eolUnix;
2899
 
  } else if (!strcmp(s, "dos")) {
2900
 
    textEOL = eolDOS;
2901
 
  } else if (!strcmp(s, "mac")) {
2902
 
    textEOL = eolMac;
2903
 
  } else {
2904
 
    unlockGlobalParams;
2905
 
    return gFalse;
2906
 
  }
2907
 
  unlockGlobalParams;
2908
 
  return gTrue;
2909
 
}
2910
 
 
2911
 
void GlobalParams::setTextPageBreaks(GBool pageBreaks) {
2912
 
  lockGlobalParams;
2913
 
  textPageBreaks = pageBreaks;
2914
 
  unlockGlobalParams;
2915
 
}
2916
 
 
2917
 
void GlobalParams::setTextKeepTinyChars(GBool keep) {
2918
 
  lockGlobalParams;
2919
 
  textKeepTinyChars = keep;
2920
 
  unlockGlobalParams;
2921
 
}
2922
 
 
2923
 
void GlobalParams::setInitialZoom(char *s) {
2924
 
  lockGlobalParams;
2925
 
  delete initialZoom;
2926
 
  initialZoom = new GString(s);
2927
 
  unlockGlobalParams;
2928
 
}
2929
 
 
2930
 
void GlobalParams::setContinuousView(GBool cont) {
2931
 
  lockGlobalParams;
2932
 
  continuousView = cont;
2933
 
  unlockGlobalParams;
2934
 
}
2935
 
 
2936
 
GBool GlobalParams::setEnableT1lib(char *s) {
2937
 
  GBool ok;
2938
 
 
2939
 
  lockGlobalParams;
2940
 
  ok = parseYesNo2(s, &enableT1lib);
2941
 
  unlockGlobalParams;
2942
 
  return ok;
2943
 
}
2944
 
 
2945
 
GBool GlobalParams::setEnableFreeType(char *s) {
2946
 
  GBool ok;
2947
 
 
2948
 
  lockGlobalParams;
2949
 
  ok = parseYesNo2(s, &enableFreeType);
2950
 
  unlockGlobalParams;
2951
 
  return ok;
2952
 
}
2953
 
 
2954
 
 
2955
 
GBool GlobalParams::setAntialias(char *s) {
2956
 
  GBool ok;
2957
 
 
2958
 
  lockGlobalParams;
2959
 
  ok = parseYesNo2(s, &antialias);
2960
 
  unlockGlobalParams;
2961
 
  return ok;
2962
 
}
2963
 
 
2964
 
GBool GlobalParams::setVectorAntialias(char *s) {
2965
 
  GBool ok;
2966
 
 
2967
 
  lockGlobalParams;
2968
 
  ok = parseYesNo2(s, &vectorAntialias);
2969
 
  unlockGlobalParams;
2970
 
  return ok;
2971
 
}
2972
 
 
2973
 
void GlobalParams::setScreenType(ScreenType t) {
2974
 
  lockGlobalParams;
2975
 
  screenType = t;
2976
 
  unlockGlobalParams;
2977
 
}
2978
 
 
2979
 
void GlobalParams::setScreenSize(int size) {
2980
 
  lockGlobalParams;
2981
 
  screenSize = size;
2982
 
  unlockGlobalParams;
2983
 
}
2984
 
 
2985
 
void GlobalParams::setScreenDotRadius(int r) {
2986
 
  lockGlobalParams;
2987
 
  screenDotRadius = r;
2988
 
  unlockGlobalParams;
2989
 
}
2990
 
 
2991
 
void GlobalParams::setScreenGamma(double gamma) {
2992
 
  lockGlobalParams;
2993
 
  screenGamma = gamma;
2994
 
  unlockGlobalParams;
2995
 
}
2996
 
 
2997
 
void GlobalParams::setScreenBlackThreshold(double thresh) {
2998
 
  lockGlobalParams;
2999
 
  screenBlackThreshold = thresh;
3000
 
  unlockGlobalParams;
3001
 
}
3002
 
 
3003
 
void GlobalParams::setScreenWhiteThreshold(double thresh) {
3004
 
  lockGlobalParams;
3005
 
  screenWhiteThreshold = thresh;
3006
 
  unlockGlobalParams;
3007
 
}
3008
 
 
3009
 
void GlobalParams::setMapNumericCharNames(GBool map) {
3010
 
  lockGlobalParams;
3011
 
  mapNumericCharNames = map;
3012
 
  unlockGlobalParams;
3013
 
}
3014
 
 
3015
 
void GlobalParams::setMapUnknownCharNames(GBool map) {
3016
 
  lockGlobalParams;
3017
 
  mapUnknownCharNames = map;
3018
 
  unlockGlobalParams;
3019
 
}
3020
 
 
3021
 
void GlobalParams::setPrintCommands(GBool printCommandsA) {
3022
 
  lockGlobalParams;
3023
 
  printCommands = printCommandsA;
3024
 
  unlockGlobalParams;
3025
 
}
3026
 
 
3027
 
void GlobalParams::setErrQuiet(GBool errQuietA) {
3028
 
  lockGlobalParams;
3029
 
  errQuiet = errQuietA;
3030
 
  unlockGlobalParams;
3031
 
}
3032
 
 
3033
 
void GlobalParams::addSecurityHandler(XpdfSecurityHandler *handler) {
3034
 
#ifdef ENABLE_PLUGINS
3035
 
  lockGlobalParams;
3036
 
  securityHandlers->append(handler);
3037
 
  unlockGlobalParams;
3038
 
#endif
3039
 
}
3040
 
 
3041
 
XpdfSecurityHandler *GlobalParams::getSecurityHandler(char *name) {
3042
 
#ifdef ENABLE_PLUGINS
3043
 
  XpdfSecurityHandler *hdlr;
3044
 
  int i;
3045
 
 
3046
 
  lockGlobalParams;
3047
 
  for (i = 0; i < securityHandlers->getLength(); ++i) {
3048
 
    hdlr = (XpdfSecurityHandler *)securityHandlers->get(i);
3049
 
    if (!strcasecmp(hdlr->name, name)) {
3050
 
      unlockGlobalParams;
3051
 
      return hdlr;
3052
 
    }
3053
 
  }
3054
 
  unlockGlobalParams;
3055
 
 
3056
 
  if (!loadPlugin("security", name)) {
3057
 
    return NULL;
3058
 
  }
3059
 
 
3060
 
  lockGlobalParams;
3061
 
  for (i = 0; i < securityHandlers->getLength(); ++i) {
3062
 
    hdlr = (XpdfSecurityHandler *)securityHandlers->get(i);
3063
 
    if (!strcmp(hdlr->name, name)) {
3064
 
      unlockGlobalParams;
3065
 
      return hdlr;
3066
 
    }
3067
 
  }
3068
 
  unlockGlobalParams;
3069
 
#endif
3070
 
 
3071
 
  return NULL;
3072
 
}
3073
 
 
3074
 
#ifdef ENABLE_PLUGINS
3075
 
//------------------------------------------------------------------------
3076
 
// plugins
3077
 
//------------------------------------------------------------------------
3078
 
 
3079
 
GBool GlobalParams::loadPlugin(char *type, char *name) {
3080
 
  Plugin *plugin;
3081
 
 
3082
 
  if (!(plugin = Plugin::load(type, name))) {
3083
 
    return gFalse;
3084
 
  }
3085
 
  lockGlobalParams;
3086
 
  plugins->append(plugin);
3087
 
  unlockGlobalParams;
3088
 
  return gTrue;
3089
 
}
3090
 
 
3091
 
#endif // ENABLE_PLUGINS