GlobalParams.cc 43.8 KB
Newer Older
1
2
3
4
//========================================================================
//
// GlobalParams.cc
//
5
// Copyright 2001-2003 Glyph & Cog, LLC
6
7
8
//
//========================================================================

Wilco Greven's avatar
Wilco Greven committed
9
10
11
#include <aconf.h>

#ifdef USE_GCC_PRAGMAS
12
13
14
15
#pragma implementation
#endif

#include <string.h>
16
17
18
19
// KPDF: additional includes for Qt and Xft
#include <qstring.h>
#include <qregexp.h>
#include <qwindowdefs.h>
20
21
22
23
24
// -- gentoo compile fix (XFree 4.3.0, FC 2.2.3, FreeType 2.1.9) --
// on other distros these 2 lines should't harm
#include <ft2build.h>
#include FT_FREETYPE_H
// -- ---------------------------------------------------------- --
25
26
#include <X11/Xft/Xft.h>
#include <X11/Xft/XftCompat.h>
27
#include <stdio.h>
28
#include <ctype.h>
29
#if HAVE_PAPER_H
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <paper.h>
#endif
#include "gmem.h"
#include "GString.h"
#include "GList.h"
#include "GHash.h"
#include "gfile.h"
#include "Error.h"
#include "NameToCharCode.h"
#include "CharCodeToUnicode.h"
#include "UnicodeMap.h"
#include "CMap.h"
#include "BuiltinFontTables.h"
#include "FontEncodingTables.h"
#include "GlobalParams.h"

46
47
48
49
50
51
52
#if MULTITHREADED
#  define lockGlobalParams            gLockMutex(&mutex)
#  define lockUnicodeMapCache         gLockMutex(&unicodeMapCacheMutex)
#  define lockCMapCache               gLockMutex(&cMapCacheMutex)
#  define unlockGlobalParams          gUnlockMutex(&mutex)
#  define unlockUnicodeMapCache       gUnlockMutex(&unicodeMapCacheMutex)
#  define unlockCMapCache             gUnlockMutex(&cMapCacheMutex)
53
#else
54
55
56
57
58
59
#  define lockGlobalParams
#  define lockUnicodeMapCache
#  define lockCMapCache
#  define unlockGlobalParams
#  define unlockUnicodeMapCache
#  define unlockCMapCache
60
61
#endif

62
63
64
65
66
67
#include "NameToUnicodeTable.h"
#include "UnicodeMapTables.h"
#include "UTF8.h"

//------------------------------------------------------------------------

68
69
70
71
72
73
#define cidToUnicodeCacheSize     4
#define unicodeToUnicodeCacheSize 4

//------------------------------------------------------------------------

static struct {
74
75
  const char *name;
  const char *fileName;
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
} displayFontTab[] = {
  {"Courier",               "n022003l.pfb"},
  {"Courier-Bold",          "n022004l.pfb"},
  {"Courier-BoldOblique",   "n022024l.pfb"},
  {"Courier-Oblique",       "n022023l.pfb"},
  {"Helvetica",             "n019003l.pfb"},
  {"Helvetica-Bold",        "n019004l.pfb"},
  {"Helvetica-BoldOblique", "n019024l.pfb"},
  {"Helvetica-Oblique",     "n019023l.pfb"},
  {"Symbol",                "s050000l.pfb"},
  {"Times-Bold",            "n021004l.pfb"},
  {"Times-BoldItalic",      "n021024l.pfb"},
  {"Times-Italic",          "n021023l.pfb"},
  {"Times-Roman",           "n021003l.pfb"},
  {"ZapfDingbats",          "d050000l.pfb"},
91
  {NULL, NULL}
92
93
};

94
95
// KPDF: removed hardcoded font directories, Xft handles searching
/*static const char *displayFontDirs[] = {
96
97
98
  "/usr/share/ghostscript/fonts",
  "/usr/local/share/ghostscript/fonts",
  "/usr/share/fonts/default/Type1",
99
  "/usr/share/fonts/type1/gsfonts",
100
  "/usr/share/fonts/default/ghostscript/",
101
  NULL
102
103
};*/

104
105
106

//------------------------------------------------------------------------

107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
GlobalParams *globalParams = NULL;

//------------------------------------------------------------------------
// DisplayFontParam
//------------------------------------------------------------------------

DisplayFontParam::DisplayFontParam(GString *nameA,
				   DisplayFontParamKind kindA) {
  name = nameA;
  kind = kindA;
  switch (kind) {
  case displayFontT1:
    t1.fileName = NULL;
    break;
  case displayFontTT:
    tt.fileName = NULL;
    break;
  }
}

DisplayFontParam::~DisplayFontParam() {
  delete name;
  switch (kind) {
  case displayFontT1:
    if (t1.fileName) {
      delete t1.fileName;
    }
    break;
  case displayFontTT:
    if (tt.fileName) {
      delete tt.fileName;
    }
    break;
  }
}

//------------------------------------------------------------------------
// PSFontParam
//------------------------------------------------------------------------

PSFontParam::PSFontParam(GString *pdfFontNameA, int wModeA,
			 GString *psFontNameA, GString *encodingA) {
  pdfFontName = pdfFontNameA;
  wMode = wModeA;
  psFontName = psFontNameA;
  encoding = encodingA;
}

PSFontParam::~PSFontParam() {
  delete pdfFontName;
  delete psFontName;
  if (encoding) {
    delete encoding;
  }
}

//------------------------------------------------------------------------
// parsing
//------------------------------------------------------------------------

