~ubuntu-branches/ubuntu/natty/luatex/natty

« back to all changes in this revision

Viewing changes to source/libs/poppler/poppler-0.12.4/poppler/GlobalParams.cc

  • Committer: Package Import Robot
  • Author(s): Norbert Preining
  • Date: 2010-12-13 23:22:59 UTC
  • mfrom: (0.2.1) (1.5.4) (4.3.12 experimental)
  • Revision ID: package-import@ubuntu.com-20101213232259-nqq2mq5z5x6qldw3
Tags: 0.65.0-1
* new upstream release
* ship two source packages as they are distributed by upstream, only
  renamed to match source package requirements. Fix debian/rules
  to install the manual pdf from the right place

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
//========================================================================
 
10
//
 
11
// Modified under the Poppler project - http://poppler.freedesktop.org
 
12
//
 
13
// Copyright (C) 2005 Martin Kretzschmar <martink@gnome.org>
 
14
// Copyright (C) 2005, 2006 Kristian Høgsberg <krh@redhat.com>
 
15
// Copyright (C) 2005, 2007-2009 Albert Astals Cid <aacid@kde.org>
 
16
// Copyright (C) 2005 Jonathan Blandford <jrb@redhat.com>
 
17
// Copyright (C) 2006, 2007 Jeff Muizelaar <jeff@infidigm.net>
 
18
// Copyright (C) 2006 Takashi Iwai <tiwai@suse.de>
 
19
// Copyright (C) 2006 Ed Catmur <ed@catmur.co.uk>
 
20
// Copyright (C) 2007 Krzysztof Kowalczyk <kkowalczyk@gmail.com>
 
21
// Copyright (C) 2007, 2009 Jonathan Kew <jonathan_kew@sil.org>
 
22
// Copyright (C) 2009 Petr Gajdos <pgajdos@novell.com>
 
23
// Copyright (C) 2009 William Bader <williambader@hotmail.com>
 
24
// Copyright (C) 2009 Kovid Goyal <kovid@kovidgoyal.net>
 
25
//
 
26
// To see a description of the changes please see the Changelog file that
 
27
// came with your tarball or type make ChangeLog if you are building from git
 
28
//
 
29
//========================================================================
 
30
 
 
31
#include <config.h>
 
32
 
 
33
#ifdef USE_GCC_PRAGMAS
 
34
#pragma implementation
 
35
#endif
 
36
 
 
37
#include <string.h>
 
38
#include <stdio.h>
 
39
#include <ctype.h>
 
40
#ifdef ENABLE_PLUGINS
 
41
#  ifndef _WIN32
 
42
#    include <dlfcn.h>
 
43
#  endif
 
44
#endif
 
45
#ifdef _WIN32
 
46
#  include <shlobj.h>
 
47
#endif
 
48
#include "goo/gmem.h"
 
49
#include "goo/GooString.h"
 
50
#include "goo/GooList.h"
 
51
#include "goo/GooHash.h"
 
52
#include "goo/gfile.h"
 
53
#include "Error.h"
 
54
#include "NameToCharCode.h"
 
55
#include "CharCodeToUnicode.h"
 
56
#include "UnicodeMap.h"
 
57
#include "CMap.h"
 
58
#include "BuiltinFontTables.h"
 
59
#include "FontEncodingTables.h"
 
60
#ifdef ENABLE_PLUGINS
 
61
#  include "XpdfPluginAPI.h"
 
62
#endif
 
63
#include "GlobalParams.h"
 
64
#include "GfxFont.h"
 
65
 
 
66
#ifdef _WIN32
 
67
#  define strcasecmp stricmp
 
68
#endif
 
69
 
 
70
#if MULTITHREADED
 
71
#  define lockGlobalParams            gLockMutex(&mutex)
 
72
#  define lockUnicodeMapCache         gLockMutex(&unicodeMapCacheMutex)
 
73
#  define lockCMapCache               gLockMutex(&cMapCacheMutex)
 
74
#  define unlockGlobalParams          gUnlockMutex(&mutex)
 
75
#  define unlockUnicodeMapCache       gUnlockMutex(&unicodeMapCacheMutex)
 
76
#  define unlockCMapCache             gUnlockMutex(&cMapCacheMutex)
 
77
#else
 
78
#  define lockGlobalParams
 
79
#  define lockUnicodeMapCache
 
80
#  define lockCMapCache
 
81
#  define unlockGlobalParams
 
82
#  define unlockUnicodeMapCache
 
83
#  define unlockCMapCache
 
84
#endif
 
85
 
 
86
#ifndef FC_WEIGHT_BOOK
 
87
#define FC_WEIGHT_BOOK 75
 
88
#endif
 
89
 
 
90
#include "NameToUnicodeTable.h"
 
91
#include "UnicodeMapTables.h"
 
92
#include "UTF8.h"
 
93
 
 
94
#ifdef ENABLE_PLUGINS
 
95
#  ifdef _WIN32
 
96
extern XpdfPluginVecTable xpdfPluginVecTable;
 
97
#  endif
 
98
#endif
 
99
 
 
100
//------------------------------------------------------------------------
 
101
 
 
102
#define cidToUnicodeCacheSize     4
 
103
#define unicodeToUnicodeCacheSize 4
 
104
 
 
105
//------------------------------------------------------------------------
 
106
 
 
107
GlobalParams *globalParams = NULL;
 
108
 
 
109
//------------------------------------------------------------------------
 
110
// DisplayFontParam
 
111
//------------------------------------------------------------------------
 
112
 
 
113
DisplayFontParam::DisplayFontParam(GooString *nameA,
 
114
                                   DisplayFontParamKind kindA) {
 
115
  name = nameA;
 
116
  kind = kindA;
 
117
  switch (kind) {
 
118
  case displayFontT1:
 
119
    t1.fileName = NULL;
 
120
    break;
 
121
  case displayFontTT:
 
122
    tt.fileName = NULL;
 
123
    break;
 
124
  }
 
125
}
 
126
 
 
127
DisplayFontParam::~DisplayFontParam() {
 
128
  delete name;
 
129
  switch (kind) {
 
130
  case displayFontT1:
 
131
    if (t1.fileName) {
 
132
      delete t1.fileName;
 
133
    }
 
134
    break;
 
135
  case displayFontTT:
 
136
    if (tt.fileName) {
 
137
      delete tt.fileName;
 
138
    }
 
139
    break;
 
140
  }
 
141
}
 
142
 
 
143
#ifndef PDF_PARSER_ONLY
 
144
#ifdef _WIN32
 
145
 
 
146
//------------------------------------------------------------------------
 
147
// WinFontInfo
 
148
//------------------------------------------------------------------------
 
149
 
 
150
class WinFontInfo: public DisplayFontParam {
 
151
public:
 
152
 
 
153
  GBool bold, italic;
 
154
 
 
155
  static WinFontInfo *make(GooString *nameA, GBool boldA, GBool italicA,
 
156
                           HKEY regKey, char *winFontDir);
 
157
  WinFontInfo(GooString *nameA, GBool boldA, GBool italicA,
 
158
              GooString *fileNameA);
 
159
  virtual ~WinFontInfo();
 
160
  GBool equals(WinFontInfo *fi);
 
161
};
 
162
 
 
163
WinFontInfo *WinFontInfo::make(GooString *nameA, GBool boldA, GBool italicA,
 
164
                               HKEY regKey, char *winFontDir) {
 
165
  GooString *regName;
 
166
  GooString *fileNameA;
 
167
  char buf[MAX_PATH];
 
168
  DWORD n;
 
169
  char c;
 
170
  int i;
 
171
 
 
172
  //----- find the font file
 
173
  fileNameA = NULL;
 
174
  regName = nameA->copy();
 
175
  if (boldA) {
 
176
    regName->append(" Bold");
 
177
  }
 
178
  if (italicA) {
 
179
    regName->append(" Italic");
 
180
  }
 
181
  regName->append(" (TrueType)");
 
182
  n = sizeof(buf);
 
183
  if (RegQueryValueEx(regKey, regName->getCString(), NULL, NULL,
 
184
                      (LPBYTE)buf, &n) == ERROR_SUCCESS) {
 
185
    fileNameA = new GooString(winFontDir);
 
186
    fileNameA->append('\\')->append(buf);
 
187
  }
 
188
  delete regName;
 
189
  if (!fileNameA) {
 
190
    delete nameA;
 
191
    return NULL;
 
192
  }
 
193
 
 
194
  //----- normalize the font name
 
195
  i = 0;
 
196
  while (i < nameA->getLength()) {
 
197
    c = nameA->getChar(i);
 
198
    if (c == ' ' || c == ',' || c == '-') {
 
199
      nameA->del(i);
 
200
    } else {
 
201
      ++i;
 
202
    }
 
203
  }
 
204
 
 
205
  return new WinFontInfo(nameA, boldA, italicA, fileNameA);
 
206
}
 
207
 
 
208
WinFontInfo::WinFontInfo(GooString *nameA, GBool boldA, GBool italicA,
 
209
                         GooString *fileNameA):
 
210
  DisplayFontParam(nameA, displayFontTT)
 
211
{
 
212
  bold = boldA;
 
213
  italic = italicA;
 
214
  tt.fileName = fileNameA;
 
215
}
 
216
 
 
217
WinFontInfo::~WinFontInfo() {
 
218
}
 
219
 
 
220
GBool WinFontInfo::equals(WinFontInfo *fi) {
 
221
  return !name->cmp(fi->name) && bold == fi->bold && italic == fi->italic;
 
222
}
 
223
 
 
224
//------------------------------------------------------------------------
 
225
// WinFontList
 
226
//------------------------------------------------------------------------
 
