GlobalParams.cc 43.6 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
20
21
// KPDF: additional includes for Qt and Xft
#include <qstring.h>
#include <qregexp.h>
#include <qwindowdefs.h>
#include <X11/Xft/Xft.h>
#include <X11/Xft/XftCompat.h>
22
#include <stdio.h>
23
#include <ctype.h>
24
#if HAVE_PAPER_H
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#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"

41
42
43
44
45
46
47
#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)
48
#else
49
50
51
52
53
54
#  define lockGlobalParams
#  define lockUnicodeMapCache
#  define lockCMapCache
#  define unlockGlobalParams
#  define unlockUnicodeMapCache
#  define unlockCMapCache
55
56
#endif

57
58
59
60
61
62
#include "NameToUnicodeTable.h"
#include "UnicodeMapTables.h"
#include "UTF8.h"

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

63
64
65
66
67
68
#define cidToUnicodeCacheSize     4
#define unicodeToUnicodeCacheSize 4

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

static struct {
69
70
  const char *name;
  const char *fileName;
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
} 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"},
86
  {NULL, NULL}
87
88
};

89
90
// KPDF: removed hardcoded font directories, Xft handles searching
/*static const char *displayFontDirs[] = {
91
92
93
  "/usr/share/ghostscript/fonts",
  "/usr/local/share/ghostscript/fonts",
  "/usr/share/fonts/default/Type1",
94
  "/usr/share/fonts/type1/gsfonts",
95
  "/usr/share/fonts/default/ghostscript/",
96
  NULL
97
98
};*/

99
100
101

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

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
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
//------------------------------------------------------------------------

162
GlobalParams::GlobalParams(const char *cfgFileName) {
163
164
165
166
167
  UnicodeMap *map;
  GString *fileName;
  FILE *f;
  int i;

168
#if MULTITHREADED
169
  gInitMutex(&mutex);
170
171
  gInitMutex(&unicodeMapCacheMutex);
  gInitMutex(&cMapCacheMutex);
172
173
#endif

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

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

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

  line = 1;
331
  while (getLine(buf, sizeof(buf) - 1, f)) {
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347

    // 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));
348
      p1 = *p2 ? p2 + 1 : p2;
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
    }

    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);
372
373
      } else if (!cmd->cmp("unicodeToUnicode")) {
	parseUnicodeToUnicode(tokens, fileName, line);
374
375
376
377
378
379
      } 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);
380
      // KPDF: finding T1 and TTF fonts is handled by Xft now
381
      } else if (!cmd->cmp("displayFontT1")) {
382
//	parseDisplayFont(tokens, displayFonts, displayFontT1, fileName, line);
383
      } else if (!cmd->cmp("displayFontTT")) {
384
//	parseDisplayFont(tokens, displayFonts, displayFontTT, fileName, line);
385
      } else if (!cmd->cmp("displayNamedCIDFontT1")) {
386
	parseDisplayFont(tokens, displayNamedCIDFonts,
387
388
389
390
391
392
393
394
395
396
			 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);
397
398
399
400
401
402
403
404
405
406
407
      } 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);
408
409
410
411
412
413
414
415
416
417
418
      } 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);
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
      } 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);
438
      } else if (!cmd->cmp("textEncoding")) {          
439
440
//	Always use UTF-8 and allow QString do the magic
//	parseTextEncoding(tokens, fileName, line);
441
442
      } else if (!cmd->cmp("textEOL")) {
	parseTextEOL(tokens, fileName, line);
443
444
445
      } else if (!cmd->cmp("textPageBreaks")) {
	parseYesNo("textPageBreaks", &textPageBreaks,
		   tokens, fileName, line);
Wilco Greven's avatar
Wilco Greven committed
446
447
448
      } else if (!cmd->cmp("textKeepTinyChars")) {
	parseYesNo("textKeepTinyChars", &textKeepTinyChars,
		   tokens, fileName, line);
449
450
451
452
      } else if (!cmd->cmp("fontDir")) {
	parseFontDir(tokens, fileName, line);
      } else if (!cmd->cmp("initialZoom")) {
	parseInitialZoom(tokens, fileName, line);
453
454
455
456
457
458
      } 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);