167
GlobalParams::GlobalParams(const char *cfgFileName) {
168
169
170
171
172
  UnicodeMap *map;
  GString *fileName;
  FILE *f;
  int i;

173
#if MULTITHREADED
174
  gInitMutex(&mutex);
175
176
  gInitMutex(&unicodeMapCacheMutex);
  gInitMutex(&cMapCacheMutex);
177
178
#endif

179
180
181
182
183
184
185
186
187
188
189
190
191
  initBuiltinFontTables();

  // scan the encoding in reverse because we want the lowest-numbered
  // index for each char name ('space' is encoded twice)
  macRomanReverseMap = new NameToCharCode();
  for (i = 255; i >= 0; --i) {
    if (macRomanEncoding[i]) {
      macRomanReverseMap->add(macRomanEncoding[i], (CharCode)i);
    }
  }

  nameToUnicode = new NameToCharCode();
  cidToUnicodes = new GHash(gTrue);
192
  unicodeToUnicodes = new GHash(gTrue);
193
194
195
196
197
198
199
  residentUnicodeMaps = new GHash();
  unicodeMaps = new GHash(gTrue);
  cMapDirs = new GHash(gTrue);
  toUnicodeDirs = new GList();
  displayFonts = new GHash();
  displayCIDFonts = new GHash();
  displayNamedCIDFonts = new GHash();
200
#if HAVE_PAPER_H
Wilco Greven's avatar
Wilco Greven committed
201
  char *paperName;
202
203
  const struct paper *paperType;
  paperinit();
Wilco Greven's avatar
Wilco Greven committed
204
205
  if ((paperName = systempapername())) {
    paperType = paperinfo(paperName);
206
207
    psPaperWidth = (int)paperpswidth(paperType);
    psPaperHeight = (int)paperpsheight(paperType);
Wilco Greven's avatar
Wilco Greven committed
208
209
210
211
212
  } else {
    error(-1, "No paper information available - using defaults");
    psPaperWidth = defPaperWidth;
    psPaperHeight = defPaperHeight;
  }
213
214
215
216
217
  paperdone();
#else
  psPaperWidth = defPaperWidth;
  psPaperHeight = defPaperHeight;
#endif
218
219
220
221
222
223
224
  psImageableLLX = psImageableLLY = 0;
  psImageableURX = psPaperWidth;
  psImageableURY = psPaperHeight;
  psCrop = gTrue;
  psExpandSmaller = gFalse;
  psShrinkLarger = gTrue;
  psCenter = gTrue;
225
226
227
228
229
230
231
232
233
234
235
236
  psDuplex = gFalse;
  psLevel = psLevel2;
  psFile = NULL;
  psFonts = new GHash();
  psNamedFonts16 = new GList();
  psFonts16 = new GList();
  psEmbedType1 = gTrue;
  psEmbedTrueType = gTrue;
  psEmbedCIDPostScript = gTrue;
  psEmbedCIDTrueType = gTrue;
  psOPI = gFalse;
  psASCIIHex = gFalse;
237
  // KPDF: use always UTF-8 and QString::fromUtf 
238
  textEncoding = new GString("UTF-8");
239
240
241
242
243
244
245
#if defined(WIN32)
  textEOL = eolDOS;
#elif defined(MACOS)
  textEOL = eolMac;
#else
  textEOL = eolUnix;
#endif
246
  textPageBreaks = gTrue;
Wilco Greven's avatar
Wilco Greven committed
247
  textKeepTinyChars = gFalse;
248
  fontDirs = new GList();
249
250
251
252
  initialZoom = new GString("125");
  enableT1lib = gTrue;
  enableFreeType = gTrue;
  antialias = gTrue;
253
  urlCommand = NULL;
Wilco Greven's avatar
Wilco Greven committed
254
  movieCommand = NULL;
255
  mapNumericCharNames = gTrue;
Wilco Greven's avatar
Wilco Greven committed
256
  printCommands = gFalse;
257
258
  errQuiet = gFalse;

259
260
261
  cidToUnicodeCache = new CharCodeToUnicodeCache(cidToUnicodeCacheSize);
  unicodeToUnicodeCache =
      new CharCodeToUnicodeCache(unicodeToUnicodeCacheSize);
262
263
264
265
266
267
268
269
270
  unicodeMapCache = new UnicodeMapCache();
  cMapCache = new CMapCache();

  // set up the initial nameToUnicode table
  for (i = 0; nameToUnicodeTab[i].name; ++i) {
    nameToUnicode->add(nameToUnicodeTab[i].name, nameToUnicodeTab[i].u);
  }

  // set up the residentUnicodeMaps table
Wilco Greven's avatar
Wilco Greven committed
271
272
  map = new UnicodeMap("Latin1", gFalse,
		       latin1UnicodeMapRanges, latin1UnicodeMapLen);
273
  residentUnicodeMaps->add(map->getEncodingName(), map);
Wilco Greven's avatar
Wilco Greven committed
274
275
  map = new UnicodeMap("ASCII7", gFalse,
		       ascii7UnicodeMapRanges, ascii7UnicodeMapLen);
276
  residentUnicodeMaps->add(map->getEncodingName(), map);
Wilco Greven's avatar
Wilco Greven committed
277
278
  map = new UnicodeMap("Symbol", gFalse,
		       symbolUnicodeMapRanges, symbolUnicodeMapLen);
279
  residentUnicodeMaps->add(map->getEncodingName(), map);
Wilco Greven's avatar
Wilco Greven committed
280
  map = new UnicodeMap("ZapfDingbats", gFalse, zapfDingbatsUnicodeMapRanges,
281
282
		       zapfDingbatsUnicodeMapLen);
  residentUnicodeMaps->add(map->getEncodingName(), map);
Wilco Greven's avatar
Wilco Greven committed
283
  map = new UnicodeMap("UTF-8", gTrue, &mapUTF8);
284
  residentUnicodeMaps->add(map->getEncodingName(), map);
Wilco Greven's avatar
Wilco Greven committed
285
  map = new UnicodeMap("UCS-2", gTrue, &mapUCS2);
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
  residentUnicodeMaps->add(map->getEncodingName(), map);

  // look for a user config file, then a system-wide config file
  f = NULL;
  fileName = NULL;
  if (cfgFileName && cfgFileName[0]) {
    fileName = new GString(cfgFileName);
    if (!(f = fopen(fileName->getCString(), "r"))) {
      delete fileName;
    }
  }
  if (!f) {
    fileName = appendToPath(getHomeDir(), xpdfUserConfigFile);
    if (!(f = fopen(fileName->getCString(), "r"))) {
      delete fileName;
    }
  }
  if (!f) {
#if defined(WIN32) && !defined(__CYGWIN32__)
    char buf[512];
    i = GetModuleFileName(NULL, buf, sizeof(buf));
    if (i <= 0 || i >= sizeof(buf)) {
      // error or path too long for buffer - just use the current dir
Wilco Greven's avatar
Wilco Greven committed
309
      buf[0] = '\0';
310
311
312
313
314
315
316
317
318
319
320
321
322
    }
    fileName = grabPath(buf);
    appendToPath(fileName, xpdfSysConfigFile);
#else
    fileName = new GString(xpdfSysConfigFile);
#endif
    if (!(f = fopen(fileName->getCString(), "r"))) {
      delete fileName;
    }
  }
  if (f) {
    parseFile(fileName, f);
    delete fileName;
Wilco Greven's avatar
Wilco Greven committed
323
    fclose(f);
324
325
326
327
328
329
330
331
332
333
334
335
  }
}

