GlobalParams.cc 44.5 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
#include <strings.h>
17
18
19
20
// KPDF: additional includes for Qt and Xft
#include <qstring.h>
#include <qregexp.h>
#include <qwindowdefs.h>
21
22
23
24
25
// -- 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
// -- ---------------------------------------------------------- --
26
27
#include <X11/Xft/Xft.h>
#include <X11/Xft/XftCompat.h>
28
#include <stdio.h>
29
#include <ctype.h>
Enrico Ros's avatar
Enrico Ros committed
30
#include <sys/stat.h>
31
#if HAVE_PAPER_H
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#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"

48
49
50
51
52
53
54
#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)
55
#else
56
57
58
59
60
61
#  define lockGlobalParams
#  define lockUnicodeMapCache
#  define lockCMapCache
#  define unlockGlobalParams
#  define unlockUnicodeMapCache
#  define unlockCMapCache
62
63
#endif

64
65
66
67
68
69
#include "NameToUnicodeTable.h"
#include "UnicodeMapTables.h"
#include "UTF8.h"

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

70
71
72
73
74
75
#define cidToUnicodeCacheSize     4
#define unicodeToUnicodeCacheSize 4

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

static struct {
76
77
  const char *name;
  const char *fileName;
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
} 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"},
93
  {NULL, NULL}
94
95
};

96
static const char *displayFontDirs[] = {
97
98
99
  "/usr/share/ghostscript/fonts",
  "/usr/local/share/ghostscript/fonts",
  "/usr/share/fonts/default/Type1",
100
  "/usr/share/fonts/type1/gsfonts",
101
  "/usr/share/fonts/default/ghostscript/",
102
  NULL
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
167
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
//------------------------------------------------------------------------

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

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

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

260
261
262
  cidToUnicodeCache = new CharCodeToUnicodeCache(cidToUnicodeCacheSize);
  unicodeToUnicodeCache =
      new CharCodeToUnicodeCache(unicodeToUnicodeCacheSize);
263
264
265
266
267
268
269
270
271
  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
272
273
  map = new UnicodeMap("Latin1", gFalse,
		       latin1UnicodeMapRanges, latin1UnicodeMapLen);
274
  residentUnicodeMaps->add(map->getEncodingName(), map);
Wilco Greven's avatar
Wilco Greven committed
275
276
  map = new UnicodeMap("ASCII7", gFalse,
		       ascii7UnicodeMapRanges, ascii7UnicodeMapLen);
277
  residentUnicodeMaps->add(map->getEncodingName(), map);
Wilco Greven's avatar
Wilco Greven committed
278
279
  map = new UnicodeMap("Symbol", gFalse,
		       symbolUnicodeMapRanges, symbolUnicodeMapLen);
280
  residentUnicodeMaps->add(map->getEncodingName(), map);
Wilco Greven's avatar
Wilco Greven committed
281
  map = new UnicodeMap("ZapfDingbats", gFalse, zapfDingbatsUnicodeMapRanges,
282
283
		       zapfDingbatsUnicodeMapLen);
  residentUnicodeMaps->add(map->getEncodingName(), map);
Wilco Greven's avatar
Wilco Greven committed
284
  map = new UnicodeMap("UTF-8", gTrue, &mapUTF8);
285
  residentUnicodeMaps->add(map->getEncodingName(), map);
Wilco Greven's avatar
Wilco Greven committed
286
  map = new UnicodeMap("UCS-2", gTrue, &mapUCS2);
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
  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
310
      buf[0] = '\0';
311
312
313
314
315
316
317
318
319
320
321
322
323
    }
    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
324
    fclose(f);
325
326
327
328
329
330
331
332
333
334
335
336
  }
}

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

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

    // 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));
354
      p1 = *p2 ? p2 + 1 : p2;
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
    }

    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);
378
379
      } else if (!cmd->cmp("unicodeToUnicode")) {
	parseUnicodeToUnicode(tokens, fileName, line);
380
381
382
383
384
385
386
      } 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);
      } 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
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;
Enrico Ros's avatar
Enrico Ros committed
614
  struct stat statbuf;