227
 
 
228
class WinFontList {
 
229
public:
 
230
 
 
231
  WinFontList(char *winFontDirA);
 
232
  ~WinFontList();
 
233
  WinFontInfo *find(GooString *font);
 
234
 
 
235
private:
 
236
 
 
237
  void add(WinFontInfo *fi);
 
238
  static int CALLBACK enumFunc1(CONST LOGFONT *font,
 
239
                                CONST TEXTMETRIC *metrics,
 
240
                                DWORD type, LPARAM data);
 
241
  static int CALLBACK enumFunc2(CONST LOGFONT *font,
 
242
                                CONST TEXTMETRIC *metrics,
 
243
                                DWORD type, LPARAM data);
 
244
 
 
245
  GooList *fonts;                       // [WinFontInfo]
 
246
  HDC dc;                       // (only used during enumeration)
 
247
  HKEY regKey;                  // (only used during enumeration)
 
248
  char *winFontDir;             // (only used during enumeration)
 
249
};
 
250
 
 
251
WinFontList::WinFontList(char *winFontDirA) {
 
252
  OSVERSIONINFO version;
 
253
  char *path;
 
254
 
 
255
  fonts = new GooList();
 
256
  dc = GetDC(NULL);
 
257
  winFontDir = winFontDirA;
 
258
  version.dwOSVersionInfoSize = sizeof(version);
 
259
  GetVersionEx(&version);
 
260
  if (version.dwPlatformId == VER_PLATFORM_WIN32_NT) {
 
261
    path = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts\\";
 
262
  } else {
 
263
    path = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Fonts\\";
 
264
  }
 
265
  if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, path, 0,
 
266
                   KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS,
 
267
                   &regKey) == ERROR_SUCCESS) {
 
268
    EnumFonts(dc, NULL, &WinFontList::enumFunc1, (LPARAM)this);
 
269
    RegCloseKey(regKey);
 
270
  }
 
271
  ReleaseDC(NULL, dc);
 
272
}
 
273
 
 
274
WinFontList::~WinFontList() {
 
275
  deleteGooList(fonts, WinFontInfo);
 
276
}
 
277
 
 
278
void WinFontList::add(WinFontInfo *fi) {
 
279
  int i;
 
280
 
 
281
  for (i = 0; i < fonts->getLength(); ++i) {
 
282
    if (((WinFontInfo *)fonts->get(i))->equals(fi)) {
 
283
      delete fi;
 
284
      return;
 
285
    }
 
286
  }
 
287
  fonts->append(fi);
 
288
}
 
289
 
 
290
WinFontInfo *WinFontList::find(GooString *font) {
 
291
  GooString *name;
 
292
  GBool bold, italic;
 
293
  WinFontInfo *fi;
 
294
  char c;
 
295
  int n, i;
 
296
 
 
297
  name = font->copy();
 
298
 
 
299
  // remove space, comma, dash chars
 
300
  i = 0;
 
301
  while (i < name->getLength()) {
 
302
    c = name->getChar(i);
 
303
    if (c == ' ' || c == ',' || c == '-') {
 
304
      name->del(i);
 
305
    } else {
 
306
      ++i;
 
307
    }
 
308
  }
 
309
  n = name->getLength();
 
310
 
 
311
  // remove trailing "MT" (Foo-MT, Foo-BoldMT, etc.)
 
312
  if (!strcmp(name->getCString() + n - 2, "MT")) {
 
313
    name->del(n - 2, 2);
 
314
    n -= 2;
 
315
  }
 
316
 
 
317
  // look for "Italic"
 
318
  if (!strcmp(name->getCString() + n - 6, "Italic")) {
 
319
    name->del(n - 6, 6);
 
320
    italic = gTrue;
 
321
    n -= 6;
 
322
  } else {
 
323
    italic = gFalse;
 
324
  }
 
325
 
 
326
  // look for "Bold"
 
327
  if (!strcmp(name->getCString() + n - 4, "Bold")) {
 
328
    name->del(n - 4, 4);
 
329
    bold = gTrue;
 
330
    n -= 4;
 
331
  } else {
 
332
    bold = gFalse;
 
333
  }
 
334
 
 
335
  // remove trailing "MT" (FooMT-Bold, etc.)
 
336
  if (!strcmp(name->getCString() + n - 2, "MT")) {
 
337
    name->del(n - 2, 2);
 
338
    n -= 2;
 
339
  }
 
340
 
 
341
  // remove trailing "PS"
 
342
  if (!strcmp(name->getCString() + n - 2, "PS")) {
 
343
    name->del(n - 2, 2);
 
344
    n -= 2;
 
345
  }
 
346
 
 
347
  // search for the font
 
348
  fi = NULL;
 
349
  for (i = 0; i < fonts->getLength(); ++i) {
 
350
    fi = (WinFontInfo *)fonts->get(i);
 
351
    if (!fi->name->cmp(name) && fi->bold == bold && fi->italic == italic) {
 
352
      break;
 
353
    }
 
354
    fi = NULL;
 
355
  }
 
356
 
 
357
  delete name;
 
358
  return fi;
 
359
}
 
360
 
 
361
int CALLBACK WinFontList::enumFunc1(CONST LOGFONT *font,
 
362
                                    CONST TEXTMETRIC *metrics,
 
363
                                    DWORD type, LPARAM data) {
 
364
  WinFontList *fl = (WinFontList *)data;
 
365
 
 
366
  EnumFonts(fl->dc, font->lfFaceName, &WinFontList::enumFunc2, (LPARAM)fl);
 
367
  return 1;
 
368
}
 
369
 
 
370
int CALLBACK WinFontList::enumFunc2(CONST LOGFONT *font,
 
371
                                    CONST TEXTMETRIC *metrics,
 
372
                                    DWORD type, LPARAM data) {
 
373
  WinFontList *fl = (WinFontList *)data;
 
374
  WinFontInfo *fi;
 
375
 
 
376
  if (type & TRUETYPE_FONTTYPE) {
 
377
    if ((fi = WinFontInfo::make(new GooString(font->lfFaceName),
 
378
                                font->lfWeight >= 600,
 
379
                                font->lfItalic ? gTrue : gFalse,
 
380
                                fl->regKey, fl->winFontDir))) {
 
381
      fl->add(fi);
 
382
    }
 
383
  }
 
384
  return 1;
 
385
}
 
386
 
 
387
#endif // _WIN32
 
388
#endif // PDF_PARSER_ONLY
 
389
 
 
390
//------------------------------------------------------------------------
 
391
// PSFontParam
 
392
//------------------------------------------------------------------------
 
393
 
 
394
PSFontParam::PSFontParam(GooString *pdfFontNameA, int wModeA,
 
395
                         GooString *psFontNameA, GooString *encodingA) {
 
396
  pdfFontName = pdfFontNameA;
 
397
  wMode = wModeA;
 
398
  psFontName = psFontNameA;
 
399
  encoding = encodingA;
 
400
}
 
401
 
 
402
PSFontParam::~PSFontParam() {
 
403
  delete pdfFontName;
 
404
  delete psFontName;
 
405
  if (encoding) {
 
406
    delete encoding;
 
407
  }
 
408
}
 
409
 
 
410
#ifdef ENABLE_PLUGINS
 
411
//------------------------------------------------------------------------
 
412
// Plugin
 
413
//------------------------------------------------------------------------
 
414
 
 
415
class Plugin {
 
416
public:
 
417
 
 
418
  static Plugin *load(char *type, char *name);
 
419
  ~Plugin();
 
420
 
 
421
private:
 
422
 
 
423
#ifdef _WIN32
 
424
  Plugin(HMODULE libA);
 
425
  HMODULE lib;
 
426
#else
 
427
  Plugin(void *dlA);
 
428
  void *dl;
 
429
#endif
 
430
};
 
431
 
 
432
Plugin *Plugin::load(char *type, char *name) {
 
433
  GooString *path;
 
434
  Plugin *plugin;
 
435
  XpdfPluginVecTable *vt;
 
436
  XpdfBool (*xpdfInitPlugin)(void);
 
437
#ifdef _WIN32
 
438
  HMODULE libA;
 
439
#else
 
440
  void *dlA;
 
441
#endif
 
442
 
 
443
  path = globalParams->getBaseDir();
 
444
  appendToPath(path, "plugins");
 
445
  appendToPath(path, type);
 
446
  appendToPath(path, name);
 
447
 
 
448
#ifdef _WIN32
 
449
  path->append(".dll");
 
450
  if (!(libA = LoadLibrary(path->getCString()))) {
 
451
    error(-1, "Failed to load plugin '%s'",
 
452
          path->getCString());
 
453
    goto err1;
 
454
  }
 
455
  if (!(vt = (XpdfPluginVecTable *)
 
456
                 GetProcAddress(libA, "xpdfPluginVecTable"))) {
 
457
    error(-1, "Failed to find xpdfPluginVecTable in plugin '%s'",
 
458
          path->getCString());
 
459
    goto err2;
 
460
  }
 
461
#else
 
462
  //~ need to deal with other extensions here
 
463
  path->append(".so");
 
464
  if (!(dlA = dlopen(path->getCString(), RTLD_NOW))) {
 
465
    error(-1, "Failed to load plugin '%s': %s",
 
466
          path->getCString(), dlerror());
 
467
    goto err1;
 
468
  }
 
469
  if (!(vt = (XpdfPluginVecTable *)dlsym(dlA, "xpdfPluginVecTable"))) {
 
470
    error(-1, "Failed to find xpdfPluginVecTable in plugin '%s'",
 
471
          path->getCString());
 
472
    goto err2;
 
473
  }
 
474
#endif
 
475
 
 
476
  if (vt->version != xpdfPluginVecTable.version) {
 
477
    error(-1, "Plugin '%s' is wrong version", path->getCString());
 
478
    goto err2;
 
479
  }
 
480
  memcpy(vt, &xpdfPluginVecTable, sizeof(xpdfPluginVecTable));
 
481
 
 
482
#ifdef _WIN32
 
483
  if (!(xpdfInitPlugin = (XpdfBool (*)(void))
 
484
                             GetProcAddress(libA, "xpdfInitPlugin"))) {
 
485
    error(-1, "Failed to find xpdfInitPlugin in plugin '%s'",
 
486
          path->getCString());
 
487
    goto err2;
 
488
  }
 
489
#else
 
490
  if (!(xpdfInitPlugin = (XpdfBool (*)(void))dlsym(dlA, "xpdfInitPlugin"))) {
 
491
    error(-1, "Failed to find xpdfInitPlugin in plugin '%s'",
 
492
          path->getCString());
 
493
    goto err2;
 
494
  }
 
495
#endif
 
496
 
 
497
  if (!(*xpdfInitPlugin)()) {
 
498
    error(-1, "Initialization of plugin '%s' failed",
 
499
          path->getCString());
 
500
    goto err2;
 
501
  }
 
502
 
 
503
#ifdef _WIN32
 
504
  plugin = new Plugin(libA);
 
505
#else
 
506
  plugin = new Plugin(dlA);
 
507
#endif
 
508
 
 
509
  delete path;
 
510
  return plugin;
 
511
 
 
512
 err2:
 
513
#ifdef _WIN32
 
514
  FreeLibrary(libA);
 
515
#else
 
516
  dlclose(dlA);
 
517
#endif
 
518
 err1:
 
519
  delete path;
 
520
  return NULL;
 
521
}
 
