summaryrefslogtreecommitdiff
path: root/noncore/unsupported/qpdf/xpdf/GlobalParams.cc
Unidiff
Diffstat (limited to 'noncore/unsupported/qpdf/xpdf/GlobalParams.cc') (more/less context) (show whitespace changes)
-rw-r--r--noncore/unsupported/qpdf/xpdf/GlobalParams.cc916
1 files changed, 916 insertions, 0 deletions
diff --git a/noncore/unsupported/qpdf/xpdf/GlobalParams.cc b/noncore/unsupported/qpdf/xpdf/GlobalParams.cc
new file mode 100644
index 0000000..8be58a3
--- a/dev/null
+++ b/noncore/unsupported/qpdf/xpdf/GlobalParams.cc
@@ -0,0 +1,916 @@
1//========================================================================
2//
3// GlobalParams.cc
4//
5// Copyright 2001 Derek B. Noonburg
6//
7//========================================================================
8
9#ifdef __GNUC__
10#pragma implementation
11#endif
12
13#include <aconf.h>
14#include <string.h>
15#include <ctype.h>
16#if HAVE_PAPER_H
17#include <paper.h>
18#endif
19#include "gmem.h"
20#include "GString.h"
21#include "GList.h"
22#include "GHash.h"
23#include "gfile.h"
24#include "Error.h"
25#include "NameToCharCode.h"
26#include "CharCodeToUnicode.h"
27#include "UnicodeMap.h"
28#include "CMap.h"
29#include "BuiltinFontTables.h"
30#include "FontEncodingTables.h"
31#include "GlobalParams.h"
32
33#include "NameToUnicodeTable.h"
34#include "UnicodeMapTables.h"
35#include "DisplayFontTable.h"
36#include "UTF8.h"
37
38//------------------------------------------------------------------------
39
40GlobalParams *globalParams = NULL;
41
42//------------------------------------------------------------------------
43// DisplayFontParam
44//------------------------------------------------------------------------
45
46DisplayFontParam::DisplayFontParam(GString *nameA,
47 DisplayFontParamKind kindA) {
48 name = nameA;
49 kind = kindA;
50 switch (kind) {
51 case displayFontX:
52 x.xlfd = NULL;
53 x.encoding = NULL;
54 break;
55 case displayFontT1:
56 t1.fileName = NULL;
57 break;
58 case displayFontTT:
59 tt.fileName = NULL;
60 break;
61 }
62}
63
64DisplayFontParam::DisplayFontParam(char *nameA, char *xlfdA, char *encodingA) {
65 name = new GString(nameA);
66 kind = displayFontX;
67 x.xlfd = new GString(xlfdA);
68 x.encoding = new GString(encodingA);
69}
70
71DisplayFontParam::~DisplayFontParam() {
72 delete name;
73 switch (kind) {
74 case displayFontX:
75 if (x.xlfd) {
76 delete x.xlfd;
77 }
78 if (x.encoding) {
79 delete x.encoding;
80 }
81 break;
82 case displayFontT1:
83 if (t1.fileName) {
84 delete t1.fileName;
85 }
86 break;
87 case displayFontTT:
88 if (tt.fileName) {
89 delete tt.fileName;
90 }
91 break;
92 }
93}
94
95//------------------------------------------------------------------------
96// PSFontParam
97//------------------------------------------------------------------------
98
99PSFontParam::PSFontParam(GString *pdfFontNameA, GString *psFontNameA) {
100 pdfFontName = pdfFontNameA;
101 psFontName = psFontNameA;
102}
103
104PSFontParam::~PSFontParam() {
105 delete pdfFontName;
106 delete psFontName;
107}
108
109//------------------------------------------------------------------------
110// parsing
111//------------------------------------------------------------------------
112
113GlobalParams::GlobalParams(char *cfgFileName) {
114 UnicodeMap *map;
115 DisplayFontParam *dfp;
116 GString *fileName;
117 FILE *f;
118 char buf[512];
119 int line;
120 GList *tokens;
121 GString *cmd;
122 char *p1, *p2;
123 int i;
124
125 initBuiltinFontTables();
126
127 macRomanReverseMap = new NameToCharCode();
128 for (i = 0; i < 256; ++i) {
129 if (macRomanEncoding[i]) {
130 macRomanReverseMap->add(macRomanEncoding[i], (CharCode)i);
131 }
132 }
133
134 nameToUnicode = new NameToCharCode();
135 cidToUnicodes = new GHash(gTrue);
136 residentUnicodeMaps = new GHash();
137 unicodeMaps = new GHash(gTrue);
138 cMapDirs = new GHash(gTrue);
139 toUnicodeDirs = new GList();
140 displayFonts = new GHash();
141 displayCIDFonts = new GHash();
142#if HAVE_PAPER_H
143 const struct paper *paperType;
144 paperinit();
145 paperType = paperinfo(systempapername());
146 psPaperWidth = (int)paperpswidth(paperType);
147 psPaperHeight = (int)paperpsheight(paperType);
148 paperdone();
149#else
150 psPaperWidth = defPaperWidth;
151 psPaperHeight = defPaperHeight;
152#endif
153 psDuplex = gFalse;
154 psLevel = psLevel2;
155 psFile = NULL;
156 psFonts = new GHash();
157 psEmbedType1 = gTrue;
158 psEmbedTrueType = gTrue;
159 psOPI = gFalse;
160 textEncoding = new GString("Latin1");
161#if defined(WIN32)
162 textEOL = eolDOS;
163#elif defined(MACOS)
164 textEOL = eolMac;
165#else
166 textEOL = eolUnix;
167#endif
168 fontDirs = new GList();
169 t1libControl = fontRastAALow;
170 freetypeControl = fontRastAALow;
171 urlCommand = NULL;
172 mapNumericCharNames = gTrue;
173 errQuiet = gFalse;
174
175 cidToUnicodeCache = new CIDToUnicodeCache();
176 unicodeMapCache = new UnicodeMapCache();
177 cMapCache = new CMapCache();
178
179 // set up the initial nameToUnicode table
180 for (i = 0; nameToUnicodeTab[i].name; ++i) {
181 nameToUnicode->add(nameToUnicodeTab[i].name, nameToUnicodeTab[i].u);
182 }
183
184 // set up the residentUnicodeMaps table
185 map = new UnicodeMap("Latin1", latin1UnicodeMapRanges, latin1UnicodeMapLen);
186 residentUnicodeMaps->add(map->getEncodingName(), map);
187 map = new UnicodeMap("ASCII7", ascii7UnicodeMapRanges, ascii7UnicodeMapLen);
188 residentUnicodeMaps->add(map->getEncodingName(), map);
189 map = new UnicodeMap("Symbol", symbolUnicodeMapRanges, symbolUnicodeMapLen);
190 residentUnicodeMaps->add(map->getEncodingName(), map);
191 map = new UnicodeMap("ZapfDingbats", zapfDingbatsUnicodeMapRanges,
192 zapfDingbatsUnicodeMapLen);
193 residentUnicodeMaps->add(map->getEncodingName(), map);
194 map = new UnicodeMap("UTF-8", &mapUTF8);
195 residentUnicodeMaps->add(map->getEncodingName(), map);
196
197 // default displayFonts table
198 for (i = 0; displayFontTab[i].name; ++i) {
199 dfp = new DisplayFontParam(displayFontTab[i].name,
200 displayFontTab[i].xlfd,
201 displayFontTab[i].encoding);
202 displayFonts->add(dfp->name, dfp);
203 }
204
205 // look for a user config file, then a system-wide config file
206 f = NULL;
207 fileName = NULL;
208 if (cfgFileName && cfgFileName[0]) {
209 fileName = new GString(cfgFileName);
210 if (!(f = fopen(fileName->getCString(), "r"))) {
211 delete fileName;
212 }
213 }
214 if (!f) {
215 fileName = appendToPath(getHomeDir(), xpdfUserConfigFile);
216 if (!(f = fopen(fileName->getCString(), "r"))) {
217 delete fileName;
218 }
219 }
220 if (!f) {
221#if defined(WIN32) && !defined(__CYGWIN32__)
222 i = GetModuleFileName(NULL, buf, sizeof(buf));
223 if (i <= 0 || i >= sizeof(buf)) {
224 // error or path too long for buffer - just use the current dir
225 buf[i] = '\0';
226 }
227 fileName = grabPath(buf);
228 appendToPath(fileName, xpdfSysConfigFile);
229#else
230 fileName = new GString(xpdfSysConfigFile);
231#endif
232 if (!(f = fopen(fileName->getCString(), "r"))) {
233 delete fileName;
234 }
235 }
236 if (f) {
237 line = 1;
238 while (fgets(buf, sizeof(buf) - 1, f)) {
239
240 // break the line into tokens
241 tokens = new GList();
242 p1 = buf;
243 while (*p1) {
244 for (; *p1 && isspace(*p1); ++p1) ;
245 if (!*p1) {
246 break;
247 }
248 if (*p1 == '"' || *p1 == '\'') {
249 for (p2 = p1 + 1; *p2 && *p2 != *p1; ++p2) ;
250 ++p1;
251 } else {
252 for (p2 = p1 + 1; *p2 && !isspace(*p2); ++p2) ;
253 }
254 tokens->append(new GString(p1, p2 - p1));
255 p1 = p2 + 1;
256 }
257
258 if (tokens->getLength() > 0 &&
259 ((GString *)tokens->get(0))->getChar(0) != '#') {
260 cmd = (GString *)tokens->get(0);
261 if (!cmd->cmp("nameToUnicode")) {
262 parseNameToUnicode(tokens, fileName, line);
263 } else if (!cmd->cmp("cidToUnicode")) {
264 parseCIDToUnicode(tokens, fileName, line);
265 } else if (!cmd->cmp("unicodeMap")) {
266 parseUnicodeMap(tokens, fileName, line);
267 } else if (!cmd->cmp("cMapDir")) {
268 parseCMapDir(tokens, fileName, line);
269 } else if (!cmd->cmp("toUnicodeDir")) {
270 parseToUnicodeDir(tokens, fileName, line);
271 } else if (!cmd->cmp("displayFontX")) {
272 parseDisplayFont(tokens, gFalse, displayFontX, fileName, line);
273 } else if (!cmd->cmp("displayFontT1")) {
274 parseDisplayFont(tokens, gFalse, displayFontT1, fileName, line);
275 } else if (!cmd->cmp("displayFontTT")) {
276 parseDisplayFont(tokens, gFalse, displayFontTT, fileName, line);
277 } else if (!cmd->cmp("displayCIDFontX")) {
278 parseDisplayFont(tokens, gTrue, displayFontX, fileName, line);
279 } else if (!cmd->cmp("psFile")) {
280 parsePSFile(tokens, fileName, line);
281 } else if (!cmd->cmp("psFont")) {
282 parsePSFont(tokens, fileName, line);
283 } else if (!cmd->cmp("psPaperSize")) {
284 parsePSPaperSize(tokens, fileName, line);
285 } else if (!cmd->cmp("psDuplex")) {
286 parseYesNo("psDuplex", &psDuplex, tokens, fileName, line);
287 } else if (!cmd->cmp("psLevel")) {
288 parsePSLevel(tokens, fileName, line);
289 } else if (!cmd->cmp("psEmbedType1")) {
290 parseYesNo("psEmbedType1", &psEmbedType1, tokens, fileName, line);
291 } else if (!cmd->cmp("psEmbedTrueType")) {
292 parseYesNo("psEmbedTrueType", &psEmbedTrueType,
293 tokens, fileName, line);
294 } else if (!cmd->cmp("psOPI")) {
295 parseYesNo("psOPI", &psOPI, tokens, fileName, line);
296 } else if (!cmd->cmp("textEncoding")) {
297 parseTextEncoding(tokens, fileName, line);
298 } else if (!cmd->cmp("textEOL")) {
299 parseTextEOL(tokens, fileName, line);
300 } else if (!cmd->cmp("fontDir")) {
301 parseFontDir(tokens, fileName, line);
302 } else if (!cmd->cmp("t1libControl")) {
303 parseFontRastControl("t1libControl", &t1libControl,
304 tokens, fileName, line);
305 } else if (!cmd->cmp("freetypeControl")) {
306 parseFontRastControl("freetypeControl", &freetypeControl,
307 tokens, fileName, line);
308 } else if (!cmd->cmp("urlCommand")) {
309 parseURLCommand(tokens, fileName, line);
310 } else if (!cmd->cmp("mapNumericCharNames")) {
311 parseYesNo("mapNumericCharNames", &mapNumericCharNames,
312 tokens, fileName, line);
313 } else if (!cmd->cmp("errQuiet")) {
314 parseYesNo("errQuiet", &errQuiet, tokens, fileName, line);
315 } else if (!cmd->cmp("fontpath") || !cmd->cmp("fontmap")) {
316 error(-1, "Unknown config file command");
317 error(-1, "-- the config file format has changed since Xpdf 0.9x");
318 } else {
319 error(-1, "Unknown config file command '%s' (%s:%d)",
320 cmd->getCString(), fileName->getCString(), line);
321 }
322 }
323
324 deleteGList(tokens, GString);
325 ++line;
326 }
327
328 delete fileName;
329 }
330}
331
332void GlobalParams::parseNameToUnicode(GList *tokens, GString *fileName,
333 int line) {
334 GString *name;
335 char *tok1, *tok2;
336 FILE *f;
337 char buf[256];
338 int line2;
339 Unicode u;
340
341 if (tokens->getLength() != 2) {
342 error(-1, "Bad 'nameToUnicode' config file command (%s:%d)",
343 fileName->getCString(), line);
344 return;
345 }
346 name = (GString *)tokens->get(1);
347 if (!(f = fopen(name->getCString(), "r"))) {
348 error(-1, "Couldn't open 'nameToUnicode' file '%s'",
349 name->getCString());
350 return;
351 }
352 line2 = 1;
353 while (fgets(buf, sizeof(buf), f)) {
354 tok1 = strtok(buf, " \t\r\n");
355 tok2 = strtok(NULL, " \t\r\n");
356 if (tok1 && tok2) {
357 sscanf(tok1, "%x", &u);
358 nameToUnicode->add(tok2, u);
359 } else {
360 error(-1, "Bad line in 'nameToUnicode' file (%s:%d)", name, line2);
361 }
362 ++line2;
363 }
364 fclose(f);
365}
366
367void GlobalParams::parseCIDToUnicode(GList *tokens, GString *fileName,
368 int line) {
369 GString *collection, *name, *old;
370
371 if (tokens->getLength() != 3) {
372 error(-1, "Bad 'cidToUnicode' config file command (%s:%d)",
373 fileName->getCString(), line);
374 return;
375 }
376 collection = (GString *)tokens->get(1);
377 name = (GString *)tokens->get(2);
378 if ((old = (GString *)cidToUnicodes->remove(collection))) {
379 delete old;
380 }
381 cidToUnicodes->add(collection->copy(), name->copy());
382}
383
384void GlobalParams::parseUnicodeMap(GList *tokens, GString *fileName,
385 int line) {
386 GString *encodingName, *name, *old;
387
388 if (tokens->getLength() != 3) {
389 error(-1, "Bad 'unicodeMap' config file command (%s:%d)",
390 fileName->getCString(), line);
391 return;
392 }
393 encodingName = (GString *)tokens->get(1);
394 name = (GString *)tokens->get(2);
395 if ((old = (GString *)unicodeMaps->remove(encodingName))) {
396 delete old;
397 }
398 unicodeMaps->add(encodingName->copy(), name->copy());
399}
400
401void GlobalParams::parseCMapDir(GList *tokens, GString *fileName, int line) {
402 GString *collection, *dir;
403 GList *list;
404
405 if (tokens->getLength() != 3) {
406 error(-1, "Bad 'cMapDir' config file command (%s:%d)",
407 fileName->getCString(), line);
408 return;
409 }
410 collection = (GString *)tokens->get(1);
411 dir = (GString *)tokens->get(2);
412 if (!(list = (GList *)cMapDirs->lookup(collection))) {
413 list = new GList();
414 cMapDirs->add(collection->copy(), list);
415 }
416 list->append(dir->copy());
417}
418
419void GlobalParams::parseToUnicodeDir(GList *tokens, GString *fileName,
420 int line) {
421 if (tokens->getLength() != 2) {
422 error(-1, "Bad 'toUnicodeDir' config file command (%s:%d)",
423 fileName->getCString(), line);
424 return;
425 }
426 toUnicodeDirs->append(((GString *)tokens->get(1))->copy());
427}
428
429void GlobalParams::parseDisplayFont(GList *tokens, GBool isCID,
430 DisplayFontParamKind kind,
431 GString *fileName, int line) {
432 DisplayFontParam *param, *old;
433
434 if (tokens->getLength() < 2) {
435 goto err1;
436 }
437 param = new DisplayFontParam(((GString *)tokens->get(1))->copy(), kind);
438
439 switch (kind) {
440 case displayFontX:
441 if (tokens->getLength() != 4) {
442 goto err2;
443 }
444 param->x.xlfd = ((GString *)tokens->get(2))->copy();
445 param->x.encoding = ((GString *)tokens->get(3))->copy();
446 break;
447 case displayFontT1:
448 if (tokens->getLength() != 3) {
449 goto err2;
450 }
451 param->t1.fileName = ((GString *)tokens->get(2))->copy();
452 break;
453 case displayFontTT:
454 if (tokens->getLength() != 3) {
455 goto err2;
456 }
457 param->tt.fileName = ((GString *)tokens->get(2))->copy();
458 break;
459 }
460
461 if (isCID) {
462 if ((old = (DisplayFontParam *)displayCIDFonts->remove(param->name))) {
463 delete old;
464 }
465 displayCIDFonts->add(param->name, param);
466 } else {
467 if ((old = (DisplayFontParam *)displayFonts->remove(param->name))) {
468 delete old;
469 }
470 displayFonts->add(param->name, param);
471 }
472 return;
473
474 err2:
475 delete param;
476 err1:
477 error(-1, "Bad 'displayFont...' config file command (%s:%d)",
478 fileName->getCString(), line);
479}
480
481void GlobalParams::parsePSPaperSize(GList *tokens, GString *fileName,
482 int line) {
483 GString *tok;
484
485 if (tokens->getLength() == 2) {
486 tok = (GString *)tokens->get(1);
487 if (!setPSPaperSize(tok->getCString())) {
488 error(-1, "Bad 'psPaperSize' config file command (%s:%d)",
489 fileName->getCString(), line);
490 }
491 } else if (tokens->getLength() == 3) {
492 tok = (GString *)tokens->get(1);
493 psPaperWidth = atoi(tok->getCString());
494 tok = (GString *)tokens->get(2);
495 psPaperHeight = atoi(tok->getCString());
496 } else {
497 error(-1, "Bad 'psPaperSize' config file command (%s:%d)",
498 fileName->getCString(), line);
499 }
500}
501
502void GlobalParams::parsePSLevel(GList *tokens, GString *fileName, int line) {
503 GString *tok;
504
505 if (tokens->getLength() != 2) {
506 error(-1, "Bad 'psLevel' config file command (%s:%d)",
507 fileName->getCString(), line);
508 return;
509 }
510 tok = (GString *)tokens->get(1);
511 if (!tok->cmp("level1")) {
512 psLevel = psLevel1;
513 } else if (!tok->cmp("level1sep")) {
514 psLevel = psLevel1Sep;
515 } else if (!tok->cmp("level2")) {
516 psLevel = psLevel2;
517 } else if (!tok->cmp("level2sep")) {
518 psLevel = psLevel2Sep;
519 } else {
520 error(-1, "Bad 'psLevel' config file command (%s:%d)",
521 fileName->getCString(), line);
522 }
523}
524
525void GlobalParams::parsePSFile(GList *tokens, GString *fileName, int line) {
526 if (tokens->getLength() != 2) {
527 error(-1, "Bad 'psFile' config file command (%s:%d)",
528 fileName->getCString(), line);
529 return;
530 }
531 if (psFile) {
532 delete psFile;
533 }
534 psFile = ((GString *)tokens->get(1))->copy();
535}
536
537void GlobalParams::parsePSFont(GList *tokens, GString *fileName, int line) {
538 PSFontParam *param;
539
540 if (tokens->getLength() != 3) {
541 error(-1, "Bad 'psFont' config file command (%s:%d)",
542 fileName->getCString(), line);
543 return;
544 }
545 param = new PSFontParam(((GString *)tokens->get(1))->copy(),
546 ((GString *)tokens->get(2))->copy());
547 psFonts->add(param->pdfFontName, param);
548}
549
550void GlobalParams::parseTextEncoding(GList *tokens, GString *fileName,
551 int line) {
552 if (tokens->getLength() != 2) {
553 error(-1, "Bad 'textEncoding' config file command (%s:%d)",
554 fileName->getCString(), line);
555 return;
556 }
557 delete textEncoding;
558 textEncoding = ((GString *)tokens->get(1))->copy();
559}
560
561void GlobalParams::parseTextEOL(GList *tokens, GString *fileName, int line) {
562 GString *tok;
563
564 if (tokens->getLength() != 2) {
565 error(-1, "Bad 'textEOL' config file command (%s:%d)",
566 fileName->getCString(), line);
567 return;
568 }
569 tok = (GString *)tokens->get(1);
570 if (!tok->cmp("unix")) {
571 textEOL = eolUnix;
572 } else if (!tok->cmp("dos")) {
573 textEOL = eolDOS;
574 } else if (!tok->cmp("mac")) {
575 textEOL = eolMac;
576 } else {
577 error(-1, "Bad 'textEOL' config file command (%s:%d)",
578 fileName->getCString(), line);
579 }
580}
581
582void GlobalParams::parseFontDir(GList *tokens, GString *fileName, int line) {
583 if (tokens->getLength() != 2) {
584 error(-1, "Bad 'fontDir' config file command (%s:%d)",
585 fileName->getCString(), line);
586 return;
587 }
588 fontDirs->append(((GString *)tokens->get(1))->copy());
589}
590
591void GlobalParams::parseURLCommand(GList *tokens, GString *fileName,
592 int line) {
593 if (tokens->getLength() != 2) {
594 error(-1, "Bad 'urlCommand' config file command (%s:%d)",
595 fileName->getCString(), line);
596 return;
597 }
598 if (urlCommand) {
599 delete urlCommand;
600 }
601 urlCommand = ((GString *)tokens->get(1))->copy();
602}
603
604void GlobalParams::parseFontRastControl(char *cmdName, FontRastControl *val,
605 GList *tokens, GString *fileName,
606 int line) {
607 GString *tok;
608
609 if (tokens->getLength() != 2) {
610 error(-1, "Bad '%s' config file command (%s:%d)",
611 cmdName, fileName->getCString(), line);
612 return;
613 }
614 tok = (GString *)tokens->get(1);
615 if (!setFontRastControl(val, tok->getCString())) {
616 error(-1, "Bad '%s' config file command (%s:%d)",
617 cmdName, fileName->getCString(), line);
618 }
619}
620
621void GlobalParams::parseYesNo(char *cmdName, GBool *flag,
622 GList *tokens, GString *fileName, int line) {
623 GString *tok;
624
625 if (tokens->getLength() != 2) {
626 error(-1, "Bad '%s' config file command (%s:%d)",
627 cmdName, fileName->getCString(), line);
628 return;
629 }
630 tok = (GString *)tokens->get(1);
631 if (!tok->cmp("yes")) {
632 *flag = gTrue;
633 } else if (!tok->cmp("no")) {
634 *flag = gFalse;
635 } else {
636 error(-1, "Bad '%s' config file command (%s:%d)",
637 cmdName, fileName->getCString(), line);
638 }
639}
640
641GlobalParams::~GlobalParams() {
642 GHashIter *iter;
643 GString *key;
644 GList *list;
645
646 freeBuiltinFontTables();
647
648 delete macRomanReverseMap;
649
650 delete nameToUnicode;
651 deleteGHash(cidToUnicodes, GString);
652 deleteGHash(residentUnicodeMaps, UnicodeMap);
653 deleteGHash(unicodeMaps, GString);
654 deleteGList(toUnicodeDirs, GString);
655 deleteGHash(displayFonts, DisplayFontParam);
656 deleteGHash(displayCIDFonts, DisplayFontParam);
657 if (psFile) {
658 delete psFile;
659 }
660 deleteGHash(psFonts, PSFontParam);
661 delete textEncoding;
662 deleteGList(fontDirs, GString);
663 if (urlCommand) {
664 delete urlCommand;
665 }
666
667 cMapDirs->startIter(&iter);
668 while (cMapDirs->getNext(&iter, &key, (void **)&list)) {
669 deleteGList(list, GString);
670 }
671 delete cMapDirs;
672
673 delete cidToUnicodeCache;
674 delete unicodeMapCache;
675 delete cMapCache;
676}
677
678//------------------------------------------------------------------------
679// accessors
680//------------------------------------------------------------------------
681
682CharCode GlobalParams::getMacRomanCharCode(char *charName) {
683 return macRomanReverseMap->lookup(charName);
684}
685
686Unicode GlobalParams::mapNameToUnicode(char *charName) {
687 return nameToUnicode->lookup(charName);
688}
689
690FILE *GlobalParams::getCIDToUnicodeFile(GString *collection) {
691 GString *fileName;
692
693 if (!(fileName = (GString *)cidToUnicodes->lookup(collection))) {
694 return NULL;
695 }
696 return fopen(fileName->getCString(), "r");
697}
698
699UnicodeMap *GlobalParams::getResidentUnicodeMap(GString *encodingName) {
700 return (UnicodeMap *)residentUnicodeMaps->lookup(encodingName);
701}
702
703FILE *GlobalParams::getUnicodeMapFile(GString *encodingName) {
704 GString *fileName;
705
706 if (!(fileName = (GString *)unicodeMaps->lookup(encodingName))) {
707 return NULL;
708 }
709 return fopen(fileName->getCString(), "r");
710}
711
712FILE *GlobalParams::findCMapFile(GString *collection, GString *cMapName) {
713 GList *list;
714 GString *dir;
715 GString *fileName;
716 FILE *f;
717 int i;
718
719 if (!(list = (GList *)cMapDirs->lookup(collection))) {
720 return NULL;
721 }
722 for (i = 0; i < list->getLength(); ++i) {
723 dir = (GString *)list->get(i);
724 fileName = appendToPath(dir->copy(), cMapName->getCString());
725 f = fopen(fileName->getCString(), "r");
726 delete fileName;
727 if (f) {
728 return f;
729 }
730 }
731 return NULL;
732}
733
734FILE *GlobalParams::findToUnicodeFile(GString *name) {
735 GString *dir, *fileName;
736 FILE *f;
737 int i;
738
739 for (i = 0; i < toUnicodeDirs->getLength(); ++i) {
740 dir = (GString *)toUnicodeDirs->get(i);
741 fileName = appendToPath(dir->copy(), name->getCString());
742 f = fopen(fileName->getCString(), "r");
743 delete fileName;
744 if (f) {
745 return f;
746 }
747 }
748 return NULL;
749}
750
751DisplayFontParam *GlobalParams::getDisplayFont(GString *fontName) {
752 return (DisplayFontParam *)displayFonts->lookup(fontName);
753}
754
755DisplayFontParam *GlobalParams::getDisplayCIDFont(GString *collection) {
756 return (DisplayFontParam *)displayCIDFonts->lookup(collection);
757}
758
759PSFontParam *GlobalParams::getPSFont(GString *fontName) {
760 return (PSFontParam *)psFonts->lookup(fontName);
761}
762
763GString *GlobalParams::findFontFile(GString *fontName,
764 char *ext1, char *ext2) {
765 GString *dir, *fileName;
766 FILE *f;
767 int i;
768
769 for (i = 0; i < fontDirs->getLength(); ++i) {
770 dir = (GString *)fontDirs->get(i);
771 if (ext1) {
772 fileName = appendToPath(dir->copy(), fontName->getCString());
773 fileName->append(ext1);
774 if ((f = fopen(fileName->getCString(), "r"))) {
775 fclose(f);
776 return fileName;
777 }
778 delete fileName;
779 }
780 if (ext2) {
781 fileName = appendToPath(dir->copy(), fontName->getCString());
782 fileName->append(ext2);
783 if ((f = fopen(fileName->getCString(), "r"))) {
784 fclose(f);
785 return fileName;
786 }
787 delete fileName;
788 }
789 }
790 return NULL;
791}
792
793CharCodeToUnicode *GlobalParams::getCIDToUnicode(GString *collection) {
794 return cidToUnicodeCache->getCIDToUnicode(collection);
795}
796
797UnicodeMap *GlobalParams::getUnicodeMap(GString *encodingName) {
798 UnicodeMap *map;
799
800 if ((map = getResidentUnicodeMap(encodingName))) {
801 map->incRefCnt();
802 return map;
803 }
804 return unicodeMapCache->getUnicodeMap(encodingName);
805}
806
807CMap *GlobalParams::getCMap(GString *collection, GString *cMapName) {
808 return cMapCache->getCMap(collection, cMapName);
809}
810
811UnicodeMap *GlobalParams::getTextEncoding() {
812 return getUnicodeMap(textEncoding);
813}
814
815//------------------------------------------------------------------------
816// functions to set parameters
817//------------------------------------------------------------------------
818
819void GlobalParams::setPSFile(char *file) {
820 if (psFile) {
821 delete psFile;
822 }
823 psFile = new GString(file);
824}
825
826GBool GlobalParams::setPSPaperSize(char *size) {
827 if (!strcmp(size, "letter")) {
828 psPaperWidth = 612;
829 psPaperHeight = 792;
830 } else if (!strcmp(size, "legal")) {
831 psPaperWidth = 612;
832 psPaperHeight = 1008;
833 } else if (!strcmp(size, "A4")) {
834 psPaperWidth = 595;
835 psPaperHeight = 842;
836 } else if (!strcmp(size, "A3")) {
837 psPaperWidth = 842;
838 psPaperHeight = 1190;
839 } else {
840 return gFalse;
841 }
842 return gTrue;
843}
844
845void GlobalParams::setPSPaperWidth(int width) {
846 psPaperWidth = width;
847}
848
849void GlobalParams::setPSPaperHeight(int height) {
850 psPaperHeight = height;
851}
852
853void GlobalParams::setPSDuplex(GBool duplex) {
854 psDuplex = duplex;
855}
856
857void GlobalParams::setPSLevel(PSLevel level) {
858 psLevel = level;
859}
860
861void GlobalParams::setPSEmbedType1(GBool embed) {
862 psEmbedType1 = embed;
863}
864
865void GlobalParams::setPSEmbedTrueType(GBool embed) {
866 psEmbedTrueType = embed;
867}
868
869void GlobalParams::setPSOPI(GBool opi) {
870 psOPI = opi;
871}
872
873void GlobalParams::setTextEncoding(char *encodingName) {
874 delete textEncoding;
875 textEncoding = new GString(encodingName);
876}
877
878GBool GlobalParams::setTextEOL(char *s) {
879 if (!strcmp(s, "unix")) {
880 textEOL = eolUnix;
881 } else if (!strcmp(s, "dos")) {
882 textEOL = eolDOS;
883 } else if (!strcmp(s, "mac")) {
884 textEOL = eolMac;
885 } else {
886 return gFalse;
887 }
888 return gTrue;
889}
890
891GBool GlobalParams::setT1libControl(char *s) {
892 return setFontRastControl(&t1libControl, s);
893}
894
895GBool GlobalParams::setFreeTypeControl(char *s) {
896 return setFontRastControl(&freetypeControl, s);
897}
898
899GBool GlobalParams::setFontRastControl(FontRastControl *val, char *s) {
900 if (!strcmp(s, "none")) {
901 *val = fontRastNone;
902 } else if (!strcmp(s, "plain")) {
903 *val = fontRastPlain;
904 } else if (!strcmp(s, "low")) {
905 *val = fontRastAALow;
906 } else if (!strcmp(s, "high")) {
907 *val = fontRastAAHigh;
908 } else {
909 return gFalse;
910 }
911 return gTrue;
912}
913
914void GlobalParams::setErrQuiet(GBool errQuietA) {
915 errQuiet = errQuietA;
916}