void GlobalParams::parseFile(GString *fileName, FILE *f) {
  int line;
  GList *tokens;
  GString *cmd, *incFile;
  char *p1, *p2;
  char buf[512];
  FILE *f2;

  line = 1;
336
  while (getLine(buf, sizeof(buf) - 1, f)) {
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352

    // break the line into tokens
    tokens = new GList();
    p1 = buf;
    while (*p1) {
      for (; *p1 && isspace(*p1); ++p1) ;
      if (!*p1) {
	break;
      }
      if (*p1 == '"' || *p1 == '\'') {
	for (p2 = p1 + 1; *p2 && *p2 != *p1; ++p2) ;
	++p1;
      } else {
	for (p2 = p1 + 1; *p2 && !isspace(*p2); ++p2) ;
      }
      tokens->append(new GString(p1, p2 - p1));
353
      p1 = *p2 ? p2 + 1 : p2;
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
    }

    if (tokens->getLength() > 0 &&
	((GString *)tokens->get(0))->getChar(0) != '#') {
      cmd = (GString *)tokens->get(0);
      if (!cmd->cmp("include")) {
	if (tokens->getLength() == 2) {
	  incFile = (GString *)tokens->get(1);
	  if ((f2 = fopen(incFile->getCString(), "r"))) {
	    parseFile(incFile, f2);
	    fclose(f2);
	  } else {
	    error(-1, "Couldn't find included config file: '%s' (%s:%d)",
		  incFile->getCString(), fileName->getCString(), line);
	  }
	} else {
	  error(-1, "Bad 'include' config file command (%s:%d)",
		fileName->getCString(), line);
	}
      } else if (!cmd->cmp("nameToUnicode")) {
	parseNameToUnicode(tokens, fileName, line);
      } else if (!cmd->cmp("cidToUnicode")) {
	parseCIDToUnicode(tokens, fileName, line);
377
378
      } else if (!cmd->cmp("unicodeToUnicode")) {
	parseUnicodeToUnicode(tokens, fileName, line);
379
380
381
382
383
384
      } else if (!cmd->cmp("unicodeMap")) {
	parseUnicodeMap(tokens, fileName, line);
      } else if (!cmd->cmp("cMapDir")) {
	parseCMapDir(tokens, fileName, line);
      } else if (!cmd->cmp("toUnicodeDir")) {
	parseToUnicodeDir(tokens, fileName, line);
385
      // KPDF: finding T1 and TTF fonts is handled by Xft now
386
      } else if (!cmd->cmp("displayFontT1")) {
387
//	parseDisplayFont(tokens, displayFonts, displayFontT1, fileName, line);
388
      } else if (!cmd->cmp("displayFontTT")) {
389
//	parseDisplayFont(tokens, displayFonts, displayFontTT, fileName, line);
390
      } else if (!cmd->cmp("displayNamedCIDFontT1")) {
391
	parseDisplayFont(tokens, displayNamedCIDFonts,
392
393
394
395
396
397
398
399
400
401
			 displayFontT1, fileName, line);
      } else if (!cmd->cmp("displayCIDFontT1")) {
	parseDisplayFont(tokens, displayCIDFonts,
			 displayFontT1, fileName, line);
      } else if (!cmd->cmp("displayNamedCIDFontTT")) {
	parseDisplayFont(tokens, displayNamedCIDFonts,
			 displayFontTT, fileName, line);
      } else if (!cmd->cmp("displayCIDFontTT")) {
	parseDisplayFont(tokens, displayCIDFonts,
			 displayFontTT, fileName, line);
402
403
404
405
406
407
408
409
410
411
412
      } else if (!cmd->cmp("psFile")) {
	parsePSFile(tokens, fileName, line);
      } else if (!cmd->cmp("psFont")) {
	parsePSFont(tokens, fileName, line);
      } else if (!cmd->cmp("psNamedFont16")) {
	parsePSFont16("psNamedFont16", psNamedFonts16,
		      tokens, fileName, line);
      } else if (!cmd->cmp("psFont16")) {
	parsePSFont16("psFont16", psFonts16, tokens, fileName, line);
      } else if (!cmd->cmp("psPaperSize")) {
	parsePSPaperSize(tokens, fileName, line);
413
414
415
416
417
418
419
420
421
422
423
      } else if (!cmd->cmp("psImageableArea")) {
	parsePSImageableArea(tokens, fileName, line);
      } else if (!cmd->cmp("psCrop")) {
	parseYesNo("psCrop", &psCrop, tokens, fileName, line);
      } else if (!cmd->cmp("psExpandSmaller")) {
	parseYesNo("psExpandSmaller", &psExpandSmaller,
		   tokens, fileName, line);
      } else if (!cmd->cmp("psShrinkLarger")) {
	parseYesNo("psShrinkLarger", &psShrinkLarger, tokens, fileName, line);
      } else if (!cmd->cmp("psCenter")) {
	parseYesNo("psCenter", &psCenter, tokens, fileName, line);
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
      } else if (!cmd->cmp("psDuplex")) {
	parseYesNo("psDuplex", &psDuplex, tokens, fileName, line);
      } else if (!cmd->cmp("psLevel")) {
	parsePSLevel(tokens, fileName, line);
      } else if (!cmd->cmp("psEmbedType1Fonts")) {
	parseYesNo("psEmbedType1", &psEmbedType1, tokens, fileName, line);
      } else if (!cmd->cmp("psEmbedTrueTypeFonts")) {
	parseYesNo("psEmbedTrueType", &psEmbedTrueType,
		   tokens, fileName, line);
      } else if (!cmd->cmp("psEmbedCIDPostScriptFonts")) {
	parseYesNo("psEmbedCIDPostScript", &psEmbedCIDPostScript,
		   tokens, fileName, line);
      } else if (!cmd->cmp("psEmbedCIDTrueTypeFonts")) {
	parseYesNo("psEmbedCIDTrueType", &psEmbedCIDTrueType,
		   tokens, fileName, line);
      } else if (!cmd->cmp("psOPI")) {
	parseYesNo("psOPI", &psOPI, tokens, fileName, line);
      } else if (!cmd->cmp("psASCIIHex")) {
	parseYesNo("psASCIIHex", &psASCIIHex, tokens, fileName, line);
443
      } else if (!cmd->cmp("textEncoding")) {          
444
445
//	Always use UTF-8 and allow QString do the magic
//	parseTextEncoding(tokens, fileName, line);
446
447
      } else if (!cmd->cmp("textEOL")) {
	parseTextEOL(tokens, fileName, line);
448
449
450
      } else if (!cmd->cmp("textPageBreaks")) {
	parseYesNo("textPageBreaks", &textPageBreaks,
		   tokens, fileName, line);
Wilco Greven's avatar
Wilco Greven committed
451
452
453
      } else if (!cmd->cmp("textKeepTinyChars")) {
	parseYesNo("textKeepTinyChars", &textKeepTinyChars,
		   tokens, fileName, line);
454
455
456
457
      } else if (!cmd->cmp("fontDir")) {
	parseFontDir(tokens, fileName, line);
      } else if (!cmd->cmp("initialZoom")) {
	parseInitialZoom(tokens, fileName, line);
458
459
460
461
462
463
      } else if (!cmd->cmp("enableT1lib")) {
	parseYesNo("enableT1lib", &enableT1lib, tokens, fileName, line);
      } else if (!cmd->cmp("enableFreeType")) {
	parseYesNo("enableFreeType", &enableFreeType, tokens, fileName, line);
      } else if (!cmd->cmp("antialias")) {
	parseYesNo("antialias", &antialias, tokens, fileName, line);
464
      } else if (!cmd->cmp("urlCommand")) {
Wilco Greven's avatar
Wilco Greven committed
465
466
467
	parseCommand("urlCommand", &urlCommand, tokens, fileName, line);
      } else if (!cmd->cmp("movieCommand")) {
	parseCommand("movieCommand", &movieCommand, tokens, fileName, line);
468
469
470
      } else if (!cmd->cmp("mapNumericCharNames")) {
	parseYesNo("mapNumericCharNames", &mapNumericCharNames,
		   tokens, fileName, line);
Wilco Greven's avatar
Wilco Greven committed
471
472
      } else if (!cmd->cmp("printCommands")) {
	parseYesNo("printCommands", &printCommands, tokens, fileName, line);
473
474
475
476
477
      } else if (!cmd->cmp("errQuiet")) {
	parseYesNo("errQuiet", &errQuiet, tokens, fileName, line);
      } else {
	error(-1, "Unknown config file command '%s' (%s:%d)",
	      cmd->getCString(), fileName->getCString(), line);
478
479
480
481
482
483
484
485
486
487
	if (!cmd->cmp("displayFontX") ||
	    !cmd->cmp("displayNamedCIDFontX") ||
	    !cmd->cmp("displayCIDFontX")) {
	  error(-1, "-- Xpdf no longer supports X fonts");
	} else if (!cmd->cmp("t1libControl") || !cmd->cmp("freetypeControl")) {
	  error(-1, "-- The t1libControl and freetypeControl options have been replaced");
	  error(-1, "   by the enableT1lib, enableFreeType, and antialias options");
	} else if (!cmd->cmp("fontpath") || !cmd->cmp("fontmap")) {
	  error(-1, "-- the config file format has changed since Xpdf 0.9x");
	}
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
      }
    }

    deleteGList(tokens, GString);
    ++line;
  }
}