615
616
617
618
619

  if (tokens->getLength() < 2) {
    goto err1;
  }
  param = new DisplayFontParam(((GString *)tokens->get(1))->copy(), kind);
620
  
621
622
623
624
625
626
  switch (kind) {
  case displayFontT1:
    if (tokens->getLength() != 3) {
      goto err2;
    }
    param->t1.fileName = ((GString *)tokens->get(2))->copy();
Enrico Ros's avatar
Enrico Ros committed
627
628
629
630
    if (stat((param->t1.fileName->getCString)(), &statbuf)) {
      delete param; // silently ignore non-existing files
      return;
    }    
631
632
    break;
  case displayFontTT:
Enrico Ros's avatar
Enrico Ros committed
633
    if (tokens->getLength() < 3) {
634
635
636
      goto err2;
    }
    param->tt.fileName = ((GString *)tokens->get(2))->copy();
Enrico Ros's avatar
Enrico Ros committed
637
638
639
640
641
642
643
644
    if (stat((param->tt.fileName->getCString)(), &statbuf)) {
      delete param; // silently ignore non-existing files
      return;
    }
    if (tokens->getLength() > 3)
      param->tt.faceIndex = atoi(((GString *)tokens->get(3))->getCString());
    else
      param->tt.faceIndex = 0;
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
    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());
676
677
678
    psImageableLLX = psImageableLLY = 0;
    psImageableURX = psPaperWidth;
    psImageableURY = psPaperHeight;
679
680
681
682
683
684
  } else {
    error(-1, "Bad 'psPaperSize' config file command (%s:%d)",
	  fileName->getCString(), line);
  }
}

685
686
687
688
689
690
691
692
693
694
695
696
697
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());
}

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
737
738
739
740
741
742
743
744
745
746
747
748
749
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);
}

750
void GlobalParams::parsePSFont16(const char *cmdName, GList *fontList,
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
817
818
819
820
821
822
823
824
825
826
827
828
829
				 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();
}

830
void GlobalParams::parseCommand(const char *cmdName, GString **val,
Wilco Greven's avatar
Wilco Greven committed
831
				GList *tokens, GString *fileName, int line) {
832
  if (tokens->getLength() != 2) {
Wilco Greven's avatar
Wilco Greven committed
833
834
    error(-1, "Bad '%s' config file command (%s:%d)",
	  cmdName, fileName->getCString(), line);
835
836
    return;
  }
Wilco Greven's avatar
Wilco Greven committed
837
838
  if (*val) {
    delete *val;
839
  }
Wilco Greven's avatar
Wilco Greven committed
840
  *val = ((GString *)tokens->get(1))->copy();
841
842
}

843
void GlobalParams::parseYesNo(const char *cmdName, GBool *flag,
844
845
846
847
848
849
850
851
852
			      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);
853
854
855
856
857
858
859
860
  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")) {
861
    *flag = gTrue;
862
  } else if (!strcmp(token, "no")) {
863
864
    *flag = gFalse;
  } else {
865
    return gFalse;
866
  }
867
  return gTrue;
868
869
870
871
}

GlobalParams::~GlobalParams() {
  GHashIter *iter;
872
  GString *key;
873
874
875
876
877
878
879
880
  GList *list;

  freeBuiltinFontTables();

  delete macRomanReverseMap;

  delete nameToUnicode;
  deleteGHash(cidToUnicodes, GString);
881
  deleteGHash(unicodeToUnicodes, GString);
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
  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
900
901
902
  if (movieCommand) {
    delete movieCommand;
  }
903
904
905
906
907
908
909
910

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

  delete cidToUnicodeCache;
911
  delete unicodeToUnicodeCache;
912
913
  delete unicodeMapCache;
  delete cMapCache;
914

915
#if MULTITHREADED
916
  gDestroyMutex(&mutex);
917
918
  gDestroyMutex(&unicodeMapCacheMutex);
  gDestroyMutex(&cMapCacheMutex);
919
#endif
920
921
}

922
923
924
925
926
927
928
//------------------------------------------------------------------------

void GlobalParams::setupBaseFonts(char *dir) {
  GString *fontName;
  GString *fileName;
  FILE *f;
  DisplayFontParam *dfp;
929
  int i, j;
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946

  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;
      }
    }