522
 
 
523
#ifdef _WIN32
 
524
Plugin::Plugin(HMODULE libA) {
 
525
  lib = libA;
 
526
}
 
527
#else
 
528
Plugin::Plugin(void *dlA) {
 
529
  dl = dlA;
 
530
}
 
531
#endif
 
532
 
 
533
Plugin::~Plugin() {
 
534
  void (*xpdfFreePlugin)(void);
 
535
 
 
536
#ifdef _WIN32
 
537
  if ((xpdfFreePlugin = (void (*)(void))
 
538
                            GetProcAddress(lib, "xpdfFreePlugin"))) {
 
539
    (*xpdfFreePlugin)();
 
540
  }
 
541
  FreeLibrary(lib);
 
542
#else
 
543
  if ((xpdfFreePlugin = (void (*)(void))dlsym(dl, "xpdfFreePlugin"))) {
 
544
    (*xpdfFreePlugin)();
 
545
  }
 
546
  dlclose(dl);
 
547
#endif
 
548
}
 
549
 
 
550
#endif // ENABLE_PLUGINS
 
551
 
 
552
//------------------------------------------------------------------------
 
553
// parsing
 
554
//------------------------------------------------------------------------
 
555
 
 
556
GlobalParams::GlobalParams(const char *customPopplerDataDir)
 
557
  : popplerDataDir(customPopplerDataDir)
 
558
{
 
559
  UnicodeMap *map;
 
560
  int i;
 
561
 
 
562
#if !defined(PDF_PARSER_ONLY) && !defined(_MSC_VER)
 
563
  FcInit();
 
564
  FCcfg = FcConfigGetCurrent();
 
565
#endif
 
566
 
 
567
#if MULTITHREADED
 
568
  gInitMutex(&mutex);
 
569
  gInitMutex(&unicodeMapCacheMutex);
 
570
  gInitMutex(&cMapCacheMutex);
 
571
#endif
 
572
 
 
573
  initBuiltinFontTables();
 
574
 
 
575
  // scan the encoding in reverse because we want the lowest-numbered
 
576
  // index for each char name ('space' is encoded twice)
 
577
  macRomanReverseMap = new NameToCharCode();
 
578
  for (i = 255; i >= 0; --i) {
 
579
    if (macRomanEncoding[i]) {
 
580
      macRomanReverseMap->add(macRomanEncoding[i], (CharCode)i);
 
581
    }
 
582
  }
 
583
 
 
584
#ifdef _WIN32
 
585
  // baseDir will be set by a call to setBaseDir
 
586
  baseDir = new GooString();
 
587
#else
 
588
  baseDir = appendToPath(getHomeDir(), ".xpdf");
 
589
#endif
 
590
  nameToUnicode = new NameToCharCode();
 
591
  cidToUnicodes = new GooHash(gTrue);
 
592
  unicodeToUnicodes = new GooHash(gTrue);
 
593
  residentUnicodeMaps = new GooHash();
 
594
  unicodeMaps = new GooHash(gTrue);
 
595
  cMapDirs = new GooHash(gTrue);
 
596
  toUnicodeDirs = new GooList();
 
597
  displayFonts = new GooHash();
 
598
  psExpandSmaller = gFalse;
 
599
  psShrinkLarger = gTrue;
 
600
  psCenter = gTrue;
 
601
  psLevel = psLevel2;
 
602
  psFonts = new GooHash();
 
603
  psNamedFonts16 = new GooList();
 
604
  psFonts16 = new GooList();
 
605
  psEmbedType1 = gTrue;
 
606
  psEmbedTrueType = gTrue;
 
607
  psEmbedCIDPostScript = gTrue;
 
608
  psEmbedCIDTrueType = gTrue;
 
609
  psSubstFonts = gTrue;
 
610
  psPreload = gFalse;
 
611
  psOPI = gFalse;
 
612
  psASCIIHex = gFalse;
 
613
  textEncoding = new GooString("UTF-8");
 
614
#if defined(_WIN32)
 
615
  textEOL = eolDOS;
 
616
#elif defined(MACOS)
 
617
  textEOL = eolMac;
 
618
#else
 
619
  textEOL = eolUnix;
 
620
#endif
 
621
  textPageBreaks = gTrue;
 
622
  textKeepTinyChars = gFalse;
 
623
  fontDirs = new GooList();
 
624
  enableFreeType = gTrue;
 
625
  antialias = gTrue;
 
626
  vectorAntialias = gTrue;
 
627
  strokeAdjust = gTrue;
 
628
  screenType = screenUnset;
 
629
  screenSize = -1;
 
630
  screenDotRadius = -1;
 
631
  screenGamma = 1.0;
 
632
  screenBlackThreshold = 0.0;
 
633
  screenWhiteThreshold = 1.0;
 
634
  mapNumericCharNames = gTrue;
 
635
  mapUnknownCharNames = gFalse;
 
636
  printCommands = gFalse;
 
637
  profileCommands = gFalse;
 
638
  errQuiet = gFalse;
 
639
 
 
640
  cidToUnicodeCache = new CharCodeToUnicodeCache(cidToUnicodeCacheSize);
 
641
  unicodeToUnicodeCache =
 
642
      new CharCodeToUnicodeCache(unicodeToUnicodeCacheSize);
 
643
  unicodeMapCache = new UnicodeMapCache();
 
644
  cMapCache = new CMapCache();
 
645
 
 
646
#ifdef _WIN32
 
647
  baseFontsInitialized = gFalse;
 
648
  winFontList = NULL;
 
649
#endif
 
650
 
 
651
#ifdef ENABLE_PLUGINS
 
652
  plugins = new GooList();
 
653
  securityHandlers = new GooList();
 
654
#endif
 
655
 
 
656
  // set up the initial nameToUnicode table
 
657
  for (i = 0; nameToUnicodeTab[i].name; ++i) {
 
658
    nameToUnicode->add(nameToUnicodeTab[i].name, nameToUnicodeTab[i].u);
 
659
  }
 
660
 
 
661
  // set up the residentUnicodeMaps table
 
662
  map = new UnicodeMap("Latin1", gFalse,
 
663
                       latin1UnicodeMapRanges, latin1UnicodeMapLen);
 
664
  residentUnicodeMaps->add(map->getEncodingName(), map);
 
665
  map = new UnicodeMap("ASCII7", gFalse,
 
666
                       ascii7UnicodeMapRanges, ascii7UnicodeMapLen);
 
667
  residentUnicodeMaps->add(map->getEncodingName(), map);
 
668
  map = new UnicodeMap("Symbol", gFalse,
 
669
                       symbolUnicodeMapRanges, symbolUnicodeMapLen);
 
670
  residentUnicodeMaps->add(map->getEncodingName(), map);
 
671
  map = new UnicodeMap("ZapfDingbats", gFalse, zapfDingbatsUnicodeMapRanges,
 
672
                       zapfDingbatsUnicodeMapLen);
 
673
  residentUnicodeMaps->add(map->getEncodingName(), map);
 
674
  map = new UnicodeMap("UTF-8", gTrue, &mapUTF8);
 
675
  residentUnicodeMaps->add(map->getEncodingName(), map);
 
676
  map = new UnicodeMap("UCS-2", gTrue, &mapUCS2);
 
677
  residentUnicodeMaps->add(map->getEncodingName(), map);
 
678
 
 
679
  scanEncodingDirs();
 
680
}
 