void GlobalParams::parseNameToUnicode(GList *tokens, GString *fileName,
					 int line) {
  GString *name;
  char *tok1, *tok2;
  FILE *f;
  char buf[256];
  int line2;
  Unicode u;

  if (tokens->getLength() != 2) {
    error(-1, "Bad 'nameToUnicode' config file command (%s:%d)",
	  fileName->getCString(), line);
    return;
  }
  name = (GString *)tokens->get(1);
  if (!(f = fopen(name->getCString(), "r"))) {
    error(-1, "Couldn't open 'nameToUnicode' file '%s'",
	  name->getCString());
    return;
  }
  line2 = 1;
517
  while (getLine(buf, sizeof(buf), f)) {
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
    tok1 = strtok(buf, " \t\r\n");
    tok2 = strtok(NULL, " \t\r\n");
    if (tok1 && tok2) {
      sscanf(tok1, "%x", &u);
      nameToUnicode->add(tok2, u);
    } else {
      error(-1, "Bad line in 'nameToUnicode' file (%s:%d)", name, line2);
    }
    ++line2;
  }
  fclose(f);
}

void GlobalParams::parseCIDToUnicode(GList *tokens, GString *fileName,
				     int line) {
  GString *collection, *name, *old;

  if (tokens->getLength() != 3) {
    error(-1, "Bad 'cidToUnicode' config file command (%s:%d)",
	  fileName->getCString(), line);
    return;
  }
  collection = (GString *)tokens->get(1);
  name = (GString *)tokens->get(2);
  if ((old = (GString *)cidToUnicodes->remove(collection))) {
    delete old;
  }
  cidToUnicodes->add(collection->copy(), name->copy());
}

548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
void GlobalParams::parseUnicodeToUnicode(GList *tokens, GString *fileName,
					 int line) {
  GString *font, *file, *old;

  if (tokens->getLength() != 3) {
    error(-1, "Bad 'unicodeToUnicode' config file command (%s:%d)",
	  fileName->getCString(), line);
    return;
  }
  font = (GString *)tokens->get(1);
  file = (GString *)tokens->get(2);
  if ((old = (GString *)unicodeToUnicodes->remove(font))) {
    delete old;
  }
  unicodeToUnicodes->add(font->copy(), file->copy());
}

565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
void GlobalParams::parseUnicodeMap(GList *tokens, GString *fileName,
				   int line) {
  GString *encodingName, *name, *old;

  if (tokens->getLength() != 3) {
    error(-1, "Bad 'unicodeMap' config file command (%s:%d)",
	  fileName->getCString(), line);
    return;
  }
  encodingName = (GString *)tokens->get(1);
  name = (GString *)tokens->get(2);
  if ((old = (GString *)unicodeMaps->remove(encodingName))) {
    delete old;
  }
  unicodeMaps->add(encodingName->copy(), name->copy());
}

void GlobalParams::parseCMapDir(GList *tokens, GString *fileName, int line) {
  GString *collection, *dir;
  GList *list;

  if (tokens->getLength() != 3) {
    error(-1, "Bad 'cMapDir' config file command (%s:%d)",
	  fileName->getCString(), line);
    return;
  }
  collection = (GString *)tokens->get(1);
  dir = (GString *)tokens->get(2);
  if (!(list = (GList *)cMapDirs->lookup(collection))) {
    list = new GList();
    cMapDirs->add(collection->copy(), list);
  }
  list->append(dir->copy());
}

void GlobalParams::parseToUnicodeDir(GList *tokens, GString *fileName,
				     int line) {
  if (tokens->getLength() != 2) {
    error(-1, "Bad 'toUnicodeDir' config file command (%s:%d)",
	  fileName->getCString(), line);
    return;
  }
  toUnicodeDirs->append(((GString *)tokens->get(1))->copy());
}

void GlobalParams::parseDisplayFont(GList *tokens, GHash *fontHash,
				    DisplayFontParamKind kind,
				    GString *fileName, int line) {
  DisplayFontParam *param, *old;

  if (tokens->getLength() < 2) {
    goto err1;
  }
  param = new DisplayFontParam(((GString *)tokens->get(1))->copy(), kind);
619
  
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
  switch (kind) {
  case displayFontT1:
    if (tokens->getLength() != 3) {
      goto err2;
    }
    param->t1.fileName = ((GString *)tokens->get(2))->copy();
    break;
  case displayFontTT:
    if (tokens->getLength() != 3) {
      goto err2;
    }
    param->tt.fileName = ((GString *)tokens->get(2))->copy();
    break;
  }

  if ((old = (DisplayFontParam *)fontHash->remove(param->name))) {
    delete old;
  }
  fontHash->add(param->name, param);
  return;

 err2:
  delete param;
 err1:
  error(-1, "Bad 'display*Font*' config file command (%s:%d)",
	fileName->getCString(), line);
}

void GlobalParams::parsePSPaperSize(GList *tokens, GString *fileName,
				    int line) {
  GString *tok;

  if (tokens->getLength() == 2) {
    tok = (GString *)tokens->get(1);
    if (!setPSPaperSize(tok->getCString())) {
      error(-1, "Bad 'psPaperSize' config file command (%s:%d)",
	    fileName->getCString(), line);
    }
  } else if (tokens->getLength() == 3) {
    tok = (GString *)tokens->get(1);
    psPaperWidth = atoi(tok->getCString());
    tok = (GString *)tokens->get(2);
    psPaperHeight = atoi(tok->getCString());
663
664
665
    psImageableLLX = psImageableLLY = 0;
    psImageableURX = psPaperWidth;
    psImageableURY = psPaperHeight;
666
667
668
669
670
671
  } else {
    error(-1, "Bad 'psPaperSize' config file command (%s:%d)",
	  fileName->getCString(), line);
  }
}