459
      } else if (!cmd->cmp("urlCommand")) {
Wilco Greven's avatar
Wilco Greven committed
460
461
462
	parseCommand("urlCommand", &urlCommand, tokens, fileName, line);
      } else if (!cmd->cmp("movieCommand")) {
	parseCommand("movieCommand", &movieCommand, tokens, fileName, line);
463
464
465
      } else if (!cmd->cmp("mapNumericCharNames")) {
	parseYesNo("mapNumericCharNames", &mapNumericCharNames,
		   tokens, fileName, line);
Wilco Greven's avatar
Wilco Greven committed
466
467
      } else if (!cmd->cmp("printCommands")) {
	parseYesNo("printCommands", &printCommands, tokens, fileName, line);
468
469
470
471
472
      } 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);
473
474
475
476
477
478
479
480
481
482
	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");
	}
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
      }
    }

    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;
512
  while (getLine(buf, sizeof(buf), f)) {
513
514
515
516
517
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
    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());
}

543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
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());
}

560
561
562
563
564
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;

  if (tokens->getLength() < 2) {
    goto err1;
  }
  param = new DisplayFontParam(((GString *)tokens->get(1))->copy(), kind);
614
  
615
616
617
618
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
  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());
658
659
660
    psImageableLLX = psImageableLLY = 0;
    psImageableURX = psPaperWidth;
    psImageableURY = psPaperHeight;
661
662
663
664
665
666
  } else {
    error(-1, "Bad 'psPaperSize' config file command (%s:%d)",
	  fileName->getCString(), line);
  }
}

667
668
669
670
671
672
673
674
675
676
677
678
679
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());
}

680
681
682
683
684
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
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);
}

732
void GlobalParams::parsePSFont16(const char *cmdName, GList *fontList,
733
734
735
736
737
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
				 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();
}

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

825
void GlobalParams::parseYesNo(const char *cmdName, GBool *flag,
826
827
828
829
830
831
832
833
834
			      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);
835
836
837
838
839
840
841
842
  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")) {
843
    *flag = gTrue;
844
  } else if (!strcmp(token, "no")) {
845
846
    *flag = gFalse;
  } else {
847
    return gFalse;
848
  }
849
  return gTrue;
850
851
852
853
}

GlobalParams::~GlobalParams() {
  GHashIter *iter;
854
  GString *key;
855
856
857
858
859
860
861
862
  GList *list;

  freeBuiltinFontTables();

  delete macRomanReverseMap;

  delete nameToUnicode;
  deleteGHash(cidToUnicodes, GString);
863
  deleteGHash(unicodeToUnicodes, GString);
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
  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
882
883
884
  if (movieCommand) {
    delete movieCommand;
  }
885
886
887
888
889
890
891
892

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

  delete cidToUnicodeCache;
893
  delete unicodeToUnicodeCache;
894
895
  delete unicodeMapCache;
  delete cMapCache;
896

897
#if MULTITHREADED
898
  gDestroyMutex(&mutex);
899
900
  gDestroyMutex(&unicodeMapCacheMutex);
  gDestroyMutex(&cMapCacheMutex);
901
#endif
902
903
}

904
905
906
907
908
909
910
//------------------------------------------------------------------------

void GlobalParams::setupBaseFonts(char *dir) {
  GString *fontName;
  GString *fileName;
  FILE *f;
  DisplayFontParam *dfp;
911
  int i/*, j*/;
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928

  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;
      }
    }
929
930
// KPDF: no more searching hardcoded dirs, Xft handles that
/*
931
932
933
934
935
936
937
938
939
940
941
942
#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
943
*/
944
945
946
947
948
949
950
951
952
953
954
    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);
  }
}

955
956
957
958
//------------------------------------------------------------------------
// accessors
//------------------------------------------------------------------------

959
CharCode GlobalParams::getMacRomanCharCode(const char *charName) {
960
  // no need to lock - macRomanReverseMap is constant
961
962
963
  return macRomanReverseMap->lookup(charName);
}

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

969
970
UnicodeMap *GlobalParams::getResidentUnicodeMap(GString *encodingName) {
  UnicodeMap *map;
971

972
973
974
975
976
  lockGlobalParams;
  map = (UnicodeMap *)residentUnicodeMaps->lookup(encodingName);
  unlockGlobalParams;
  if (map) {
    map->incRefCnt();
977
  }
978
  return map;
979
980
981
982
}

FILE *GlobalParams::getUnicodeMapFile(GString *encodingName) {
  GString *fileName;
983
  FILE *f;
984

985
986
987
988
989
  lockGlobalParams;
  if ((fileName = (GString *)unicodeMaps->lookup(encodingName))) {
    f = fopen(fileName->getCString(), "r");
  } else {
    f = NULL;
990
  }
991
992
  unlockGlobalParams;
  return f;
993
994
995
996
997
998
999
1000
1001
}

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

1002
  lockGlobalParams;
