GlobalParams.h
1//========================================================================
2//
3// GlobalParams.h
4//
5// Copyright 2001-2002 Glyph & Cog, LLC
6//
7//========================================================================
8
9#ifndef GLOBALPARAMS_H
10#define GLOBALPARAMS_H
11
12#include <aconf.h>
13
14#ifdef USE_GCC_PRAGMAS
15#pragma interface
16#endif
17
18#include <stdio.h>
19#include "gtypes.h"
20#include "CharTypes.h"
21
22class GString;
23class GList;
24class GHash;
25class NameToCharCode;
26class CharCodeToUnicode;
27class CIDToUnicodeCache;
28class UnicodeMap;
29class UnicodeMapCache;
30class CMap;
31class CMapCache;
32class GlobalParams;
33
34//------------------------------------------------------------------------
35
36// The global parameters object.
37extern GlobalParams *globalParams;
38
39//------------------------------------------------------------------------
40
41enum DisplayFontParamKind {
42 displayFontX,
43 displayFontT1,
44 displayFontTT
45};
46
47class DisplayFontParam {
48public:
49
50 GString *name; // font name for 8-bit fonts and named
51 // CID fonts; collection name for
52 // generic CID fonts
53 DisplayFontParamKind kind;
54 union {
55 struct {
56 GString *xlfd;
57 GString *encoding;
58 } x;
59 struct {
60 GString *fileName;
61 } t1;
62 struct {
63 GString *fileName;
64 } tt;
65 };
66
67 DisplayFontParam(GString *nameA, DisplayFontParamKind kindA);
68 DisplayFontParam(const char *nameA, const char *xlfdA, const char *encodingA);
69 ~DisplayFontParam();
70};
71
72// Font rasterizer control.
73enum FontRastControl {
74 fontRastNone, // don't use this rasterizer
75 fontRastPlain, // use it, without anti-aliasing
76 fontRastAALow, // use it, with low-level anti-aliasing
77 fontRastAAHigh // use it, with high-level anti-aliasing
78};
79
80//------------------------------------------------------------------------
81
82class PSFontParam {
83public:
84
85 GString *pdfFontName; // PDF font name for 8-bit fonts and
86 // named 16-bit fonts; char collection
87 // name for generic 16-bit fonts
88 int wMode; // writing mode (0=horiz, 1=vert) for
89 // 16-bit fonts
90 GString *psFontName; // PostScript font name
91 GString *encoding; // encoding, for 16-bit fonts only
92
93 PSFontParam(GString *pdfFontNameA, int wModeA,
94 GString *psFontNameA, GString *encodingA);
95 ~PSFontParam();
96};
97
98//------------------------------------------------------------------------
99
100enum PSLevel {
101 psLevel1,
102 psLevel1Sep,
103 psLevel2,
104 psLevel2Sep,
105 psLevel3,
106 psLevel3Sep
107};
108
109//------------------------------------------------------------------------
110
111enum EndOfLineKind {
112 eolUnix, // LF
113 eolDOS, // CR+LF
114 eolMac // CR
115};
116
117//------------------------------------------------------------------------
118
119class GlobalParams {
120public:
121
122 // Initialize the global parameters by attempting to read a config
123 // file.
124 GlobalParams(const char *cfgFileName);
125
126 ~GlobalParams();
127
128 //----- accessors
129
130 CharCode getMacRomanCharCode(const char *charName);
131
132 Unicode mapNameToUnicode(const char *charName);
133 FILE *getCIDToUnicodeFile(const GString *collection);
134 UnicodeMap *getResidentUnicodeMap(const GString *encodingName);
135 FILE *getUnicodeMapFile(const GString *encodingName);
136 FILE *findCMapFile(const GString *collection, const GString *cMapName);
137 FILE *findToUnicodeFile(const GString *name);
138 DisplayFontParam *getDisplayFont(const GString *fontName);
139 DisplayFontParam *getDisplayCIDFont(const GString *fontName,
140 const GString *collection);
141 GString *getPSFile() { return psFile; }
142 int getPSPaperWidth() { return psPaperWidth; }
143 int getPSPaperHeight() { return psPaperHeight; }
144 GBool getPSDuplex() { return psDuplex; }
145 PSLevel getPSLevel() { return psLevel; }
146 PSFontParam *getPSFont(GString *fontName);
147 PSFontParam *getPSFont16(GString *fontName, GString *collection, int wMode);
148 GBool getPSEmbedType1() { return psEmbedType1; }
149 GBool getPSEmbedTrueType() { return psEmbedTrueType; }
150 GBool getPSEmbedCIDPostScript() { return psEmbedCIDPostScript; }
151 GBool getPSEmbedCIDTrueType() { return psEmbedCIDTrueType; }
152 GBool getPSOPI() { return psOPI; }
153 GBool getPSASCIIHex() { return psASCIIHex; }
154 GString *getTextEncodingName() { return textEncoding; }
155 EndOfLineKind getTextEOL() { return textEOL; }
156 GBool getTextKeepTinyChars() { return textKeepTinyChars; }
157 GString *findFontFile(const GString *fontName, const char *ext1, const char *ext2);
158 GString *getInitialZoom() { return initialZoom; }
159 FontRastControl getT1libControl() { return t1libControl; }
160 FontRastControl getFreeTypeControl() { return freetypeControl; }
161 GString *getURLCommand() { return urlCommand; }
162 GString *getMovieCommand() { return movieCommand; }
163 GBool getMapNumericCharNames() { return mapNumericCharNames; }
164 GBool getPrintCommands() { return printCommands; }
165 GBool getErrQuiet() { return errQuiet; }
166
167 CharCodeToUnicode *getCIDToUnicode(GString *collection);
168 UnicodeMap *getUnicodeMap(GString *encodingName);
169 CMap *getCMap(GString *collection, GString *cMapName);
170 UnicodeMap *getTextEncoding();
171
172 //----- functions to set parameters
173
174 void addDisplayFont(DisplayFontParam *param);
175 void setPSFile(char *file);
176 GBool setPSPaperSize(char *size);
177 void setPSPaperWidth(int width);
178 void setPSPaperHeight(int height);
179 void setPSDuplex(GBool duplex);
180 void setPSLevel(PSLevel level);
181 void setPSEmbedType1(GBool embed);
182 void setPSEmbedTrueType(GBool embed);
183 void setPSEmbedCIDPostScript(GBool embed);
184 void setPSEmbedCIDTrueType(GBool embed);
185 void setPSOPI(GBool opi);
186 void setPSASCIIHex(GBool hex);
187 void setTextEncoding(char *encodingName);
188 GBool setTextEOL(char *s);
189 void setTextKeepTinyChars(GBool keep);
190 void setInitialZoom(char *s);
191 GBool setT1libControl(char *s);
192 GBool setFreeTypeControl(char *s);
193 void setMapNumericCharNames(GBool map);
194 void setPrintCommands(GBool printCommandsA);
195 void setErrQuiet(GBool errQuietA);
196
197private:
198
199 void parseFile(GString *fileName, FILE *f);
200 void parseNameToUnicode(GList *tokens, GString *fileName, int line);
201 void parseCIDToUnicode(GList *tokens, GString *fileName, int line);
202 void parseUnicodeMap(GList *tokens, GString *fileName, int line);
203 void parseCMapDir(GList *tokens, GString *fileName, int line);
204 void parseToUnicodeDir(GList *tokens, GString *fileName, int line);
205 void parseDisplayFont(GList *tokens, GHash *fontHash,
206 DisplayFontParamKind kind,
207 GString *fileName, int line);
208 void parsePSFile(GList *tokens, GString *fileName, int line);
209 void parsePSPaperSize(GList *tokens, GString *fileName, int line);
210 void parsePSLevel(GList *tokens, GString *fileName, int line);
211 void parsePSFont(GList *tokens, GString *fileName, int line);
212 void parsePSFont16(const char *cmdName, GList *fontList,
213 GList *tokens, GString *fileName, int line);
214 void parseTextEncoding(GList *tokens, GString *fileName, int line);
215 void parseTextEOL(GList *tokens, GString *fileName, int line);
216 void parseFontDir(GList *tokens, GString *fileName, int line);
217 void parseInitialZoom(GList *tokens, GString *fileName, int line);
218 void parseFontRastControl(const char *cmdName, FontRastControl *val,
219 GList *tokens, GString *fileName, int line);
220 void parseCommand(const char *cmdName, GString **val,
221 GList *tokens, GString *fileName, int line);
222 void parseYesNo(const char *cmdName, GBool *flag,
223 GList *tokens, GString *fileName, int line);
224 GBool setFontRastControl(FontRastControl *val, const char *s);
225
226 //----- static tables
227
228 NameToCharCode * // mapping from char name to
229 macRomanReverseMap; // MacRomanEncoding index
230
231 //----- user-modifiable settings
232
233 NameToCharCode * // mapping from char name to Unicode
234 nameToUnicode;
235 GHash *cidToUnicodes; // files for mappings from char collections
236 // to Unicode, indexed by collection name
237 // [GString]
238 GHash *residentUnicodeMaps; // mappings from Unicode to char codes,
239 // indexed by encoding name [UnicodeMap]
240 GHash *unicodeMaps; // files for mappings from Unicode to char
241 // codes, indexed by encoding name [GString]
242 GHash *cMapDirs; // list of CMap dirs, indexed by collection
243 // name [GList[GString]]
244 GList *toUnicodeDirs; // list of ToUnicode CMap dirs [GString]
245 GHash *displayFonts; // display font info, indexed by font name
246 // [DisplayFontParam]
247 GHash *displayCIDFonts; // display CID font info, indexed by
248 // collection [DisplayFontParam]
249 GHash *displayNamedCIDFonts; // display CID font info, indexed by
250 // font name [DisplayFontParam]
251 GString *psFile; // PostScript file or command (for xpdf)
252 int psPaperWidth; // paper size, in PostScript points, for
253 int psPaperHeight; // PostScript output
254 GBool psDuplex; // enable duplexing in PostScript?
255 PSLevel psLevel; // PostScript level to generate
256 GHash *psFonts; // PostScript font info, indexed by PDF
257 // font name [PSFontParam]
258 GList *psNamedFonts16; // named 16-bit fonts [PSFontParam]
259 GList *psFonts16; // generic 16-bit fonts [PSFontParam]
260 GBool psEmbedType1; // embed Type 1 fonts?
261 GBool psEmbedTrueType; // embed TrueType fonts?
262 GBool psEmbedCIDPostScript; // embed CID PostScript fonts?
263 GBool psEmbedCIDTrueType; // embed CID TrueType fonts?
264 GBool psOPI; // generate PostScript OPI comments?
265 GBool psASCIIHex; // use ASCIIHex instead of ASCII85?
266 GString *textEncoding; // encoding (unicodeMap) to use for text
267 // output
268 EndOfLineKind textEOL; // type of EOL marker to use for text
269 // output
270 GBool textKeepTinyChars; // keep all characters in text output
271 GList *fontDirs; // list of font dirs [GString]
272 GString *initialZoom; // initial zoom level
273 FontRastControl t1libControl; // t1lib rasterization mode
274 FontRastControl // FreeType rasterization mode
275 freetypeControl;
276 GString *urlCommand; // command executed for URL links
277 GString *movieCommand; // command executed for movie annotations
278 GBool mapNumericCharNames; // map numeric char names (from font subsets)?
279 GBool printCommands; // print the drawing commands
280 GBool errQuiet; // suppress error messages?
281
282 CIDToUnicodeCache *cidToUnicodeCache;
283 UnicodeMapCache *unicodeMapCache;
284 CMapCache *cMapCache;
285};
286
287#endif