672
673
674
675
676
677
678
679
680
681
682
683
684
void GlobalParams::parsePSImageableArea(GList *tokens, GString *fileName,
					int line) {
  if (tokens->getLength() != 5) {
    error(-1, "Bad 'psImageableArea' config file command (%s:%d)",
	  fileName->getCString(), line);
    return;
  }
  psImageableLLX = atoi(((GString *)tokens->get(1))->getCString());
  psImageableLLY = atoi(((GString *)tokens->get(2))->getCString());
  psImageableURX = atoi(((GString *)tokens->get(3))->getCString());
  psImageableURY = atoi(((GString *)tokens->get(4))->getCString());
}

685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
void GlobalParams::parsePSLevel(GList *tokens, GString *fileName, int line) {
  GString *tok;

  if (tokens->getLength() != 2) {
    error(-1, "Bad 'psLevel' config file command (%s:%d)",
	  fileName->getCString(), line);
    return;
  }
  tok = (GString *)tokens->get(1);
  if (!tok->cmp("level1")) {
    psLevel = psLevel1;
  } else if (!tok->cmp("level1sep")) {
    psLevel = psLevel1Sep;
  } else if (!tok->cmp("level2")) {
    psLevel = psLevel2;
  } else if (!tok->cmp("level2sep")) {
    psLevel = psLevel2Sep;
  } else if (!tok->cmp("level3")) {
    psLevel = psLevel3;
  } else if (!tok->cmp("level3Sep")) {
    psLevel = psLevel3Sep;
  } else {
    error(-1, "Bad 'psLevel' config file command (%s:%d)",
	  fileName->getCString(), line);
  }
}

void GlobalParams::parsePSFile(GList *tokens, GString *fileName, int line) {
  if (tokens->getLength() != 2) {
    error(-1, "Bad 'psFile' config file command (%s:%d)",
	  fileName->getCString(), line);
    return;
  }
  if (psFile) {
    delete psFile;
  }
  psFile = ((GString *)tokens->get(1))->copy();
}

void GlobalParams::parsePSFont(GList *tokens, GString *fileName, int line) {
  PSFontParam *param;

  if (tokens->getLength() != 3) {
    error(-1, "Bad 'psFont' config file command (%s:%d)",
	  fileName->getCString(), line);
    return;
  }
  param = new PSFontParam(((GString *)tokens->get(1))->copy(), 0,
			  ((GString *)tokens->get(2))->copy(), NULL);
  psFonts->add(param->pdfFontName, param);
}

737
void GlobalParams::parsePSFont16(const char *cmdName, GList *fontList,
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
				 GList *tokens, GString *fileName, int line) {
  PSFontParam *param;
  int wMode;
  GString *tok;

  if (tokens->getLength() != 5) {
    error(-1, "Bad '%s' config file command (%s:%d)",
	  cmdName, fileName->getCString(), line);
    return;
  }
  tok = (GString *)tokens->get(2);
  if (!tok->cmp("H")) {
    wMode = 0;
  } else if (!tok->cmp("V")) {
    wMode = 1;
  } else {
    error(-1, "Bad '%s' config file command (%s:%d)",
	  cmdName, fileName->getCString(), line);
    return;
  }
  param = new PSFontParam(((GString *)tokens->get(1))->copy(),
			  wMode,
			  ((GString *)tokens->get(3))->copy(),
			  ((GString *)tokens->get(4))->copy());
  fontList->append(param);
}

void GlobalParams::parseTextEncoding(GList *tokens, GString *fileName,
				     int line) {
  if (tokens->getLength() != 2) {
    error(-1, "Bad 'textEncoding' config file command (%s:%d)",
	  fileName->getCString(), line);
    return;
  }
  delete textEncoding;
  textEncoding = ((GString *)tokens->get(1))->copy();
}

void GlobalParams::parseTextEOL(GList *tokens, GString *fileName, int line) {
  GString *tok;

  if (tokens->getLength() != 2) {
    error(-1, "Bad 'textEOL' config file command (%s:%d)",
	  fileName->getCString(), line);
    return;
  }
  tok = (GString *)tokens->get(1);
  if (!tok->cmp("unix")) {
    textEOL = eolUnix;
  } else if (!tok->cmp("dos")) {
    textEOL = eolDOS;
  } else if (!tok->cmp("mac")) {
    textEOL = eolMac;
  } else {
    error(-1, "Bad 'textEOL' config file command (%s:%d)",
	  fileName->getCString(), line);
  }
}

void GlobalParams::parseFontDir(GList *tokens, GString *fileName, int line) {
  if (tokens->getLength() != 2) {
    error(-1, "Bad 'fontDir' config file command (%s:%d)",
	  fileName->getCString(), line);
    return;
  }
  fontDirs->append(((GString *)tokens->get(1))->copy());
}

void GlobalParams::parseInitialZoom(GList *tokens,
				    GString *fileName, int line) {
  if (tokens->getLength() != 2) {
    error(-1, "Bad 'initialZoom' config file command (%s:%d)",
	  fileName->getCString(), line);
    return;
  }
  delete initialZoom;
  initialZoom = ((GString *)tokens->get(1))->copy();
}

817
void GlobalParams::parseCommand(const char *cmdName, GString **val,
Wilco Greven's avatar
Wilco Greven committed
818
				GList *tokens, GString *fileName, int line) {
819
  if (tokens->getLength() != 2) {
Wilco Greven's avatar
Wilco Greven committed
820
821
    error(-1, "Bad '%s' config file command (%s:%d)",
	  cmdName, fileName->getCString(), line);
822
823
    return;
  }
Wilco Greven's avatar
Wilco Greven committed
824
825
  if (*val) {
    delete *val;
826
  }
Wilco Greven's avatar
Wilco Greven committed
827
  *val = ((GString *)tokens->get(1))->copy();
828
829
}

830
void GlobalParams::parseYesNo(const char *cmdName, GBool *flag,
831
832
833
834
835
836
837
838
839
			      GList *tokens, GString *fileName, int line) {
  GString *tok;

  if (tokens->getLength() != 2) {
    error(-1, "Bad '%s' config file command (%s:%d)",
	  cmdName, fileName->getCString(), line);
    return;
  }
  tok = (GString *)tokens->get(1);
840
841
842
843
844
845
846
847
  if (!parseYesNo2(tok->getCString(), flag)) {
    error(-1, "Bad '%s' config file command (%s:%d)",
	  cmdName, fileName->getCString(), line);
  }
}