681
 
 
682
void GlobalParams::scanEncodingDirs() {
 
683
  GDir *dir;
 
684
  GDirEntry *entry;
 
685
  const char *dataRoot = popplerDataDir ? popplerDataDir : POPPLER_DATADIR;
 
686
  
 
687
  // allocate buffer large enough to append "/nameToUnicode"
 
688
  size_t bufSize = strlen(dataRoot) + strlen("/nameToUnicode") + 1;
 
689
  char *dataPathBuffer = new char[bufSize];
 
690
  
 
691
  snprintf(dataPathBuffer, bufSize, "%s/nameToUnicode", dataRoot);
 
692
  dir = new GDir(dataPathBuffer, gTrue);
 
693
  while (entry = dir->getNextEntry(), entry != NULL) {
 
694
    if (!entry->isDir()) {
 
695
      parseNameToUnicode(entry->getFullPath());
 
696
    }
 
697
    delete entry;
 
698
  }
 
699
  delete dir;
 
700
 
 
701
  snprintf(dataPathBuffer, bufSize, "%s/cidToUnicode", dataRoot);
 
702
  dir = new GDir(dataPathBuffer, gFalse);
 
703
  while (entry = dir->getNextEntry(), entry != NULL) {
 
704
    addCIDToUnicode(entry->getName(), entry->getFullPath());
 
705
    delete entry;
 
706
  }
 
707
  delete dir;
 
708
 
 
709
  snprintf(dataPathBuffer, bufSize, "%s/unicodeMap", dataRoot);
 
710
  dir = new GDir(dataPathBuffer, gFalse);
 
711
  while (entry = dir->getNextEntry(), entry != NULL) {
 
712
    addUnicodeMap(entry->getName(), entry->getFullPath());
 
713
    delete entry;
 
714
  }
 
715
  delete dir;
 
716
 
 
717
  snprintf(dataPathBuffer, bufSize, "%s/cMap", dataRoot);
 
718
  dir = new GDir(dataPathBuffer, gFalse);
 
719
  while (entry = dir->getNextEntry(), entry != NULL) {
 
720
    addCMapDir(entry->getName(), entry->getFullPath());
 
721
    toUnicodeDirs->append(entry->getFullPath()->copy());
 
722
    delete entry;
 
723
  }
 
724
  delete dir;
 
725
  
 
726
  delete[] dataPathBuffer;
 
727
}
 
728
 
 
729
void GlobalParams::parseNameToUnicode(GooString *name) {
 
730
  char *tok1, *tok2;
 
731
  FILE *f;
 
732
  char buf[256];
 
733
  int line;
 
734
  Unicode u;
 
735
 
 
736
  if (!(f = fopen(name->getCString(), "r"))) {
 
737
    error(-1, "Couldn't open 'nameToUnicode' file '%s'",
 
738
          name->getCString());
 
739
    return;
 
740
  }
 
741
  line = 1;
 
742
  while (getLine(buf, sizeof(buf), f)) {
 
743
    tok1 = strtok(buf, " \t\r\n");
 
744
    tok2 = strtok(NULL, " \t\r\n");
 
745
    if (tok1 && tok2) {
 
746
      sscanf(tok1, "%x", &u);
 
747
      nameToUnicode->add(tok2, u);
 
748
    } else {
 
749
      error(-1, "Bad line in 'nameToUnicode' file (%s:%d)",
 
750
            name->getCString(), line);
 
751
    }
 
752
    ++line;
 
753
  }
 
754
  fclose(f);
 
755
}
 
756
 
 
757
void GlobalParams::addCIDToUnicode(GooString *collection,
 
758
                                   GooString *fileName) {
 
759
  GooString *old;
 
760
 
 
761
  if ((old = (GooString *)cidToUnicodes->remove(collection))) {
 
762
    delete old;
 
763
  }
 
764
  cidToUnicodes->add(collection->copy(), fileName->copy());
 
765
}
 
766
 
 
767
void GlobalParams::addUnicodeMap(GooString *encodingName, GooString *fileName)
 
768
{
 
769
  GooString *old;
 
770
 
 
771
  if ((old = (GooString *)unicodeMaps->remove(encodingName))) {
 
772
    delete old;
 
773
  }
 
774
  unicodeMaps->add(encodingName->copy(), fileName->copy());
 
775
}
 
776
 
 
777
void GlobalParams::addCMapDir(GooString *collection, GooString *dir) {
 
778
  GooList *list;
 
779
 
 
780
  if (!(list = (GooList *)cMapDirs->lookup(collection))) {
 
781
    list = new GooList();
 
782
    cMapDirs->add(collection->copy(), list);
 
783
  }
 
784
  list->append(dir->copy());
 
785
}
 
786
 
 
787
GBool GlobalParams::parseYesNo2(char *token, GBool *flag) {
 
788
  if (!strcmp(token, "yes")) {
 
789
    *flag = gTrue;
 
790
  } else if (!strcmp(token, "no")) {
 
791
    *flag = gFalse;
 
792
  } else {
 
793
    return gFalse;
 
794
  }
 
795
  return gTrue;
 
796
}
 
797
 
 
798
GlobalParams::~GlobalParams() {
 
799
  freeBuiltinFontTables();
 
800
 
 
801
  delete macRomanReverseMap;
 
802
 
 
803
  delete baseDir;
 
804
  delete nameToUnicode;
 
805
  deleteGooHash(cidToUnicodes, GooString);
 
806
  deleteGooHash(unicodeToUnicodes, GooString);
 
807
  deleteGooHash(residentUnicodeMaps, UnicodeMap);
 
808
  deleteGooHash(unicodeMaps, GooString);
 
809
  deleteGooList(toUnicodeDirs, GooString);
 
810
  deleteGooHash(displayFonts, DisplayFontParam);
 
811
#ifdef _WIN32
 
812
  delete winFontList;
 
813
#endif
 
814
  deleteGooHash(psFonts, PSFontParam);
 
815
  deleteGooList(psNamedFonts16, PSFontParam);
 
816
  deleteGooList(psFonts16, PSFontParam);
 
817
  delete textEncoding;
 
818
  deleteGooList(fontDirs, GooString);
 
819
 
 
820
  GooHashIter *iter;
 
821
  GooString *key;
 
822
  cMapDirs->startIter(&iter);
 
823
  void *val;
 
824
  while (cMapDirs->getNext(&iter, &key, &val)) {
 
825
    GooList* list = (GooList*)val;
 
826
    deleteGooList(list, GooString);
 
827
  }
 
828
  delete cMapDirs;
 
829
 
 
830
  delete cidToUnicodeCache;
 
831
  delete unicodeToUnicodeCache;
 
832
  delete unicodeMapCache;
 
833
  delete cMapCache;
 
834
 
 
835
#ifdef ENABLE_PLUGINS
 
836
  delete securityHandlers;
 
837
  deleteGooList(plugins, Plugin);
 
838
#endif
 
839
 
 
840
#if MULTITHREADED
 
841
  gDestroyMutex(&mutex);
 
842
  gDestroyMutex(&unicodeMapCacheMutex);
 
843
  gDestroyMutex(&cMapCacheMutex);
 
844
#endif
 
845
}
 
846
 
 
847
//------------------------------------------------------------------------
 
848
 
 
849
void GlobalParams::setBaseDir(char *dir) {
 
850
  delete baseDir;
 
851
  baseDir = new GooString(dir);
 
852
}
 
853
 
 
854
//------------------------------------------------------------------------
 
855
// accessors
 
856
//------------------------------------------------------------------------
 
857
 
 
858
CharCode GlobalParams::getMacRomanCharCode(char *charName) {
 
859
  // no need to lock - macRomanReverseMap is constant
 
860
  return macRomanReverseMap->lookup(charName);
 
861
}
 
862
 
 
863
GooString *GlobalParams::getBaseDir() {
 
864
  GooString *s;
 
865
 
 
866
  lockGlobalParams;
 
867
  s = baseDir->copy();
 
868
  unlockGlobalParams;
 
869
  return s;
 
870
}
 
871
 
 
872
Unicode GlobalParams::mapNameToUnicode(char *charName) {
 
873
  // no need to lock - nameToUnicode is constant
 
874
  return nameToUnicode->lookup(charName);
 
875
}
 
876
 
 
877
UnicodeMap *GlobalParams::getResidentUnicodeMap(GooString *encodingName) {
 
878
  UnicodeMap *map;
 
879
 
 
880
  lockGlobalParams;
 
881
  map = (UnicodeMap *)residentUnicodeMaps->lookup(encodingName);
 
882
  unlockGlobalParams;
 
883
  if (map) {
 
884
    map->incRefCnt();
 
885
  }
 
886
  return map;
 
887
}
 
888
 
 
889
FILE *GlobalParams::getUnicodeMapFile(GooString *encodingName) {
 
890
  GooString *fileName;
 
891
  FILE *f;
 
892
 
 
893
  lockGlobalParams;
 
894
  if ((fileName = (GooString *)unicodeMaps->lookup(encodingName))) {
 
895
    f = fopen(fileName->getCString(), "r");
 
896
  } else {
 
897
    f = NULL;
 
898
  }
 
899
  unlockGlobalParams;
 
900
  return f;
 
901
}
 
902
 
 
903
FILE *GlobalParams::findCMapFile(GooString *collection, GooString *cMapName) {
 
904
  GooList *list;
 
905
  GooString *dir;
 
906
  GooString *fileName;
 
907
  FILE *f;
 
908
  int i;
 
909
 
 
910
  lockGlobalParams;
 
911
  if (!(list = (GooList *)cMapDirs->lookup(collection))) {
 
912
    unlockGlobalParams;
 
913
    return NULL;
 
914
  }
 
915
  for (i = 0; i < list->getLength(); ++i) {
 
916
    dir = (GooString *)list->get(i);
 
917
    fileName = appendToPath(dir->copy(), cMapName->getCString());
 
918
    f = fopen(fileName->getCString(), "r");
 
919
    delete fileName;
 
920
    if (f) {
 
921
      unlockGlobalParams;
 
922
      return f;
 
923
    }
 
924
  }
 
925
  unlockGlobalParams;
 
926
  return NULL;
 
927
}
 