1003
  if (!(list = (GList *)cMapDirs->lookup(collection))) {
1004
    unlockGlobalParams;
1005
1006
1007
1008
1009
1010
1011
1012
    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) {
1013
      unlockGlobalParams;
1014
1015
1016
      return f;
    }
  }
1017
  unlockGlobalParams;
1018
1019
1020
1021
1022
1023
1024
1025
  return NULL;
}

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

1026
  lockGlobalParams;
1027
1028
1029
1030
1031
1032
  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) {
1033
      unlockGlobalParams;
1034
1035
1036
      return f;
    }
  }
1037
  unlockGlobalParams;
1038
1039
1040
  return NULL;
}

1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
// 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;
}



1056
DisplayFontParam *GlobalParams::getDisplayFont(GString *fontName) {
1057
  DisplayFontParam *dfp;
1058
1059
1060
1061
1062
  FcPattern *p=0,*m=0;
  FcChar8* s;
  char * ext;
  FcResult res;
 
1063

1064
  lockGlobalParams;
1065
  dfp = (DisplayFontParam *)displayFonts->lookup(fontName);
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
  // 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);
1091
  return dfp;
1092
1093
1094
1095
1096
1097
}

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

1098
  lockGlobalParams;
1099
1100
1101
1102
  if (!fontName ||
      !(dfp = (DisplayFontParam *)displayNamedCIDFonts->lookup(fontName))) {
    dfp = (DisplayFontParam *)displayCIDFonts->lookup(collection);
  }
1103
  unlockGlobalParams;
1104
1105
1106
  return dfp;
}

1107
1108
1109
GString *GlobalParams::getPSFile() {
  GString *s;

1110
  lockGlobalParams;
1111
  s = psFile ? psFile->copy() : (GString *)NULL;
1112
  unlockGlobalParams;
1113
1114
1115
1116
1117
1118
  return s;
}

int GlobalParams::getPSPaperWidth() {
  int w;

1119
  lockGlobalParams;
1120
  w = psPaperWidth;
1121
  unlockGlobalParams;
1122
1123
1124
1125
1126
1127
  return w;
}

int GlobalParams::getPSPaperHeight() {
  int h;

1128
  lockGlobalParams;
1129
  h = psPaperHeight;
1130
  unlockGlobalParams;
1131
1132
1133
  return h;
}

1134
1135
1136
1137
1138
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
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;
}

1179
1180
1181
GBool GlobalParams::getPSDuplex() {
  GBool d;

1182
  lockGlobalParams;
1183
  d = psDuplex;
1184
  unlockGlobalParams;
1185
1186
1187
1188
1189
1190
  return d;
}

PSLevel GlobalParams::getPSLevel() {
  PSLevel level;

1191
  lockGlobalParams;
1192
  level = psLevel;
1193
  unlockGlobalParams;
1194
1195
1196
  return level;
}

1197
PSFontParam *GlobalParams::getPSFont(GString *fontName) {
1198
1199
1200
1201
1202
1203
  PSFontParam *p;

  lockGlobalParams;
  p = (PSFontParam *)psFonts->lookup(fontName);
  unlockGlobalParams;
  return p;
1204
1205
1206
1207
1208
1209
1210
}

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

1211
  lockGlobalParams;
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
  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;
    }
  }
1233
  unlockGlobalParams;
1234
1235
1236
  return p;
}

1237
1238
1239
GBool GlobalParams::getPSEmbedType1() {
  GBool e;

1240
  lockGlobalParams;
1241
  e = psEmbedType1;
1242
  unlockGlobalParams;
1243
1244
1245
1246
1247
1248
  return e;
}

GBool GlobalParams::getPSEmbedTrueType() {
  GBool e;

1249
  lockGlobalParams;
1250
  e = psEmbedTrueType;
1251
  unlockGlobalParams;
1252
1253
1254
1255
1256
1257
  return e;
}

GBool GlobalParams::getPSEmbedCIDPostScript() {
  GBool e;

1258
  lockGlobalParams;
1259
  e = psEmbedCIDPostScript;
1260
  unlockGlobalParams;
1261
1262
1263
1264
1265
1266
  return e;
}

GBool GlobalParams::getPSEmbedCIDTrueType() {
  GBool e;

1267
  lockGlobalParams;
1268
  e = psEmbedCIDTrueType;
1269
  unlockGlobalParams;
1270
1271
1272
1273
1274
1275
  return e;
}

GBool GlobalParams::getPSOPI() {
  GBool opi;

1276
  lockGlobalParams;
1277
  opi = psOPI;
1278
  unlockGlobalParams;
1279
1280
1281
1282
1283
1284
  return opi;
}