GBool GlobalParams::parseYesNo2(char *token, GBool *flag) {
  if (!strcmp(token, "yes")) {
848
    *flag = gTrue;
849
  } else if (!strcmp(token, "no")) {
850
851
    *flag = gFalse;
  } else {
852
    return gFalse;
853
  }
854
  return gTrue;
855
856
857
858
}

GlobalParams::~GlobalParams() {
  GHashIter *iter;
859
  GString *key;
860
861
862
863
864
865
866
867
  GList *list;

  freeBuiltinFontTables();

  delete macRomanReverseMap;

  delete nameToUnicode;
  deleteGHash(cidToUnicodes, GString);
868
  deleteGHash(unicodeToUnicodes, GString);
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
  deleteGHash(residentUnicodeMaps, UnicodeMap);
  deleteGHash(unicodeMaps, GString);
  deleteGList(toUnicodeDirs, GString);
  deleteGHash(displayFonts, DisplayFontParam);
  deleteGHash(displayCIDFonts, DisplayFontParam);
  deleteGHash(displayNamedCIDFonts, DisplayFontParam);
  if (psFile) {
    delete psFile;
  }
  deleteGHash(psFonts, PSFontParam);
  deleteGList(psNamedFonts16, PSFontParam);
  deleteGList(psFonts16, PSFontParam);
  delete textEncoding;
  deleteGList(fontDirs, GString);
  delete initialZoom;
  if (urlCommand) {
    delete urlCommand;
  }
Wilco Greven's avatar
Wilco Greven committed
887
888
889
  if (movieCommand) {
    delete movieCommand;
  }
890
891
892
893
894
895
896
897

  cMapDirs->startIter(&iter);
  while (cMapDirs->getNext(&iter, &key, (void **)&list)) {
    deleteGList(list, GString);
  }
  delete cMapDirs;

  delete cidToUnicodeCache;
898
  delete unicodeToUnicodeCache;
899
900
  delete unicodeMapCache;
  delete cMapCache;
901

902
#if MULTITHREADED
903
  gDestroyMutex(&mutex);
904
905
  gDestroyMutex(&unicodeMapCacheMutex);
  gDestroyMutex(&cMapCacheMutex);
906
#endif
907
908
}

909
910
911
912
913
914
915
//------------------------------------------------------------------------

void GlobalParams::setupBaseFonts(char *dir) {
  GString *fontName;
  GString *fileName;
  FILE *f;
  DisplayFontParam *dfp;
916
  int i/*, j*/;
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933

  for (i = 0; displayFontTab[i].name; ++i) {
    fontName = new GString(displayFontTab[i].name);
    if (getDisplayFont(fontName)) {
      delete fontName;
      continue;
    }
    fileName = NULL;
    if (dir) {
      fileName = appendToPath(new GString(dir), displayFontTab[i].fileName);
      if ((f = fopen(fileName->getCString(), "rb"))) {
	fclose(f);
      } else {
	delete fileName;
	fileName = NULL;
      }
    }
934
935
// KPDF: no more searching hardcoded dirs, Xft handles that
/*
936
937
938
939
940
941
942
943
944
945
946
947
#ifndef WIN32
    for (j = 0; !fileName && displayFontDirs[j]; ++j) {
      fileName = appendToPath(new GString(displayFontDirs[j]),
			      displayFontTab[i].fileName);
      if ((f = fopen(fileName->getCString(), "rb"))) {
	fclose(f);
      } else {
	delete fileName;
	fileName = NULL;
      }
    }
#endif
948
*/
949
950
951
952
953
954
955
956
957
958
959
    if (!fileName) {
      error(-1, "No display font for '%s'", displayFontTab[i].name);
      delete fontName;
      continue;
    }
    dfp = new DisplayFontParam(fontName, displayFontT1);
    dfp->t1.fileName = fileName;
    globalParams->addDisplayFont(dfp);
  }
}

960
961
962
963
//------------------------------------------------------------------------
// accessors
//------------------------------------------------------------------------

964
CharCode GlobalParams::getMacRomanCharCode(const char *charName) {
965
  // no need to lock - macRomanReverseMap is constant
966
967
968
  return macRomanReverseMap->lookup(charName);
}

969
Unicode GlobalParams::mapNameToUnicode(const char *charName) {
970
  // no need to lock - nameToUnicode is constant
971
972
973
  return nameToUnicode->lookup(charName);
}

974
975
UnicodeMap *GlobalParams::getResidentUnicodeMap(GString *encodingName) {
  UnicodeMap *map;
976

977
978
979
980
981
  lockGlobalParams;
  map = (UnicodeMap *)residentUnicodeMaps->lookup(encodingName);
  unlockGlobalParams;
  if (map) {
    map->incRefCnt();
982
  }
983
  return map;
984
985
986
987
}

FILE *GlobalParams::getUnicodeMapFile(GString *encodingName) {
  GString *fileName;
988
  FILE *f;
989

990
991
992
993
994
  lockGlobalParams;
  if ((fileName = (GString *)unicodeMaps->lookup(encodingName))) {
    f = fopen(fileName->getCString(), "r");
  } else {
    f = NULL;
995
  }
996
997
  unlockGlobalParams;
  return f;
998
999
1000
1001
1002
1003
1004
1005
1006
}

FILE *GlobalParams::findCMapFile(GString *collection, GString *cMapName) {
  GList *list;
  GString *dir;
  GString *fileName;
  FILE *f;
  int i;

1007
  lockGlobalParams;
1008
  if (!(list = (GList *)cMapDirs->lookup(collection))) {
1009
    unlockGlobalParams;
1010
1011
1012
1013
1014
1015
1016
1017
    return NULL;
  }
  for (i = 0; i < list->getLength(); ++i) {
    dir = (GString *)list->get(i);
    fileName = appendToPath(dir->copy(), cMapName->getCString());
    f = fopen(fileName->getCString(), "r");
    delete fileName;
    if (f) {
1018
      unlockGlobalParams;
1019
1020
1021
      return f;
    }
  }
1022
  unlockGlobalParams;
1023
1024
1025
1026
1027
1028
1029
1030
  return NULL;
}

FILE *GlobalParams::findToUnicodeFile(GString *name) {
  GString *dir, *fileName;
  FILE *f;
  int i;

1031
  lockGlobalParams;
1032
1033
1034
1035
1036
1037
  for (i = 0; i < toUnicodeDirs->getLength(); ++i) {
    dir = (GString *)toUnicodeDirs->get(i);
    fileName = appendToPath(dir->copy(), name->getCString());
    f = fopen(fileName->getCString(), "r");
    delete fileName;
    if (f) {
1038
      unlockGlobalParams;
1039
1040
1041
      return f;
    }
  }
1042
  unlockGlobalParams;
1043
1044
1045
  return NULL;
}

1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
// KPDF: parse xpdf font name into family and style
// Helvetica-BoldOblique => name=Helvetica, weight=Bold, slant=Oblique