947

948
949
950
951
952
953
954
955
956
957
958
959
#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
960

961
962
963
964
965
966
967
968
969
970
971
    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);
  }
}

972
973
974
975
//------------------------------------------------------------------------
// accessors
//------------------------------------------------------------------------

976
CharCode GlobalParams::getMacRomanCharCode(const char *charName) {
977
  // no need to lock - macRomanReverseMap is constant
978
979
980
  return macRomanReverseMap->lookup(charName);
}

981
Unicode GlobalParams::mapNameToUnicode(const char *charName) {
982
  // no need to lock - nameToUnicode is constant
983
984
985
  return nameToUnicode->lookup(charName);
}

986
987
UnicodeMap *GlobalParams::getResidentUnicodeMap(GString *encodingName) {
  UnicodeMap *map;
988

989
990
991
992
993
  lockGlobalParams;
  map = (UnicodeMap *)residentUnicodeMaps->lookup(encodingName);
  unlockGlobalParams;
  if (map) {
    map->incRefCnt();
994
  }
995
  return map;
996
997
998
999
}

FILE *GlobalParams::getUnicodeMapFile(GString *encodingName) {
  GString *fileName;
1000
  FILE *f;
1001

1002
1003
1004
1005
1006
  lockGlobalParams;
  if ((fileName = (GString *)unicodeMaps->lookup(encodingName))) {
    f = fopen(fileName->getCString(), "r");
  } else {
    f = NULL;
1007
  }
1008
1009
  unlockGlobalParams;
  return f;
1010
1011
1012
1013
1014
1015
1016
1017
1018
}

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

1019
  lockGlobalParams;
1020
  if (!(list = (GList *)cMapDirs->lookup(collection))) {
1021
    unlockGlobalParams;
1022
1023
1024
1025
1026
1027
1028
1029
    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) {
1030
      unlockGlobalParams;
1031
1032
1033
      return f;
    }
  }
1034
  unlockGlobalParams;
1035
1036
1037
1038
1039
1040
1041
1042
  return NULL;
}

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

1043
  lockGlobalParams;
1044
1045
1046
1047
1048
1049
  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) {
1050
      unlockGlobalParams;
1051
1052
1053
      return f;
    }
  }
1054
  unlockGlobalParams;
1055
1056
1057
  return NULL;
}

1058
1059
1060
// KPDF: parse xpdf font name into family and style
// Helvetica-BoldOblique => name=Helvetica, weight=Bold, slant=Oblique

Enrico Ros's avatar
Enrico Ros committed
1061
void parseStyle(QString& name, int& weight, int& slant, int& width)
1062
{
Enrico Ros's avatar
Enrico Ros committed
1063
1064
  if (name.find("MS-") == 0) name = "MS " + name.remove(0,3);

1065
1066
1067
1068
1069
1070
  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;
Enrico Ros's avatar
Enrico Ros committed
1071
1072
  if (type.contains("Light")) weight=FC_WEIGHT_LIGHT;
  if (type.contains("Condensed")) width=FC_WIDTH_CONDENSED;
1073
1074
}