928
 
 
929
FILE *GlobalParams::findToUnicodeFile(GooString *name) {
 
930
  GooString *dir, *fileName;
 
931
  FILE *f;
 
932
  int i;
 
933
 
 
934
  lockGlobalParams;
 
935
  for (i = 0; i < toUnicodeDirs->getLength(); ++i) {
 
936
    dir = (GooString *)toUnicodeDirs->get(i);
 
937
    fileName = appendToPath(dir->copy(), name->getCString());
 
938
    f = fopen(fileName->getCString(), "r");
 
939
    delete fileName;
 
940
    if (f) {
 
941
      unlockGlobalParams;
 
942
      return f;
 
943
    }
 
944
  }
 
945
  unlockGlobalParams;
 
946
  return NULL;
 
947
}
 
948
 
 
949
#if !defined(PDF_PARSER_ONLY) && !defined(_MSC_VER)
 
950
static GBool findModifier(const char *name, const char *modifier, const char **start)
 
951
{
 
952
  const char *match;
 
953
 
 
954
  if (name == NULL)
 
955
    return gFalse;
 
956
 
 
957
  match = strstr(name, modifier);
 
958
  if (match) {
 
959
    if (*start == NULL || match < *start)
 
960
      *start = match;
 
961
    return gTrue;
 
962
  }
 
963
  else {
 
964
    return gFalse;
 
965
  }
 
966
}
 
967
 
 
968
static FcPattern *buildFcPattern(GfxFont *font)
 
969
{
 
970
  int weight = -1,
 
971
      slant = -1,
 
972
      width = -1,
 
973
      spacing = -1;
 
974
  bool deleteFamily = false;
 
975
  char *family, *name, *lang, *modifiers;
 
976
  const char *start;
 
977
  FcPattern *p;
 
978
 
 
979
  // this is all heuristics will be overwritten if font had proper info
 
980
  name = font->getName()->getCString();
 
981
  
 
982
  modifiers = strchr (name, ',');
 
983
  if (modifiers == NULL)
 
984
    modifiers = strchr (name, '-');
 
985
  
 
986
  // remove the - from the names, for some reason, Fontconfig does not
 
987
  // understand "MS-Mincho" but does with "MS Mincho"
 
988
  int len = strlen(name);
 
989
  for (int i = 0; i < len; i++)
 
990
    name[i] = (name[i] == '-' ? ' ' : name[i]);
 
991
 
 
992
  start = NULL;
 
993
  findModifier(modifiers, "Regular", &start);
 
994
  findModifier(modifiers, "Roman", &start);
 
995
  
 
996
  if (findModifier(modifiers, "Oblique", &start))
 
997
    slant = FC_SLANT_OBLIQUE;
 
998
  if (findModifier(modifiers, "Italic", &start))
 
999
    slant = FC_SLANT_ITALIC;
 
1000
  if (findModifier(modifiers, "Bold", &start))
 
1001
    weight = FC_WEIGHT_BOLD;
 
1002
  if (findModifier(modifiers, "Light", &start))
 
1003
    weight = FC_WEIGHT_LIGHT;
 
1004
  if (findModifier(modifiers, "Condensed", &start))
 
1005
    width = FC_WIDTH_CONDENSED;
 
1006
  
 
1007
  if (start) {
 
1008
    // There have been "modifiers" in the name, crop them to obtain
 
1009
    // the family name
 
1010
    family = new char[len+1];
 
1011
    strcpy(family, name);
 
1012
    int pos = (modifiers - name);
 
1013
    family[pos] = '\0';
 
1014
    deleteFamily = true;
 
1015
  }
 
1016
  else {
 
1017
    family = name;
 
1018
  }
 
1019
  
 
1020
  // use font flags
 
1021
  if (font->isFixedWidth())
 
1022
    spacing = FC_MONO;
 
1023
  if (font->isBold())
 
1024
    weight = FC_WEIGHT_BOLD;
 
1025
  if (font->isItalic())
 
1026
    slant = FC_SLANT_ITALIC;
 
1027
  
 
1028
  // if the FontDescriptor specified a family name use it
 
1029
  if (font->getFamily()) {
 
1030
    if (deleteFamily) {
 
1031
      delete[] family;
 
1032
      deleteFamily = false;
 
1033
    }
 
1034
    family = font->getFamily()->getCString();
 
1035
  }
 
1036
  
 
1037
  // if the FontDescriptor specified a weight use it
 
1038
  switch (font -> getWeight())
 
1039
  {
 
1040
    case GfxFont::W100: weight = FC_WEIGHT_EXTRALIGHT; break; 
 
1041
    case GfxFont::W200: weight = FC_WEIGHT_LIGHT; break; 
 
1042
    case GfxFont::W300: weight = FC_WEIGHT_BOOK; break; 
 
1043
    case GfxFont::W400: weight = FC_WEIGHT_NORMAL; break; 
 
1044
    case GfxFont::W500: weight = FC_WEIGHT_MEDIUM; break; 
 
1045
    case GfxFont::W600: weight = FC_WEIGHT_DEMIBOLD; break; 
 
1046
    case GfxFont::W700: weight = FC_WEIGHT_BOLD; break; 
 
1047
    case GfxFont::W800: weight = FC_WEIGHT_EXTRABOLD; break; 
 
1048
    case GfxFont::W900: weight = FC_WEIGHT_BLACK; break; 
 
1049
    default: break; 
 
1050
  }
 
1051
  
 
1052
  // if the FontDescriptor specified a width use it
 
1053
  switch (font -> getStretch())
 
1054
  {
 
1055
    case GfxFont::UltraCondensed: width = FC_WIDTH_ULTRACONDENSED; break; 
 
1056
    case GfxFont::ExtraCondensed: width = FC_WIDTH_EXTRACONDENSED; break; 
 
1057
    case GfxFont::Condensed: width = FC_WIDTH_CONDENSED; break; 
 
1058
    case GfxFont::SemiCondensed: width = FC_WIDTH_SEMICONDENSED; break; 
 
1059
    case GfxFont::Normal: width = FC_WIDTH_NORMAL; break; 
 
1060
    case GfxFont::SemiExpanded: width = FC_WIDTH_SEMIEXPANDED; break; 
 
1061
    case GfxFont::Expanded: width = FC_WIDTH_EXPANDED; break; 
 
1062
    case GfxFont::ExtraExpanded: width = FC_WIDTH_EXTRAEXPANDED; break; 
 
1063
    case GfxFont::UltraExpanded: width = FC_WIDTH_ULTRAEXPANDED; break; 
 
1064
    default: break; 
 
1065
  }
 
1066
  
 
1067
  // find the language we want the font to support
 
1068
  if (font->isCIDFont())
 
1069
  {
 
1070
    GooString *collection = ((GfxCIDFont *)font)->getCollection();
 
1071
    if (collection)
 
1072
    {
 
1073
      if (strcmp(collection->getCString(), "Adobe-GB1") == 0)
 
1074
        lang = "zh-cn"; // Simplified Chinese
 
1075
      else if (strcmp(collection->getCString(), "Adobe-CNS1") == 0)
 
1076
        lang = "zh-tw"; // Traditional Chinese
 
1077
      else if (strcmp(collection->getCString(), "Adobe-Japan1") == 0)
 
1078
        lang = "ja"; // Japanese
 
1079
      else if (strcmp(collection->getCString(), "Adobe-Japan2") == 0)
 
1080
        lang = "ja"; // Japanese
 
1081
      else if (strcmp(collection->getCString(), "Adobe-Korea1") == 0)
 
1082
        lang = "ko"; // Korean
 
1083
      else if (strcmp(collection->getCString(), "Adobe-UCS") == 0)
 
1084
        lang = "xx";
 
1085
      else if (strcmp(collection->getCString(), "Adobe-Identity") == 0)
 
1086
        lang = "xx";
 
1087
      else
 
1088
      {
 
1089
        error(-1, "Unknown CID font collection, please report to poppler bugzilla.");
 
1090
        lang = "xx";
 
1091
      }
 
1092
    }
 
1093
    else lang = "xx";
 
1094
  }
 
1095
  else lang = "xx";
 
1096
  
 
1097
  p = FcPatternBuild(NULL,
 
1098
                    FC_FAMILY, FcTypeString, family,
 
1099
                    FC_LANG, FcTypeString, lang,
 
1100
                    NULL);
 
1101
  if (slant != -1) FcPatternAddInteger(p, FC_SLANT, slant);
 
1102
  if (weight != -1) FcPatternAddInteger(p, FC_WEIGHT, weight);
 
1103
  if (width != -1) FcPatternAddInteger(p, FC_WIDTH, width);
 
1104
  if (spacing != -1) FcPatternAddInteger(p, FC_SPACING, spacing);
 
1105
 
 
1106
  if (deleteFamily)
 
1107
    delete[] family;
 
1108
  return p;
 
1109
}
 
1110
#endif
 
1111
 
 
1112
/* if you can't or don't want to use Fontconfig, you need to implement
 
1113
   this function for your platform. For Windows, it's in GlobalParamsWin.cc
 
1114
*/
 
1115
#ifdef PDF_PARSER_ONLY
 
1116
DisplayFontParam *GlobalParams::getDisplayFont(GfxFont *font) {
 
1117
  return (DisplayFontParam * )NULL;
 
1118
}
 
1119
#else
 
1120
#ifndef _MSC_VER
 