void parseStyle(QString& name, int& weight, int& slant)
{
  if (!name.contains('-') && !name.contains(',')) return;
  QString type = name.section(QRegExp("[-,]"),-1);
  name = name.section(QRegExp("[-,]"),0,-2);
  if (type.contains("Oblique")) slant=FC_SLANT_OBLIQUE;
  if (type.contains("Italic")) slant=FC_SLANT_ITALIC;
  if (type.contains("Bold")) weight=FC_WEIGHT_BOLD;
}



1061
DisplayFontParam *GlobalParams::getDisplayFont(GString *fontName) {
1062
  DisplayFontParam *dfp;
1063
1064
1065
1066
1067
  FcPattern *p=0,*m=0;
  FcChar8* s;
  char * ext;
  FcResult res;
 
1068

1069
  lockGlobalParams;
1070
  dfp = (DisplayFontParam *)displayFonts->lookup(fontName);
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
  // KPDF: try to find font using Xft
  if (!dfp) {
  	int weight=FC_WEIGHT_MEDIUM, slant=FC_SLANT_ROMAN;
	QString name(fontName->getCString());
	parseStyle(name,weight,slant);
	p = FcPatternBuild(0,FC_FAMILY,FcTypeString, name.ascii(), FC_SLANT, FcTypeInteger, slant, FC_WEIGHT, FcTypeInteger, weight, (char*)0);
	if (!p) goto fin;
	m = XftFontMatch(qt_xdisplay(),qt_xscreen(),p,&res);
	if (!m) goto fin; 
	res = FcPatternGetString (m, FC_FILE, 0, &s);
	if (res != FcResultMatch || !s)  goto fin; 
	ext = rindex((char*)s,'.');
	if (!ext) goto fin;
	if (!strncasecmp(ext,".ttf",4)) {
	  dfp = new DisplayFontParam(fontName->copy(), displayFontTT);  
   	  dfp->tt.fileName = new GString((char*)s);
	 }  else if (!strncasecmp(ext,".pfa",4) || !strncasecmp(ext,".pfb",4)) {
	   dfp = new DisplayFontParam(fontName->copy(), displayFontT1);  
	   dfp->t1.fileName = new GString((char*)s);
	 } else goto fin;
	displayFonts->add(dfp->name,dfp);
	}		
fin:  unlockGlobalParams;
  if (m) FcPatternDestroy(m);
  if (p) FcPatternDestroy(p);
1096
  return dfp;
1097
1098
1099
1100
1101
1102
}

DisplayFontParam *GlobalParams::getDisplayCIDFont(GString *fontName,
						  GString *collection) {
  DisplayFontParam *dfp;

1103
  lockGlobalParams;
1104
1105
1106
1107
  if (!fontName ||
      !(dfp = (DisplayFontParam *)displayNamedCIDFonts->lookup(fontName))) {
    dfp = (DisplayFontParam *)displayCIDFonts->lookup(collection);
  }
1108
  unlockGlobalParams;
1109
1110
1111
  return dfp;
}

1112
1113
1114
GString *GlobalParams::getPSFile() {
  GString *s;

1115
  lockGlobalParams;
1116
  s = psFile ? psFile->copy() : (GString *)NULL;
1117
  unlockGlobalParams;
1118
1119
1120
1121
1122
1123
  return s;
}

int GlobalParams::getPSPaperWidth() {
  int w;

1124
  lockGlobalParams;
1125
  w = psPaperWidth;
1126
  unlockGlobalParams;
1127
1128
1129
1130
1131
1132
  return w;
}

int GlobalParams::getPSPaperHeight() {
  int h;

1133
  lockGlobalParams;
1134
  h = psPaperHeight;
1135
  unlockGlobalParams;
1136
1137
1138
  return h;
}

1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
void GlobalParams::getPSImageableArea(int *llx, int *lly, int *urx, int *ury) {
  lockGlobalParams;
  *llx = psImageableLLX;
  *lly = psImageableLLY;
  *urx = psImageableURX;
  *ury = psImageableURY;
  unlockGlobalParams;
}

GBool GlobalParams::getPSCrop() {
  GBool f;

  lockGlobalParams;
  f = psCrop;
  unlockGlobalParams;
  return f;
}

GBool GlobalParams::getPSExpandSmaller() {
  GBool f;

  lockGlobalParams;
  f = psExpandSmaller;
  unlockGlobalParams;
  return f;
}

GBool GlobalParams::getPSShrinkLarger() {
  GBool f;

  lockGlobalParams;
  f = psShrinkLarger;
  unlockGlobalParams;
  return f;
}

GBool GlobalParams::getPSCenter() {
  GBool f;

  lockGlobalParams;
  f = psCenter;
  unlockGlobalParams;
  return f;
}

1184
1185
1186
GBool GlobalParams::getPSDuplex() {
  GBool d;

1187
  lockGlobalParams;
1188
  d = psDuplex;
1189
  unlockGlobalParams;
1190
1191
1192
1193
1194
1195
  return d;
}

PSLevel GlobalParams::getPSLevel() {
  PSLevel level;

1196
  lockGlobalParams;
1197
  level = psLevel;
1198
  unlockGlobalParams;
1199
1200
1201
  return level;
}

1202
PSFontParam *GlobalParams::getPSFont(GString *fontName) {
1203
1204
1205
1206
1207
1208
  PSFontParam *p;

  lockGlobalParams;
  p = (PSFontParam *)psFonts->lookup(fontName);
  unlockGlobalParams;
  return p;
1209
1210
1211
1212
1213
1214
1215
}

PSFontParam *GlobalParams::getPSFont16(GString *fontName,
				       GString *collection, int wMode) {
  PSFontParam *p;
  int i;

1216
  lockGlobalParams;
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
  p = NULL;
  if (fontName) {
    for (i = 0; i < psNamedFonts16->getLength(); ++i) {
      p = (PSFontParam *)psNamedFonts16->get(i);
      if (!p->pdfFontName->cmp(fontName) &&
	  p->wMode == wMode) {
	break;
      }
      p = NULL;
    }
  }
  if (!p && collection) {
    for (i = 0; i < psFonts16->getLength(); ++i) {
      p = (PSFontParam *)psFonts16->get(i);
      if (!p->pdfFontName->cmp(collection) &&
	  p->wMode == wMode) {
	break;
      }
      p = NULL;
    }
  }
1238
  unlockGlobalParams;
1239
1240
1241
  return p;
}

1242
1243
1244
GBool GlobalParams::getPSEmbedType1() {
  GBool e;

1245
  lockGlobalParams;
1246
  e = psEmbedType1;
1247
  unlockGlobalParams;
1248
1249
1250
1251
1252
1253
  return e;
}

GBool GlobalParams::getPSEmbedTrueType() {
  GBool e;

1254
  lockGlobalParams;
1255
  e = psEmbedTrueType;
1256
  unlockGlobalParams;
1257
1258
1259
1260
1261
1262
  return e;
}

