Back to index

tetex-bin  3.0
GlobalParams.h
Go to the documentation of this file.
00001 //========================================================================
00002 //
00003 // GlobalParams.h
00004 //
00005 // Copyright 2001-2003 Glyph & Cog, LLC
00006 //
00007 //========================================================================
00008 
00009 #ifndef GLOBALPARAMS_H
00010 #define GLOBALPARAMS_H
00011 
00012 #include <aconf.h>
00013 
00014 #ifdef USE_GCC_PRAGMAS
00015 #pragma interface
00016 #endif
00017 
00018 #include <stdio.h>
00019 #include "gtypes.h"
00020 #include "CharTypes.h"
00021 
00022 #if MULTITHREADED
00023 #include "GMutex.h"
00024 #endif
00025 
00026 class GString;
00027 class GList;
00028 class GHash;
00029 class NameToCharCode;
00030 class CharCodeToUnicode;
00031 class CharCodeToUnicodeCache;
00032 class UnicodeMap;
00033 class UnicodeMapCache;
00034 class CMap;
00035 class CMapCache;
00036 class GlobalParams;
00037 
00038 //------------------------------------------------------------------------
00039 
00040 // The global parameters object.
00041 extern GlobalParams *globalParams;
00042 
00043 //------------------------------------------------------------------------
00044 
00045 enum DisplayFontParamKind {
00046   displayFontT1,
00047   displayFontTT
00048 };
00049 
00050 struct DFP_t1_tt_ {
00051   GString *fileName;
00052 };
00053 
00054 class DisplayFontParam {
00055 public:
00056 
00057   GString *name;            // font name for 8-bit fonts and named
00058                             //   CID fonts; collection name for
00059                             //   generic CID fonts
00060   DisplayFontParamKind kind;
00061   union {
00062     struct DFP_t1_tt_ t1;
00063     struct DFP_t1_tt_ tt;
00064   };
00065 
00066   DisplayFontParam(GString *nameA, DisplayFontParamKind kindA);
00067   ~DisplayFontParam();
00068 };
00069 
00070 //------------------------------------------------------------------------
00071 
00072 class PSFontParam {
00073 public:
00074 
00075   GString *pdfFontName;            // PDF font name for 8-bit fonts and
00076                             //   named 16-bit fonts; char collection
00077                             //   name for generic 16-bit fonts
00078   int wMode;                // writing mode (0=horiz, 1=vert) for
00079                             //   16-bit fonts
00080   GString *psFontName;             // PostScript font name
00081   GString *encoding;        // encoding, for 16-bit fonts only
00082 
00083   PSFontParam(GString *pdfFontNameA, int wModeA,
00084              GString *psFontNameA, GString *encodingA);
00085   ~PSFontParam();
00086 };
00087 
00088 //------------------------------------------------------------------------
00089 
00090 enum PSLevel {
00091   psLevel1,
00092   psLevel1Sep,
00093   psLevel2,
00094   psLevel2Sep,
00095   psLevel3,
00096   psLevel3Sep
00097 };
00098 
00099 //------------------------------------------------------------------------
00100 
00101 enum EndOfLineKind {
00102   eolUnix,                  // LF
00103   eolDOS,                   // CR+LF
00104   eolMac                    // CR
00105 };
00106 
00107 //------------------------------------------------------------------------
00108 
00109 class GlobalParams {
00110 public:
00111 
00112   // Initialize the global parameters by attempting to read a config
00113   // file.
00114   GlobalParams(char *cfgFileName);
00115   GlobalParams();
00116 
00117   ~GlobalParams();
00118 
00119   void setupBaseFonts(char *dir);
00120 
00121   //----- accessors
00122 
00123   CharCode getMacRomanCharCode(char *charName);
00124 
00125   Unicode mapNameToUnicode(char *charName);
00126   UnicodeMap *getResidentUnicodeMap(GString *encodingName);
00127   FILE *getUnicodeMapFile(GString *encodingName);
00128   FILE *findCMapFile(GString *collection, GString *cMapName);
00129   FILE *findToUnicodeFile(GString *name);
00130   DisplayFontParam *getDisplayFont(GString *fontName);
00131   DisplayFontParam *getDisplayCIDFont(GString *fontName, GString *collection);
00132   GString *getPSFile();
00133   int getPSPaperWidth();
00134   int getPSPaperHeight();
00135   void getPSImageableArea(int *llx, int *lly, int *urx, int *ury);
00136   GBool getPSDuplex();
00137   GBool getPSCrop();
00138   GBool getPSExpandSmaller();
00139   GBool getPSShrinkLarger();
00140   GBool getPSCenter();
00141   PSLevel getPSLevel();
00142   PSFontParam *getPSFont(GString *fontName);
00143   PSFontParam *getPSFont16(GString *fontName, GString *collection, int wMode);
00144   GBool getPSEmbedType1();
00145   GBool getPSEmbedTrueType();
00146   GBool getPSEmbedCIDPostScript();
00147   GBool getPSEmbedCIDTrueType();
00148   GBool getPSOPI();
00149   GBool getPSASCIIHex();
00150   GString *getTextEncodingName();
00151   EndOfLineKind getTextEOL();
00152   GBool getTextPageBreaks();
00153   GBool getTextKeepTinyChars();
00154   GString *findFontFile(GString *fontName, char **exts);
00155   GString *getInitialZoom();
00156   GBool getEnableT1lib();
00157   GBool getEnableFreeType();
00158   GBool getAntialias();
00159   GString *getURLCommand() { return urlCommand; }
00160   GString *getMovieCommand() { return movieCommand; }
00161   GBool getMapNumericCharNames();
00162   GBool getPrintCommands();
00163   GBool getErrQuiet();
00164 
00165   CharCodeToUnicode *getCIDToUnicode(GString *collection);
00166   CharCodeToUnicode *getUnicodeToUnicode(GString *fontName);
00167   UnicodeMap *getUnicodeMap(GString *encodingName);
00168   CMap *getCMap(GString *collection, GString *cMapName);
00169   UnicodeMap *getTextEncoding();
00170 
00171   //----- functions to set parameters
00172 
00173   void addDisplayFont(DisplayFontParam *param);
00174   void setPSFile(char *file);
00175   GBool setPSPaperSize(char *size);
00176   void setPSPaperWidth(int width);
00177   void setPSPaperHeight(int height);
00178   void setPSImageableArea(int llx, int lly, int urx, int ury);
00179   void setPSDuplex(GBool duplex);
00180   void setPSCrop(GBool crop);
00181   void setPSExpandSmaller(GBool expand);
00182   void setPSShrinkLarger(GBool shrink);
00183   void setPSCenter(GBool center);
00184   void setPSLevel(PSLevel level);
00185   void setPSEmbedType1(GBool embed);
00186   void setPSEmbedTrueType(GBool embed);
00187   void setPSEmbedCIDPostScript(GBool embed);
00188   void setPSEmbedCIDTrueType(GBool embed);
00189   void setPSOPI(GBool opi);
00190   void setPSASCIIHex(GBool hex);
00191   void setTextEncoding(char *encodingName);
00192   GBool setTextEOL(char *s);
00193   void setTextPageBreaks(GBool pageBreaks);
00194   void setTextKeepTinyChars(GBool keep);
00195   void setInitialZoom(char *s);
00196   GBool setEnableT1lib(char *s);
00197   GBool setEnableFreeType(char *s);
00198   GBool setAntialias(char *s);
00199   void setMapNumericCharNames(GBool map);
00200   void setPrintCommands(GBool printCommandsA);
00201   void setErrQuiet(GBool errQuietA);
00202 
00203 private:
00204 
00205   void parseFile(GString *fileName, FILE *f);
00206   void parseNameToUnicode(GList *tokens, GString *fileName, int line);
00207   void parseCIDToUnicode(GList *tokens, GString *fileName, int line);
00208   void parseUnicodeToUnicode(GList *tokens, GString *fileName, int line);
00209   void parseUnicodeMap(GList *tokens, GString *fileName, int line);
00210   void parseCMapDir(GList *tokens, GString *fileName, int line);
00211   void parseToUnicodeDir(GList *tokens, GString *fileName, int line);
00212   void parseDisplayFont(GList *tokens, GHash *fontHash,
00213                      DisplayFontParamKind kind,
00214                      GString *fileName, int line);
00215   void parsePSFile(GList *tokens, GString *fileName, int line);
00216   void parsePSPaperSize(GList *tokens, GString *fileName, int line);
00217   void parsePSImageableArea(GList *tokens, GString *fileName, int line);
00218   void parsePSLevel(GList *tokens, GString *fileName, int line);
00219   void parsePSFont(GList *tokens, GString *fileName, int line);
00220   void parsePSFont16(char *cmdName, GList *fontList,
00221                    GList *tokens, GString *fileName, int line);
00222   void parseTextEncoding(GList *tokens, GString *fileName, int line);
00223   void parseTextEOL(GList *tokens, GString *fileName, int line);
00224   void parseFontDir(GList *tokens, GString *fileName, int line);
00225   void parseInitialZoom(GList *tokens, GString *fileName, int line);
00226   void parseCommand(char *cmdName, GString **val,
00227                   GList *tokens, GString *fileName, int line);
00228   void parseYesNo(char *cmdName, GBool *flag,
00229                 GList *tokens, GString *fileName, int line);
00230   GBool parseYesNo2(char *token, GBool *flag);
00231   UnicodeMap *getUnicodeMap2(GString *encodingName);
00232 
00233   //----- static tables
00234 
00235   NameToCharCode *          // mapping from char name to
00236     macRomanReverseMap;            //   MacRomanEncoding index
00237 
00238   //----- user-modifiable settings
00239 
00240   NameToCharCode *          // mapping from char name to Unicode
00241     nameToUnicode;
00242   GHash *cidToUnicodes;            // files for mappings from char collections
00243                             //   to Unicode, indexed by collection name
00244                             //   [GString]
00245   GHash *unicodeToUnicodes; // files for Unicode-to-Unicode mappings,
00246                             //   indexed by font name pattern [GString]
00247   GHash *residentUnicodeMaps;      // mappings from Unicode to char codes,
00248                             //   indexed by encoding name [UnicodeMap]
00249   GHash *unicodeMaps;              // files for mappings from Unicode to char
00250                             //   codes, indexed by encoding name [GString]
00251   GHash *cMapDirs;          // list of CMap dirs, indexed by collection
00252                             //   name [GList[GString]]
00253   GList *toUnicodeDirs;            // list of ToUnicode CMap dirs [GString]
00254   GHash *displayFonts;             // display font info, indexed by font name
00255                             //   [DisplayFontParam]
00256   GHash *displayCIDFonts;   // display CID font info, indexed by
00257                             //   collection [DisplayFontParam]
00258   GHash *displayNamedCIDFonts;     // display CID font info, indexed by
00259                             //   font name [DisplayFontParam]
00260   GString *psFile;          // PostScript file or command (for xpdf)
00261   int psPaperWidth;         // paper size, in PostScript points, for
00262   int psPaperHeight;        //   PostScript output
00263   int psImageableLLX,              // imageable area, in PostScript points,
00264       psImageableLLY,              //   for PostScript output
00265       psImageableURX,
00266       psImageableURY;
00267   GBool psCrop;                    // crop PS output to CropBox
00268   GBool psExpandSmaller;    // expand smaller pages to fill paper
00269   GBool psShrinkLarger;            // shrink larger pages to fit paper
00270   GBool psCenter;           // center pages on the paper
00271   GBool psDuplex;           // enable duplexing in PostScript?
00272   PSLevel psLevel;          // PostScript level to generate
00273   GHash *psFonts;           // PostScript font info, indexed by PDF
00274                             //   font name [PSFontParam]
00275   GList *psNamedFonts16;    // named 16-bit fonts [PSFontParam]
00276   GList *psFonts16;         // generic 16-bit fonts [PSFontParam]
00277   GBool psEmbedType1;              // embed Type 1 fonts?
00278   GBool psEmbedTrueType;    // embed TrueType fonts?
00279   GBool psEmbedCIDPostScript;      // embed CID PostScript fonts?
00280   GBool psEmbedCIDTrueType; // embed CID TrueType fonts?
00281   GBool psOPI;                     // generate PostScript OPI comments?
00282   GBool psASCIIHex;         // use ASCIIHex instead of ASCII85?
00283   GString *textEncoding;    // encoding (unicodeMap) to use for text
00284                             //   output
00285   EndOfLineKind textEOL;    // type of EOL marker to use for text
00286                             //   output
00287   GBool textPageBreaks;            // insert end-of-page markers?
00288   GBool textKeepTinyChars;  // keep all characters in text output
00289   GList *fontDirs;          // list of font dirs [GString]
00290   GString *initialZoom;            // initial zoom level
00291   GBool enableT1lib;        // t1lib enable flag
00292   GBool enableFreeType;            // FreeType enable flag
00293   GBool antialias;          // anti-aliasing enable flag
00294   GString *urlCommand;             // command executed for URL links
00295   GString *movieCommand;    // command executed for movie annotations
00296   GBool mapNumericCharNames;       // map numeric char names (from font subsets)?
00297   GBool printCommands;             // print the drawing commands
00298   GBool errQuiet;           // suppress error messages?
00299 
00300   CharCodeToUnicodeCache *cidToUnicodeCache;
00301   CharCodeToUnicodeCache *unicodeToUnicodeCache;
00302   UnicodeMapCache *unicodeMapCache;
00303   CMapCache *cMapCache;
00304 
00305 #if MULTITHREADED
00306   GMutex mutex;
00307   GMutex unicodeMapCacheMutex;
00308   GMutex cMapCacheMutex;
00309 #endif
00310 };
00311 
00312 #endif