1121
DisplayFontParam *GlobalParams::getDisplayFont(GfxFont *font) {
 
1122
  DisplayFontParam *dfp;
 
1123
  FcPattern *p=0;
 
1124
 
 
1125
  GooString *fontName = font->getName();
 
1126
  if (!fontName) return NULL;
 
1127
  
 
1128
  lockGlobalParams;
 
1129
  dfp = font->dfp;
 
1130
  if (!dfp)
 
1131
  {
 
1132
    FcChar8* s;
 
1133
    char * ext;
 
1134
    FcResult res;
 
1135
    FcFontSet *set;
 
1136
    int i;
 
1137
    p = buildFcPattern(font);
 
1138
 
 
1139
    if (!p)
 
1140
      goto fin;
 
1141
    FcConfigSubstitute(FCcfg, p, FcMatchPattern);
 
1142
    FcDefaultSubstitute(p);
 
1143
    set = FcFontSort(FCcfg, p, FcFalse, NULL, &res);
 
1144
    if (!set)
 
1145
      goto fin;
 
1146
    for (i = 0; i < set->nfont; ++i)
 
1147
    {
 
1148
      res = FcPatternGetString(set->fonts[i], FC_FILE, 0, &s);
 
1149
      if (res != FcResultMatch || !s)
 
1150
        continue;
 
1151
      ext = strrchr((char*)s,'.');
 
1152
      if (!ext)
 
1153
        continue;
 
1154
      if (!strncasecmp(ext,".ttf",4) || !strncasecmp(ext, ".ttc", 4))
 
1155
      {
 
1156
        dfp = new DisplayFontParam(fontName->copy(), displayFontTT);  
 
1157
        dfp->tt.fileName = new GooString((char*)s);
 
1158
        FcPatternGetInteger(set->fonts[i], FC_INDEX, 0, &(dfp->tt.faceIndex));
 
1159
      }
 
1160
      else if (!strncasecmp(ext,".pfa",4) || !strncasecmp(ext,".pfb",4)) 
 
1161
      {
 
1162
        dfp = new DisplayFontParam(fontName->copy(), displayFontT1);  
 
1163
        dfp->t1.fileName = new GooString((char*)s);
 
1164
      }
 
1165
      else
 
1166
        continue;
 
1167
      font->dfp = dfp;
 
1168
      break;
 
1169
    }
 
1170
    FcFontSetDestroy(set);
 
1171
  }
 
1172
fin:
 
1173
  if (p)
 
1174
    FcPatternDestroy(p);
 
1175
 
 
1176
  unlockGlobalParams;
 
1177
  return dfp;
 
1178
}
 
1179
#endif
 
1180
#endif
 
1181
 
 
1182
GBool GlobalParams::getPSExpandSmaller() {
 
1183
  GBool f;
 
1184
 
 
1185
  lockGlobalParams;
 
1186
  f = psExpandSmaller;
 
1187
  unlockGlobalParams;
 
1188
  return f;
 
1189
}
 
1190
 
 
1191
GBool GlobalParams::getPSShrinkLarger() {
 
1192
  GBool f;
 
1193
 
 
1194
  lockGlobalParams;
 
1195
  f = psShrinkLarger;
 
1196
  unlockGlobalParams;
 
1197
  return f;
 
1198
}
 
1199
 
 
1200
GBool GlobalParams::getPSCenter() {
 
1201
  GBool f;
 
1202
 
 
1203
  lockGlobalParams;
 
1204
  f = psCenter;
 
1205
  unlockGlobalParams;
 
1206
  return f;
 
1207
}
 
1208
 
 
1209
PSLevel GlobalParams::getPSLevel() {
 
1210
  PSLevel level;
 
1211
 
 
1212
  lockGlobalParams;
 
1213
  level = psLevel;
 
1214
  unlockGlobalParams;
 
1215
  return level;
 
1216
}
 
1217
 
 
1218
PSFontParam *GlobalParams::getPSFont(GooString *fontName) {
 
1219
  PSFontParam *p;
 
1220
 
 
1221
  lockGlobalParams;
 
1222
  p = (PSFontParam *)psFonts->lookup(fontName);
 
1223
  unlockGlobalParams;
 
1224
  return p;
 
1225
}
 
1226
 
 
1227
PSFontParam *GlobalParams::getPSFont16(GooString *fontName,
 
1228
                                       GooString *collection, int wMode) {
 
1229
  PSFontParam *p;
 
1230
  int i;
 
1231
 
 
1232
  lockGlobalParams;
 
1233
  p = NULL;
 
1234
  if (fontName) {
 
1235
    for (i = 0; i < psNamedFonts16->getLength(); ++i) {
 
1236
      p = (PSFontParam *)psNamedFonts16->get(i);
 
1237
      if (!p->pdfFontName->cmp(fontName) &&
 
1238
          p->wMode == wMode) {
 
1239
        break;
 
1240
      }
 
1241
      p = NULL;
 
1242
    }
 
1243
  }
 
1244
  if (!p && collection) {
 
1245
    for (i = 0; i < psFonts16->getLength(); ++i) {
 
1246
      p = (PSFontParam *)psFonts16->get(i);
 
1247
      if (!p->pdfFontName->cmp(collection) &&
 
1248
          p->wMode == wMode) {
 
1249
        break;
 
1250
      }
 
1251
      p = NULL;
 
1252
    }
 
1253
  }
 
1254
  unlockGlobalParams;
 
1255
  return p;
 
1256
}
 
1257
 
 
1258
GBool GlobalParams::getPSEmbedType1() {
 
1259
  GBool e;
 
1260
 
 
1261
  lockGlobalParams;
 
1262
  e = psEmbedType1;
 
1263
  unlockGlobalParams;
 
1264
  return e;
 
1265
}
 
1266
 
 
1267
GBool GlobalParams::getPSEmbedTrueType() {
 
1268
  GBool e;
 
1269
 
 
1270
  lockGlobalParams;
 
1271
  e = psEmbedTrueType;
 
1272
  unlockGlobalParams;
 
1273
  return e;
 
1274
}
 
1275
 
 
1276
GBool GlobalParams::getPSEmbedCIDPostScript() {
 
1277
  GBool e;
 
1278
 
 
1279
  lockGlobalParams;
 
1280
  e = psEmbedCIDPostScript;
 
1281
  unlockGlobalParams;
 
1282
  return e;
 
1283
}
 
1284
 
 
1285
GBool GlobalParams::getPSEmbedCIDTrueType() {
 
1286
  GBool e;
 
1287
 
 
1288
  lockGlobalParams;
 
1289
  e = psEmbedCIDTrueType;
 
1290
  unlockGlobalParams;
 
1291
  return e;
 
1292
}
 
1293
 
 
1294
GBool GlobalParams::getPSSubstFonts() {
 
1295
  GBool e;
 
1296
 
 
1297
  lockGlobalParams;
 
1298
  e = psSubstFonts;
 
1299
  unlockGlobalParams;
 
1300
  return e;
 
1301
}
 
1302
 
 
1303
GBool GlobalParams::getPSPreload() {
 
1304
  GBool preload;
 
1305
 
 
1306
  lockGlobalParams;
 
1307
  preload = psPreload;
 
1308
  unlockGlobalParams;
 
1309
  return preload;
 
1310
}
 
1311
 
 
1312
GBool GlobalParams::getPSOPI() {
 
1313
  GBool opi;
 
1314
 
 
1315
  lockGlobalParams;
 
1316
  opi = psOPI;
 
1317
  unlockGlobalParams;
 
1318
  return opi;
 
1319
}
 
1320
 
 
1321
GBool GlobalParams::getPSASCIIHex() {
 
1322
  GBool ah;
 
1323
 
 
1324
  lockGlobalParams;
 
1325
  ah = psASCIIHex;
 
1326
  unlockGlobalParams;
 
1327
  return ah;
 
1328
}
 
1329
 
 
1330
GooString *GlobalParams::getTextEncodingName() {
 
1331
  GooString *s;
 
1332
 
 
1333
  lockGlobalParams;
 
1334
  s = textEncoding->copy();
 
1335
  unlockGlobalParams;
 
1336
  return s;
 
1337
}
 
1338
 
 
1339
EndOfLineKind GlobalParams::getTextEOL() {
 
1340
  EndOfLineKind eol;
 
1341
 
 
1342
  lockGlobalParams;
 
1343
  eol = textEOL;
 
1344
  unlockGlobalParams;
 
1345
  return eol;
 
1346
}
 
1347
 
 
1348
GBool GlobalParams::getTextPageBreaks() {
 
1349
  GBool pageBreaks;
 
1350
 
 
1351
  lockGlobalParams;
 
1352
  pageBreaks = textPageBreaks;
 
1353
  unlockGlobalParams;
 
1354
  return pageBreaks;
 
1355
}
 
1356
 
 
1357
GBool GlobalParams::getTextKeepTinyChars() {
 
1358
  GBool tiny;
 
1359
 
 
1360
  lockGlobalParams;
 
1361
  tiny = textKeepTinyChars;
 
1362
  unlockGlobalParams;
 
1363
  return tiny;
 
1364
}
 
1365
 
 
1366
GooString *GlobalParams::findFontFile(GooString *fontName, char **exts) {
 
1367
  GooString *dir, *fileName;
 
1368
  char **ext;
 
1369
  FILE *f;
 
1370
  int i;
 
1371
 
 
1372
  lockGlobalParams;
 
1373
  for (i = 0; i < fontDirs->getLength(); ++i) {
 
1374
    dir = (GooString *)fontDirs->get(i);
 
1375
    for (ext = exts; *ext; ++ext) {
 
1376
      fileName = appendToPath(dir->copy(), fontName->getCString());
 
1377
      fileName->append(*ext);
 
1378
      if ((f = fopen(fileName->getCString(), "rb"))) {
 
1379
        fclose(f);
 
1380
        unlockGlobalParams;
 
1381
        return fileName;
 
1382
      }
 
1383
      delete fileName;
 
1384
    }
 
1385
  }
 
1386
  unlockGlobalParams;
 
1387
  return NULL;
 
1388
}
 