1075
DisplayFontParam *GlobalParams::getDisplayFont(GString *fontName) {
1076
  DisplayFontParam *dfp;
1077
1078
1079
1080
  FcPattern *p=0,*m=0;
  FcChar8* s;
  char * ext;
  FcResult res;
1081

1082
  lockGlobalParams;
1083
  dfp = (DisplayFontParam *)displayFonts->lookup(fontName);
1084
1085
  // KPDF: try to find font using Xft
  if (!dfp) {
Enrico Ros's avatar
Enrico Ros committed
1086
  	int weight=FC_WEIGHT_MEDIUM, slant=FC_SLANT_ROMAN, width=FC_WIDTH_NORMAL;
1087
	QString name(fontName->getCString());
Enrico Ros's avatar
Enrico Ros committed
1088
1089
	
	parseStyle(name,weight,slant,width);
1090
1091
	p = FcPatternBuild(0,FC_FAMILY,FcTypeString, name.ascii(), 
		FC_SLANT, FcTypeInteger, slant, FC_WEIGHT, FcTypeInteger, weight,
Enrico Ros's avatar
Enrico Ros committed
1092
		FC_WIDTH, FcTypeInteger, width, FC_LANG, FcTypeString, "xx", (char*)0);
1093
1094
	if (!p) goto fin;
	m = XftFontMatch(qt_xdisplay(),qt_xscreen(),p,&res);
Enrico Ros's avatar
Enrico Ros committed
1095
	if (!m) goto fin;
1096
1097
1098
1099
	res = FcPatternGetString (m, FC_FILE, 0, &s);
	if (res != FcResultMatch || !s)  goto fin; 
	ext = rindex((char*)s,'.');
	if (!ext) goto fin;
Enrico Ros's avatar
Enrico Ros committed
1100
	if (!strncasecmp(ext,".ttf",4) || !strncasecmp(ext,".ttc",4)) {
1101
1102
	  dfp = new DisplayFontParam(fontName->copy(), displayFontTT);  
   	  dfp->tt.fileName = new GString((char*)s);
Enrico Ros's avatar
Enrico Ros committed
1103
   	  FcPatternGetInteger(m, FC_INDEX, 0, &(dfp->tt.faceIndex));
1104
1105
1106
1107
1108
1109
1110
1111
1112
	 }  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);
1113
  return dfp;
1114
1115
1116
1117
1118
1119
}

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

1120
  lockGlobalParams;
1121
1122
1123
1124
  if (!fontName ||
      !(dfp = (DisplayFontParam *)displayNamedCIDFonts->lookup(fontName))) {
    dfp = (DisplayFontParam *)displayCIDFonts->lookup(collection);
  }
1125
  unlockGlobalParams;
Enrico Ros's avatar
Enrico Ros committed
1126
  if (!dfp) dfp = getDisplayFont(fontName);
1127
1128
1129
  return dfp;
}

1130
1131
1132
GString *GlobalParams::getPSFile() {
  GString *s;

1133
  lockGlobalParams;
1134
  s = psFile ? psFile->copy() : (GString *)NULL;
1135
  unlockGlobalParams;
1136
1137
1138
1139
1140
1141
  return s;
}

int GlobalParams::getPSPaperWidth() {
  int w;

1142
  lockGlobalParams;
1143
  w = psPaperWidth;
1144
  unlockGlobalParams;
1145
1146
1147
1148
1149
1150
  return w;
}

int GlobalParams::getPSPaperHeight() {
  int h;

1151
  lockGlobalParams;
1152
  h = psPaperHeight;
1153
  unlockGlobalParams;
1154
1155
1156
  return h;
}

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
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
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;
}

1202
1203
1204
GBool GlobalParams::getPSDuplex() {
  GBool d;

1205
  lockGlobalParams;
1206
  d = psDuplex;
1207
  unlockGlobalParams;
1208
1209
1210
1211
1212
1213
  return d;
}

PSLevel GlobalParams::getPSLevel() {
  PSLevel level;

1214
  lockGlobalParams;
1215
  level = psLevel;
1216
  unlockGlobalParams;
1217
1218
1219
  return level;
}

1220
PSFontParam *GlobalParams::getPSFont(GString *fontName) {
1221
1222
1223
1224
1225
1226
  PSFontParam *p;

  lockGlobalParams;
  p = (PSFontParam *)psFonts->lookup(fontName);
  unlockGlobalParams;
  return p;
1227
1228
1229
1230
1231
1232
1233
}

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

1234
  lockGlobalParams;
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
  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;
    }
  }
1256
  unlockGlobalParams;
1257
1258
1259
  return p;
}