GBool GlobalParams::getPSEmbedCIDPostScript() {
  GBool e;

1263
  lockGlobalParams;
1264
  e = psEmbedCIDPostScript;
1265
  unlockGlobalParams;
1266
1267
1268
1269
1270
1271
  return e;
}

GBool GlobalParams::getPSEmbedCIDTrueType() {
  GBool e;

1272
  lockGlobalParams;
1273
  e = psEmbedCIDTrueType;
1274
  unlockGlobalParams;
1275
1276
1277
1278
1279
1280
  return e;
}

GBool GlobalParams::getPSOPI() {
  GBool opi;

1281
  lockGlobalParams;
1282
  opi = psOPI;
1283
  unlockGlobalParams;
1284
1285
1286
1287
1288
1289
  return opi;
}

GBool GlobalParams::getPSASCIIHex() {
  GBool ah;

1290
  lockGlobalParams;
1291
  ah = psASCIIHex;
1292
  unlockGlobalParams;
1293
1294
1295
  return ah;
}

1296
1297
1298
1299
1300
1301
1302
1303
1304
GString *GlobalParams::getTextEncodingName() {
  GString *s;

  lockGlobalParams;
  s = textEncoding->copy();
  unlockGlobalParams;
  return s;
}

1305
1306
1307
EndOfLineKind GlobalParams::getTextEOL() {
  EndOfLineKind eol;

1308
  lockGlobalParams;
1309
  eol = textEOL;
1310
  unlockGlobalParams;
1311
1312
1313
  return eol;
}

1314
1315
1316
1317
1318
1319
1320
1321
1322
GBool GlobalParams::getTextPageBreaks() {
  GBool pageBreaks;

  lockGlobalParams;
  pageBreaks = textPageBreaks;
  unlockGlobalParams;
  return pageBreaks;
}

1323
1324
1325
GBool GlobalParams::getTextKeepTinyChars() {
  GBool tiny;

1326
  lockGlobalParams;
1327
  tiny = textKeepTinyChars;
1328
  unlockGlobalParams;
1329
1330
1331
  return tiny;
}

1332
GString *GlobalParams::findFontFile(GString *fontName, const char **exts) {
1333
  GString *dir, *fileName;
1334
  const char **ext;
1335
1336
1337
  FILE *f;
  int i;

1338
  lockGlobalParams;
1339
1340
  for (i = 0; i < fontDirs->getLength(); ++i) {
    dir = (GString *)fontDirs->get(i);
1341
    for (ext = exts; *ext; ++ext) {
1342
      fileName = appendToPath(dir->copy(), fontName->getCString());
1343
      fileName->append(*ext);
1344
      if ((f = fopen(fileName->getCString(), "rb"))) {
1345
	fclose(f);
1346
	unlockGlobalParams;
1347
1348
1349
1350
1351
	return fileName;
      }
      delete fileName;
    }
  }
1352
  unlockGlobalParams;
1353
1354
1355
  return NULL;
}

1356
1357
1358
GString *GlobalParams::getInitialZoom() {
  GString *s;

1359
  lockGlobalParams;
1360
  s = initialZoom->copy();
1361
  unlockGlobalParams;
1362
1363
1364
  return s;
}

1365
1366
GBool GlobalParams::getEnableT1lib() {
  GBool f;
1367

1368
1369
1370
1371
  lockGlobalParams;
  f = enableT1lib;
  unlockGlobalParams;
  return f;
1372
1373
}

1374
1375
GBool GlobalParams::getEnableFreeType() {
  GBool f;
1376

1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
  lockGlobalParams;
  f = enableFreeType;
  unlockGlobalParams;
  return f;
}


GBool GlobalParams::getAntialias() {
  GBool f;

  lockGlobalParams;
  f = antialias;
  unlockGlobalParams;
  return f;
1391
1392
1393
1394
1395
}

GBool GlobalParams::getMapNumericCharNames() {
  GBool map;

1396
  lockGlobalParams;
1397
  map = mapNumericCharNames;
1398
  unlockGlobalParams;
1399
1400
1401
1402
1403
1404
  return map;
}

GBool GlobalParams::getPrintCommands() {
  GBool p;

1405
  lockGlobalParams;
1406
  p = printCommands;
1407
  unlockGlobalParams;
1408
1409
1410
1411
1412
1413
  return p;
}

GBool GlobalParams::getErrQuiet() {
  GBool q;

1414
  lockGlobalParams;
1415
  q = errQuiet;
1416
  unlockGlobalParams;
1417
1418
1419
  return q;
}

1420
CharCodeToUnicode *GlobalParams::getCIDToUnicode(GString *collection) {
1421
  GString *fileName;
1422
1423
  CharCodeToUnicode *ctu;

1424
1425
1426
1427
1428
1429
1430
1431
  lockGlobalParams;
  if (!(ctu = cidToUnicodeCache->getCharCodeToUnicode(collection))) {
    if ((fileName = (GString *)cidToUnicodes->lookup(collection)) &&
	(ctu = CharCodeToUnicode::parseCIDToUnicode(fileName, collection))) {
      cidToUnicodeCache->add(ctu);
    }
  }
  unlockGlobalParams;
1432
  return ctu;
1433
1434
}

1435
1436
1437
1438
CharCodeToUnicode *GlobalParams::getUnicodeToUnicode(GString *fontName) {
  CharCodeToUnicode *ctu;
  GHashIter *iter;
  GString *fontPattern, *fileName;
1439

1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
  lockGlobalParams;
  fileName = NULL;
  unicodeToUnicodes->startIter(&iter);
  while (unicodeToUnicodes->getNext(&iter, &fontPattern, (void **)&fileName)) {
    if (strstr(fontName->getCString(), fontPattern->getCString())) {
      unicodeToUnicodes->killIter(&iter);
      break;
    }
    fileName = NULL;
  }
  if (fileName) {
    if (!(ctu = unicodeToUnicodeCache->getCharCodeToUnicode(fileName))) {
      if ((ctu = CharCodeToUnicode::parseUnicodeToUnicode(fileName))) {
	unicodeToUnicodeCache->add(ctu);
      }
    }
  } else {
    ctu = NULL;
  }
  unlockGlobalParams;
  return ctu;
}

UnicodeMap *GlobalParams::getUnicodeMap(GString *encodingName) {
  return getUnicodeMap2(encodingName);
1465
1466
1467
1468
1469
}

UnicodeMap *GlobalParams::getUnicodeMap2(GString *encodingName) {
  UnicodeMap *map;

1470
1471
  if (!(map = getResidentUnicodeMap(encodingName))) {
    lockUnicodeMapCache;
1472
    map = unicodeMapCache->getUnicodeMap(encodingName);
1473
    unlockUnicodeMapCache;
1474
  }
1475
  return map;
1476
1477
1478
}

CMap *GlobalParams::getCMap(GString *collection, GString *cMapName) {
1479
1480
  CMap *cMap;

1481
  lockCMapCache;
1482
  cMap = cMapCache->getCMap(collection, cMapName);
1483
  unlockCMapCache;
1484
  return cMap;