1389
 
 
1390
GBool GlobalParams::getEnableFreeType() {
 
1391
  GBool f;
 
1392
 
 
1393
  lockGlobalParams;
 
1394
  f = enableFreeType;
 
1395
  unlockGlobalParams;
 
1396
  return f;
 
1397
}
 
1398
 
 
1399
 
 
1400
GBool GlobalParams::getAntialias() {
 
1401
  GBool f;
 
1402
 
 
1403
  lockGlobalParams;
 
1404
  f = antialias;
 
1405
  unlockGlobalParams;
 
1406
  return f;
 
1407
}
 
1408
 
 
1409
GBool GlobalParams::getVectorAntialias() {
 
1410
  GBool f;
 
1411
 
 
1412
  lockGlobalParams;
 
1413
  f = vectorAntialias;
 
1414
  unlockGlobalParams;
 
1415
  return f;
 
1416
}
 
1417
 
 
1418
GBool GlobalParams::getStrokeAdjust() {
 
1419
  GBool f;
 
1420
 
 
1421
  lockGlobalParams;
 
1422
  f = strokeAdjust;
 
1423
  unlockGlobalParams;
 
1424
  return f;
 
1425
}
 
1426
 
 
1427
ScreenType GlobalParams::getScreenType() {
 
1428
  ScreenType t;
 
1429
 
 
1430
  lockGlobalParams;
 
1431
  t = screenType;
 
1432
  unlockGlobalParams;
 
1433
  return t;
 
1434
}
 
1435
 
 
1436
int GlobalParams::getScreenSize() {
 
1437
  int size;
 
1438
 
 
1439
  lockGlobalParams;
 
1440
  size = screenSize;
 
1441
  unlockGlobalParams;
 
1442
  return size;
 
1443
}
 
1444
 
 
1445
int GlobalParams::getScreenDotRadius() {
 
1446
  int r;
 
1447
 
 
1448
  lockGlobalParams;
 
1449
  r = screenDotRadius;
 
1450
  unlockGlobalParams;
 
1451
  return r;
 
1452
}
 
1453
 
 
1454
double GlobalParams::getScreenGamma() {
 
1455
  double gamma;
 
1456
 
 
1457
  lockGlobalParams;
 
1458
  gamma = screenGamma;
 
1459
  unlockGlobalParams;
 
1460
  return gamma;
 
1461
}
 
1462
 
 
1463
double GlobalParams::getScreenBlackThreshold() {
 
1464
  double thresh;
 
1465
 
 
1466
  lockGlobalParams;
 
1467
  thresh = screenBlackThreshold;
 
1468
  unlockGlobalParams;
 
1469
  return thresh;
 
1470
}
 
1471
 
 
1472
double GlobalParams::getScreenWhiteThreshold() {
 
1473
  double thresh;
 
1474
 
 
1475
  lockGlobalParams;
 
1476
  thresh = screenWhiteThreshold;
 
1477
  unlockGlobalParams;
 
1478
  return thresh;
 
1479
}
 
1480
 
 
1481
GBool GlobalParams::getMapNumericCharNames() {
 
1482
  GBool map;
 
1483
 
 
1484
  lockGlobalParams;
 
1485
  map = mapNumericCharNames;
 
1486
  unlockGlobalParams;
 
1487
  return map;
 
1488
}
 
1489
 
 
1490
GBool GlobalParams::getMapUnknownCharNames() {
 
1491
  GBool map;
 
1492
 
 
1493
  lockGlobalParams;
 
1494
  map = mapUnknownCharNames;
 
1495
  unlockGlobalParams;
 
1496
  return map;
 
1497
}
 
1498
 
 
1499
GBool GlobalParams::getPrintCommands() {
 
1500
  GBool p;
 
1501
 
 
1502
  lockGlobalParams;
 
1503
  p = printCommands;
 
1504
  unlockGlobalParams;
 
1505
  return p;
 
1506
}
 
1507
 
 
1508
GBool GlobalParams::getProfileCommands() {
 
1509
  GBool p;
 
1510
 
 
1511
  lockGlobalParams;
 
1512
  p = profileCommands;
 
1513
  unlockGlobalParams;
 
1514
  return p;
 
1515
}
 
1516
 
 
1517
GBool GlobalParams::getErrQuiet() {
 
1518
  // no locking -- this function may get called from inside a locked
 
1519
  // section
 
1520
  return errQuiet;
 
1521
}
 
1522
 
 
1523
CharCodeToUnicode *GlobalParams::getCIDToUnicode(GooString *collection) {
 
1524
  GooString *fileName;
 
1525
  CharCodeToUnicode *ctu;
 
1526
 
 
1527
  lockGlobalParams;
 
1528
  if (!(ctu = cidToUnicodeCache->getCharCodeToUnicode(collection))) {
 
1529
    if ((fileName = (GooString *)cidToUnicodes->lookup(collection)) &&
 
1530
        (ctu = CharCodeToUnicode::parseCIDToUnicode(fileName, collection))) {
 
1531
      cidToUnicodeCache->add(ctu);
 
1532
    }
 
1533
  }
 
1534
  unlockGlobalParams;
 
1535
  return ctu;
 
1536
}
 
1537
 
 
1538
CharCodeToUnicode *GlobalParams::getUnicodeToUnicode(GooString *fontName) {
 
1539
  lockGlobalParams;
 
1540
  GooHashIter *iter;
 
1541
  unicodeToUnicodes->startIter(&iter);
 
1542
  GooString *fileName = NULL;
 
1543
  GooString *fontPattern;
 
1544
  void *val;
 
1545
  while (!fileName && unicodeToUnicodes->getNext(&iter, &fontPattern, &val)) {
 
1546
    if (strstr(fontName->getCString(), fontPattern->getCString())) {
 
1547
      unicodeToUnicodes->killIter(&iter);
 
1548
      fileName = (GooString*)val;
 
1549
    }
 
1550
  }
 
1551
  CharCodeToUnicode *ctu = NULL;
 
1552
  if (fileName) {
 
1553
    ctu = unicodeToUnicodeCache->getCharCodeToUnicode(fileName);
 
1554
    if (!ctu) {
 
1555
      ctu = CharCodeToUnicode::parseUnicodeToUnicode(fileName);
 
1556
      if (ctu)
 
1557
         unicodeToUnicodeCache->add(ctu);
 
1558
    }
 
1559
  }
 
1560
  unlockGlobalParams;
 
1561
  return ctu;
 
1562
}
 
1563
 
 
1564
UnicodeMap *GlobalParams::getUnicodeMap(GooString *encodingName) {
 
1565
  return getUnicodeMap2(encodingName);
 
1566
}
 
1567
 
 
1568
UnicodeMap *GlobalParams::getUnicodeMap2(GooString *encodingName) {
 
1569
  UnicodeMap *map;
 
1570
 
 
1571
  if (!(map = getResidentUnicodeMap(encodingName))) {
 
1572
    lockUnicodeMapCache;
 
1573
    map = unicodeMapCache->getUnicodeMap(encodingName);
 
1574
    unlockUnicodeMapCache;
 
1575
  }
 
1576
  return map;
 
1577
}
 
1578
 
 
1579
CMap *GlobalParams::getCMap(GooString *collection, GooString *cMapName, Stream *stream) {
 
1580
  CMap *cMap;
 
1581
 
 
1582
  lockCMapCache;
 
1583
  cMap = cMapCache->getCMap(collection, cMapName, stream);
 
1584
  unlockCMapCache;
 
1585
  return cMap;
 
1586
}
 
1587
 
 
1588
UnicodeMap *GlobalParams::getTextEncoding() {
 
1589
  return getUnicodeMap2(textEncoding);
 
1590
}
 
1591
 
 
1592
GooList *GlobalParams::getEncodingNames()
 
1593
{
 
1594
  GooList *result = new GooList;
 
1595
  GooHashIter *iter;
 
1596
  GooString *key;
 
1597
  void *val;
 
1598
  residentUnicodeMaps->startIter(&iter);
 
1599
  while (residentUnicodeMaps->getNext(&iter, &key, &val)) {
 
1600
    result->append(key);
 
1601
  }
 
1602
  residentUnicodeMaps->killIter(&iter);
 
1603
  unicodeMaps->startIter(&iter);
 
1604
  while (unicodeMaps->getNext(&iter, &key, &val)) {
 
1605
    result->append(key);
 
1606
  }
 
1607
  unicodeMaps->killIter(&iter);
 
1608
  return result;
 
1609
}
 
1610
 
 
1611
//------------------------------------------------------------------------
 
1612
// functions to set parameters
 
1613
//------------------------------------------------------------------------
 
1614
 
 
1615
void GlobalParams::setPSExpandSmaller(GBool expand) {
 
1616
  lockGlobalParams;
 
1617
  psExpandSmaller = expand;
 
1618
  unlockGlobalParams;
 
1619
}
 
1620
 
 
1621
void GlobalParams::setPSShrinkLarger(GBool shrink) {
 
1622
  lockGlobalParams;
 
1623
  psShrinkLarger = shrink;
 
1624
  unlockGlobalParams;
 
1625
}
 
1626
 
 
1627
void GlobalParams::setPSCenter(GBool center) {
 
1628
  lockGlobalParams;
 
1629
  psCenter = center;
 
1630
  unlockGlobalParams;
 
1631
}
 
1632
 
 
1633
void GlobalParams::setPSLevel(PSLevel level) {
 
1634
  lockGlobalParams;
 
1635
  psLevel = level;
 
1636
  unlockGlobalParams;
 
1637
}
 
1638
 
 
1639
void GlobalParams::setPSEmbedType1(GBool embed) {
 
1640
  lockGlobalParams;
 
1641
  psEmbedType1 = embed;
 
1642
  unlockGlobalParams;
 
1643
}
 