1260
1261
1262
GBool GlobalParams::getPSEmbedType1() {
  GBool e;

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

GBool GlobalParams::getPSEmbedTrueType() {
  GBool e;

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

GBool GlobalParams::getPSEmbedCIDPostScript() {
  GBool e;

1281
  lockGlobalParams;
1282
  e = psEmbedCIDPostScript;
1283
  unlockGlobalParams;
1284
1285
1286
1287
1288
1289
  return e;
}

GBool GlobalParams::getPSEmbedCIDTrueType() {
  GBool e;

1290
  lockGlobalParams;
1291
  e = psEmbedCIDTrueType;
1292
  unlockGlobalParams;
1293
1294
1295
1296
1297
1298
  return e;
}

GBool GlobalParams::getPSOPI() {
  GBool opi;

1299
  lockGlobalParams;
1300
  opi = psOPI;
1301
  unlockGlobalParams;
1302
1303
1304
1305
1306
1307
  return opi;
}

GBool GlobalParams::getPSASCIIHex() {
  GBool ah;

1308
  lockGlobalParams;
1309
  ah = psASCIIHex;
1310
  unlockGlobalParams;
1311
1312
1313
  return ah;
}

1314
1315
1316
1317
1318
1319
1320
1321
1322
GString *GlobalParams::getTextEncodingName() {
  GString *s;

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

1323
1324
1325
EndOfLineKind GlobalParams::getTextEOL() {
  EndOfLineKind eol;

1326
  lockGlobalParams;
1327
  eol = textEOL;
1328
  unlockGlobalParams;
1329
1330
1331
  return eol;
}

1332
1333
1334
1335
1336
1337
1338
1339
1340
GBool GlobalParams::getTextPageBreaks() {
  GBool pageBreaks;

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

1341
1342
1343
GBool GlobalParams::getTextKeepTinyChars() {
  GBool tiny;

1344
  lockGlobalParams;
1345
  tiny = textKeepTinyChars;
1346
  unlockGlobalParams;
1347
1348
1349
  return tiny;
}

1350
GString *GlobalParams::findFontFile(GString *fontName, const char **exts) {
1351
  GString *dir, *fileName;
1352
  const char **ext;
1353
1354
1355
  FILE *f;
  int i;

1356
  lockGlobalParams;
1357
1358
  for (i = 0; i < fontDirs->getLength(); ++i) {
    dir = (GString *)fontDirs->get(i);
1359
    for (ext = exts; *ext; ++ext) {
1360
      fileName = appendToPath(dir->copy(), fontName->getCString());
1361
      fileName->append(*ext);
1362
      if ((f = fopen(fileName->getCString(), "rb"))) {
1363
	fclose(f);
1364
	unlockGlobalParams;
1365
1366
1367
1368
1369
	return fileName;
      }
      delete fileName;
    }
  }
1370
  unlockGlobalParams;
1371
1372
1373
  return NULL;
}

1374
1375
1376
GString *GlobalParams::getInitialZoom() {
  GString *s;

1377
  lockGlobalParams;
1378
  s = initialZoom->copy();
1379
  unlockGlobalParams;
1380
1381
1382
  return s;
}

1383
1384
GBool GlobalParams::getEnableT1lib() {
  GBool f;
1385

1386
1387
1388
1389
  lockGlobalParams;
  f = enableT1lib;
  unlockGlobalParams;
  return f;
1390
1391
}

1392
1393
GBool GlobalParams::getEnableFreeType() {
  GBool f;
1394

1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
  lockGlobalParams;
  f = enableFreeType;
  unlockGlobalParams;
  return f;
}


GBool GlobalParams::getAntialias() {
  GBool f;

  lockGlobalParams;
  f = antialias;
  unlockGlobalParams;
  return f;
1409
1410
1411
1412
1413
}

GBool GlobalParams::getMapNumericCharNames() {
  GBool map;

1414
  lockGlobalParams;
1415
  map = mapNumericCharNames;
1416
  unlockGlobalParams;
1417
1418
1419
1420
1421
1422
  return map;
}

GBool GlobalParams::getPrintCommands() {
  GBool p;

1423
  lockGlobalParams;
1424
  p = printCommands;
1425
  unlockGlobalParams;
1426
1427
1428
1429
1430
1431
  return p;
}

GBool GlobalParams::getErrQuiet() {
  GBool q;

1432
  lockGlobalParams;
1433
  q = errQuiet;
1434
  unlockGlobalParams;
1435
1436
1437
  return q;
}

1438
CharCodeToUnicode *GlobalParams::getCIDToUnicode(GString *collection) {
1439
  GString *fileName;
1440