GBool GlobalParams::getPSASCIIHex() {
  GBool ah;

1285
  lockGlobalParams;
1286
  ah = psASCIIHex;
1287
  unlockGlobalParams;
1288
1289
1290
  return ah;
}

1291
1292
1293
1294
1295
1296
1297
1298
1299
GString *GlobalParams::getTextEncodingName() {
  GString *s;

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

1300
1301
1302
EndOfLineKind GlobalParams::getTextEOL() {
  EndOfLineKind eol;

1303
  lockGlobalParams;
1304
  eol = textEOL;
1305
  unlockGlobalParams;
1306
1307
1308
  return eol;
}

1309
1310
1311
1312
1313
1314
1315
1316
1317
GBool GlobalParams::getTextPageBreaks() {
  GBool pageBreaks;

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

1318
1319
1320
GBool GlobalParams::getTextKeepTinyChars() {
  GBool tiny;

1321
  lockGlobalParams;
1322
  tiny = textKeepTinyChars;
1323
  unlockGlobalParams;
1324
1325
1326
  return tiny;
}

1327
GString *GlobalParams::findFontFile(GString *fontName, const char **exts) {
1328
  GString *dir, *fileName;
1329
  const char **ext;
1330
1331
1332
  FILE *f;
  int i;

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

1351
1352
1353
GString *GlobalParams::getInitialZoom() {
  GString *s;

1354
  lockGlobalParams;
1355
  s = initialZoom->copy();
1356
  unlockGlobalParams;
1357
1358
1359
  return s;
}

1360
1361
GBool GlobalParams::getEnableT1lib() {
  GBool f;
1362

1363
1364
1365
1366
  lockGlobalParams;
  f = enableT1lib;
  unlockGlobalParams;
  return f;
1367
1368
}

1369
1370
GBool GlobalParams::getEnableFreeType() {
  GBool f;
1371

1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
  lockGlobalParams;
  f = enableFreeType;
  unlockGlobalParams;
  return f;
}


GBool GlobalParams::getAntialias() {
  GBool f;

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

GBool GlobalParams::getMapNumericCharNames() {
  GBool map;

1391
  lockGlobalParams;
1392
  map = mapNumericCharNames;
1393
  unlockGlobalParams;
1394
1395
1396
1397
1398
1399
  return map;
}

GBool GlobalParams::getPrintCommands() {
  GBool p;

1400
  lockGlobalParams;
1401
  p = printCommands;
1402
  unlockGlobalParams;
1403
1404
1405
1406
1407
1408
  return p;
}

GBool GlobalParams::getErrQuiet() {
  GBool q;

1409
  lockGlobalParams;
1410
  q = errQuiet;
1411
  unlockGlobalParams;
1412
1413
1414
  return q;
}

1415
CharCodeToUnicode *GlobalParams::getCIDToUnicode(GString *collection) {
1416
  GString *fileName;
1417
1418
  CharCodeToUnicode *ctu;

1419
1420
1421
1422
1423
1424
1425
1426
  lockGlobalParams;
  if (!(ctu = cidToUnicodeCache->getCharCodeToUnicode(collection))) {
    if ((fileName = (GString *)cidToUnicodes->lookup(collection)) &&
	(ctu = CharCodeToUnicode::parseCIDToUnicode(fileName, collection))) {
      cidToUnicodeCache->add(ctu);
    }
  }
  unlockGlobalParams;
1427
  return ctu;
1428
1429
}

1430
1431
1432
1433
CharCodeToUnicode *GlobalParams::getUnicodeToUnicode(GString *fontName) {
  CharCodeToUnicode *ctu;
  GHashIter *iter;
  GString *fontPattern, *fileName;
1434

1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
  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);
1460
1461
1462
1463
1464
}

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

1465
1466
  if (!(map = getResidentUnicodeMap(encodingName))) {
    lockUnicodeMapCache;
1467
    map = unicodeMapCache->getUnicodeMap(encodingName);
1468
    unlockUnicodeMapCache;
1469
  }
1470
  return map;
1471
1472
1473
}

CMap *GlobalParams::getCMap(GString *collection, GString *cMapName) {
1474
1475
  CMap *cMap;

1476
  lockCMapCache;
1477
  cMap = cMapCache->getCMap(collection, cMapName);
1478
  unlockCMapCache;
1479
  return cMap;
1480
1481
1482
}

UnicodeMap *GlobalParams::getTextEncoding() {
1483
  return getUnicodeMap2(textEncoding);