1644
 
 
1645
void GlobalParams::setPSEmbedTrueType(GBool embed) {
 
1646
  lockGlobalParams;
 
1647
  psEmbedTrueType = embed;
 
1648
  unlockGlobalParams;
 
1649
}
 
1650
 
 
1651
void GlobalParams::setPSEmbedCIDPostScript(GBool embed) {
 
1652
  lockGlobalParams;
 
1653
  psEmbedCIDPostScript = embed;
 
1654
  unlockGlobalParams;
 
1655
}
 
1656
 
 
1657
void GlobalParams::setPSEmbedCIDTrueType(GBool embed) {
 
1658
  lockGlobalParams;
 
1659
  psEmbedCIDTrueType = embed;
 
1660
  unlockGlobalParams;
 
1661
}
 
1662
 
 
1663
void GlobalParams::setPSSubstFonts(GBool substFonts) {
 
1664
  lockGlobalParams;
 
1665
  psSubstFonts = substFonts;
 
1666
  unlockGlobalParams;
 
1667
}
 
1668
 
 
1669
void GlobalParams::setPSPreload(GBool preload) {
 
1670
  lockGlobalParams;
 
1671
  psPreload = preload;
 
1672
  unlockGlobalParams;
 
1673
}
 
1674
 
 
1675
void GlobalParams::setPSOPI(GBool opi) {
 
1676
  lockGlobalParams;
 
1677
  psOPI = opi;
 
1678
  unlockGlobalParams;
 
1679
}
 
1680
 
 
1681
void GlobalParams::setPSASCIIHex(GBool hex) {
 
1682
  lockGlobalParams;
 
1683
  psASCIIHex = hex;
 
1684
  unlockGlobalParams;
 
1685
}
 
1686
 
 
1687
void GlobalParams::setTextEncoding(char *encodingName) {
 
1688
  lockGlobalParams;
 
1689
  delete textEncoding;
 
1690
  textEncoding = new GooString(encodingName);
 
1691
  unlockGlobalParams;
 
1692
}
 
1693
 
 
1694
GBool GlobalParams::setTextEOL(char *s) {
 
1695
  lockGlobalParams;
 
1696
  if (!strcmp(s, "unix")) {
 
1697
    textEOL = eolUnix;
 
1698
  } else if (!strcmp(s, "dos")) {
 
1699
    textEOL = eolDOS;
 
1700
  } else if (!strcmp(s, "mac")) {
 
1701
    textEOL = eolMac;
 
1702
  } else {
 
1703
    unlockGlobalParams;
 
1704
    return gFalse;
 
1705
  }
 
1706
  unlockGlobalParams;
 
1707
  return gTrue;
 
1708
}
 
1709
 
 
1710
void GlobalParams::setTextPageBreaks(GBool pageBreaks) {
 
1711
  lockGlobalParams;
 
1712
  textPageBreaks = pageBreaks;
 
1713
  unlockGlobalParams;
 
1714
}
 
1715
 
 
1716
void GlobalParams::setTextKeepTinyChars(GBool keep) {
 
1717
  lockGlobalParams;
 
1718
  textKeepTinyChars = keep;
 
1719
  unlockGlobalParams;
 
1720
}
 
1721
 
 
1722
GBool GlobalParams::setEnableFreeType(char *s) {
 
1723
  GBool ok;
 
1724
 
 
1725
  lockGlobalParams;
 
1726
  ok = parseYesNo2(s, &enableFreeType);
 
1727
  unlockGlobalParams;
 
1728
  return ok;
 
1729
}
 
1730
 
 
1731
 
 
1732
GBool GlobalParams::setAntialias(char *s) {
 
1733
  GBool ok;
 
1734
 
 
1735
  lockGlobalParams;
 
1736
  ok = parseYesNo2(s, &antialias);
 
1737
  unlockGlobalParams;
 
1738
  return ok;
 
1739
}
 
1740
 
 
1741
GBool GlobalParams::setVectorAntialias(char *s) {
 
1742
  GBool ok;
 
1743
 
 
1744
  lockGlobalParams;
 
1745
  ok = parseYesNo2(s, &vectorAntialias);
 
1746
  unlockGlobalParams;
 
1747
  return ok;
 
1748
}
 
1749
 
 
1750
void GlobalParams::setStrokeAdjust(GBool adjust)
 
1751
{
 
1752
  lockGlobalParams;
 
1753
  strokeAdjust = adjust;
 
1754
  unlockGlobalParams;
 
1755
}
 
1756
 
 
1757
void GlobalParams::setScreenType(ScreenType st)
 
1758
{
 
1759
  lockGlobalParams;
 
1760
  screenType = st;
 
1761
  unlockGlobalParams;
 
1762
}
 
1763
 
 
1764
void GlobalParams::setScreenSize(int size)
 
1765
{
 
1766
  lockGlobalParams;
 
1767
  screenSize = size;
 
1768
  unlockGlobalParams;
 
1769
}
 
1770
 
 
1771
void GlobalParams::setScreenDotRadius(int radius)
 
1772
{
 
1773
  lockGlobalParams;
 
1774
  screenDotRadius = radius;
 
1775
  unlockGlobalParams;
 
1776
}
 
1777
 
 
1778
void GlobalParams::setScreenGamma(double gamma)
 
1779
{
 
1780
  lockGlobalParams;
 
1781
  screenGamma = gamma;
 
1782
  unlockGlobalParams;
 
1783
}
 
1784
 
 
1785
void GlobalParams::setScreenBlackThreshold(double blackThreshold)
 
1786
{
 
1787
  lockGlobalParams;
 
1788
  screenBlackThreshold = blackThreshold;
 
1789
  unlockGlobalParams;
 
1790
}
 
1791
 
 
1792
void GlobalParams::setScreenWhiteThreshold(double whiteThreshold)
 
1793
{
 
1794
  lockGlobalParams;
 
1795
  screenWhiteThreshold = whiteThreshold;
 
1796
  unlockGlobalParams;
 
1797
}
 
1798
 
 
1799
void GlobalParams::setMapNumericCharNames(GBool map) {
 
1800
  lockGlobalParams;
 
1801
  mapNumericCharNames = map;
 
1802
  unlockGlobalParams;
 
1803
}
 
1804
 
 
1805
void GlobalParams::setMapUnknownCharNames(GBool map) {
 
1806
  lockGlobalParams;
 
1807
  mapUnknownCharNames = map;
 
1808
  unlockGlobalParams;
 
1809
}
 
1810
 
 
1811
void GlobalParams::setPrintCommands(GBool printCommandsA) {
 
1812
  lockGlobalParams;
 
1813
  printCommands = printCommandsA;
 
1814
  unlockGlobalParams;
 
1815
}
 
1816
 
 
1817
void GlobalParams::setProfileCommands(GBool profileCommandsA) {
 
1818
  lockGlobalParams;
 
1819
  profileCommands = profileCommandsA;
 
1820
  unlockGlobalParams;
 
1821
}
 
1822
 
 
1823
void GlobalParams::setErrQuiet(GBool errQuietA) {
 
1824
  lockGlobalParams;
 
1825
  errQuiet = errQuietA;
 
1826
  unlockGlobalParams;
 
1827
}
 
1828
 
 
1829
void GlobalParams::addSecurityHandler(XpdfSecurityHandler *handler) {
 
1830
#ifdef ENABLE_PLUGINS
 
1831
  lockGlobalParams;
 
1832
  securityHandlers->append(handler);
 
1833
  unlockGlobalParams;
 
1834
#endif
 
1835
}
 
1836
 
 
1837
XpdfSecurityHandler *GlobalParams::getSecurityHandler(char *name) {
 
1838
#ifdef ENABLE_PLUGINS
 
1839
  XpdfSecurityHandler *hdlr;
 
1840
  int i;
 
1841
 
 
1842
  lockGlobalParams;
 
1843
  for (i = 0; i < securityHandlers->getLength(); ++i) {
 
1844
    hdlr = (XpdfSecurityHandler *)securityHandlers->get(i);
 
1845
    if (!strcasecmp(hdlr->name, name)) {
 
1846
      unlockGlobalParams;
 
1847
      return hdlr;
 
1848
    }
 
1849
  }
 
1850
  unlockGlobalParams;
 
1851
 
 
1852
  if (!loadPlugin("security", name)) {
 
1853
    return NULL;
 
1854
  }
 
1855
  deleteGooList(keyBindings, KeyBinding);
 
1856
 
 
1857
  lockGlobalParams;
 
1858
  for (i = 0; i < securityHandlers->getLength(); ++i) {
 
1859
    hdlr = (XpdfSecurityHandler *)securityHandlers->get(i);
 
1860
    if (!strcmp(hdlr->name, name)) {
 
1861
      unlockGlobalParams;
 
1862
      return hdlr;
 
1863
    }
 
1864
  }
 
1865
  unlockGlobalParams;
 
1866
#else
 
1867
  (void)name;
 
1868
#endif
 
1869
 
 
1870
  return NULL;
 
1871
}
 
1872
 
 
1873
#ifdef ENABLE_PLUGINS
 
1874
//------------------------------------------------------------------------
 
1875
// plugins
 
1876
//------------------------------------------------------------------------
 
1877
 
 
1878
GBool GlobalParams::loadPlugin(char *type, char *name) {
 
1879
  Plugin *plugin;
 
1880
 
 
1881
  if (!(plugin = Plugin::load(type, name))) {
 
1882
    return gFalse;
 
1883
  }
 
1884
  lockGlobalParams;
 
1885
  plugins->append(plugin);
 
1886
  unlockGlobalParams;
 
1887
  return gTrue;
 
1888
}
 
1889
 
 
1890
#endif // ENABLE_PLUGINS