GlobalParams.h 11.5 KB
Newer Older
Kristian Høgsberg's avatar
Kristian Høgsberg committed
1 2 3 4 5 6 7
//========================================================================
//
// GlobalParams.h
//
// Copyright 2001-2003 Glyph & Cog, LLC
//
//========================================================================
8 9 10 11 12

//========================================================================
//
// Modified under the Poppler project - http://poppler.freedesktop.org
//
13 14 15
// All changes made under the Poppler project to this file are licensed
// under GPL version 2 or later
//
16
// Copyright (C) 2005, 2007-2009 Albert Astals Cid <aacid@kde.org>
17 18 19 20
// Copyright (C) 2005 Jonathan Blandford <jrb@redhat.com>
// Copyright (C) 2006 Takashi Iwai <tiwai@suse.de>
// Copyright (C) 2006 Kristian Høgsberg <krh@redhat.com>
// Copyright (C) 2007 Krzysztof Kowalczyk <kkowalczyk@gmail.com>
21
// Copyright (C) 2009 Jonathan Kew <jonathan_kew@sil.org>
22
// Copyright (C) 2009 Petr Gajdos <pgajdos@novell.com>
23
// Copyright (C) 2009 William Bader <williambader@hotmail.com>
24 25 26 27 28
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
//
//========================================================================
Kristian Høgsberg's avatar
Kristian Høgsberg committed
29 30 31 32 33 34 35 36

#ifndef GLOBALPARAMS_H
#define GLOBALPARAMS_H

#ifdef USE_GCC_PRAGMAS
#pragma interface
#endif

37
#include <assert.h>
Kristian Høgsberg's avatar
Kristian Høgsberg committed
38 39
#include "poppler-config.h"
#include <stdio.h>
40
#ifndef _MSC_VER
Kristian Høgsberg's avatar
Kristian Høgsberg committed
41
#include <fontconfig/fontconfig.h>
42
#endif
Kristian Høgsberg's avatar
Kristian Høgsberg committed
43 44 45 46
#include "goo/gtypes.h"
#include "CharTypes.h"

#if MULTITHREADED
Albert Astals Cid's avatar
Albert Astals Cid committed
47
#include "goo/GooMutex.h"
Kristian Høgsberg's avatar
Kristian Høgsberg committed
48 49 50 51 52 53 54 55 56 57 58 59
#endif

class GooString;
class GooList;
class GooHash;
class NameToCharCode;
class CharCodeToUnicode;
class CharCodeToUnicodeCache;
class UnicodeMap;
class UnicodeMapCache;
class CMap;
class CMapCache;
60
struct XpdfSecurityHandler;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
61
class GlobalParams;
62
class GfxFont;
63
class Stream;
Kovid Goyal's avatar
Kovid Goyal committed
64
#ifdef _WIN32
65 66
class WinFontList;
#endif
Kristian Høgsberg's avatar
Kristian Høgsberg committed
67 68 69 70 71 72 73 74 75 76 77 78 79

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

// The global parameters object.
extern GlobalParams *globalParams;

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

enum DisplayFontParamKind {
  displayFontT1,
  displayFontTT
};

80 81 82 83 84 85
struct DisplayFontParamT1 {
  GooString *fileName;
};

struct DisplayFontParamTT {
  GooString *fileName;
86
  int faceIndex;
87 88
};

Kristian Høgsberg's avatar
Kristian Høgsberg committed
89 90 91 92 93 94 95 96
class DisplayFontParam {
public:

  GooString *name;		// font name for 8-bit fonts and named
				//   CID fonts; collection name for
				//   generic CID fonts
  DisplayFontParamKind kind;
  union {
97 98
    DisplayFontParamT1 t1;
    DisplayFontParamTT tt;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
99 100 101
  };

  DisplayFontParam(GooString *nameA, DisplayFontParamKind kindA);
102 103 104 105 106 107 108 109
  void setFileName(GooString *fileNameA) {
    if (displayFontT1 == kind)
        t1.fileName = fileNameA;
    else {
        assert(displayFontTT == kind);
        tt.fileName = fileNameA;
    }
  }  
110
  virtual ~DisplayFontParam();
Kristian Høgsberg's avatar
Kristian Høgsberg committed
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
};

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

class PSFontParam {
public:

  GooString *pdfFontName;		// PDF font name for 8-bit fonts and
				//   named 16-bit fonts; char collection
				//   name for generic 16-bit fonts
  int wMode;			// writing mode (0=horiz, 1=vert) for
				//   16-bit fonts
  GooString *psFontName;		// PostScript font name
  GooString *encoding;		// encoding, for 16-bit fonts only

  PSFontParam(GooString *pdfFontNameA, int wModeA,
	      GooString *psFontNameA, GooString *encodingA);
  ~PSFontParam();
};

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

enum PSLevel {
  psLevel1,
  psLevel1Sep,
  psLevel2,
  psLevel2Sep,
  psLevel3,
  psLevel3Sep
};

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

enum EndOfLineKind {
  eolUnix,			// LF
  eolDOS,			// CR+LF
  eolMac			// CR
};

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

152 153 154 155 156 157 158 159 160
enum ScreenType {
  screenUnset,
  screenDispersed,
  screenClustered,
  screenStochasticClustered
};

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

Kristian Høgsberg's avatar
Kristian Høgsberg committed
161 162 163 164 165
class GlobalParams {
public:

  // Initialize the global parameters by attempting to read a config
  // file.
166
  GlobalParams(const char *customPopplerDataDir = NULL);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
167 168 169

  ~GlobalParams();

170 171
  void setBaseDir(char *dir);

172 173 174 175
#ifdef _MSC_VER
  void setupBaseFonts(char *dir);
#endif

Kristian Høgsberg's avatar
Kristian Høgsberg committed
176 177 178 179
  //----- accessors

  CharCode getMacRomanCharCode(char *charName);

180
  GooString *getBaseDir();
Kristian Høgsberg's avatar
Kristian Høgsberg committed
181 182 183 184 185
  Unicode mapNameToUnicode(char *charName);
  UnicodeMap *getResidentUnicodeMap(GooString *encodingName);
  FILE *getUnicodeMapFile(GooString *encodingName);
  FILE *findCMapFile(GooString *collection, GooString *cMapName);
  FILE *findToUnicodeFile(GooString *name);
186
  DisplayFontParam *getDisplayFont(GfxFont *font);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
187 188 189 190 191 192 193 194 195 196
  GBool getPSExpandSmaller();
  GBool getPSShrinkLarger();
  GBool getPSCenter();
  PSLevel getPSLevel();
  PSFontParam *getPSFont(GooString *fontName);
  PSFontParam *getPSFont16(GooString *fontName, GooString *collection, int wMode);
  GBool getPSEmbedType1();
  GBool getPSEmbedTrueType();
  GBool getPSEmbedCIDPostScript();
  GBool getPSEmbedCIDTrueType();
197
  GBool getPSSubstFonts();
198
  GBool getPSPreload();
Kristian Høgsberg's avatar
Kristian Høgsberg committed
199 200 201 202 203 204 205 206 207
  GBool getPSOPI();
  GBool getPSASCIIHex();
  GooString *getTextEncodingName();
  EndOfLineKind getTextEOL();
  GBool getTextPageBreaks();
  GBool getTextKeepTinyChars();
  GooString *findFontFile(GooString *fontName, char **exts);
  GBool getEnableFreeType();
  GBool getAntialias();
208
  GBool getVectorAntialias();
209
  GBool getForceNoFTAutoHinting();
210 211 212 213 214 215 216
  GBool getStrokeAdjust();
  ScreenType getScreenType();
  int getScreenSize();
  int getScreenDotRadius();
  double getScreenGamma();
  double getScreenBlackThreshold();
  double getScreenWhiteThreshold();
Kristian Høgsberg's avatar
Kristian Høgsberg committed
217
  GBool getMapNumericCharNames();
218
  GBool getMapUnknownCharNames();
Kristian Høgsberg's avatar
Kristian Høgsberg committed
219
  GBool getPrintCommands();
220
  GBool getProfileCommands();
Kristian Høgsberg's avatar
Kristian Høgsberg committed
221 222 223 224 225
  GBool getErrQuiet();

  CharCodeToUnicode *getCIDToUnicode(GooString *collection);
  CharCodeToUnicode *getUnicodeToUnicode(GooString *fontName);
  UnicodeMap *getUnicodeMap(GooString *encodingName);
226
  CMap *getCMap(GooString *collection, GooString *cMapName, Stream *stream = NULL);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
227
  UnicodeMap *getTextEncoding();
228 229 230
#ifdef ENABLE_PLUGINS
  GBool loadPlugin(char *type, char *name);
#endif
Kristian Høgsberg's avatar
Kristian Høgsberg committed
231

232 233
  GooList *getEncodingNames();

Kristian Høgsberg's avatar
Kristian Høgsberg committed
234 235 236 237 238 239 240 241 242
  //----- functions to set parameters
  void setPSExpandSmaller(GBool expand);
  void setPSShrinkLarger(GBool shrink);
  void setPSCenter(GBool center);
  void setPSLevel(PSLevel level);
  void setPSEmbedType1(GBool embed);
  void setPSEmbedTrueType(GBool embed);
  void setPSEmbedCIDPostScript(GBool embed);
  void setPSEmbedCIDTrueType(GBool embed);
243
  void setPSSubstFonts(GBool substFonts);
244
  void setPSPreload(GBool preload);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
245 246 247 248 249 250 251 252
  void setPSOPI(GBool opi);
  void setPSASCIIHex(GBool hex);
  void setTextEncoding(char *encodingName);
  GBool setTextEOL(char *s);
  void setTextPageBreaks(GBool pageBreaks);
  void setTextKeepTinyChars(GBool keep);
  GBool setEnableFreeType(char *s);
  GBool setAntialias(char *s);
253
  GBool setVectorAntialias(char *s);
254
  GBool setForceNoFTAutoHinting(char *s);
255 256 257 258 259 260 261
  void setStrokeAdjust(GBool strokeAdjust);
  void setScreenType(ScreenType st);
  void setScreenSize(int size);
  void setScreenDotRadius(int radius);
  void setScreenGamma(double gamma);
  void setScreenBlackThreshold(double blackThreshold);
  void setScreenWhiteThreshold(double whiteThreshold);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
262
  void setMapNumericCharNames(GBool map);
263
  void setMapUnknownCharNames(GBool map);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
264
  void setPrintCommands(GBool printCommandsA);
265
  void setProfileCommands(GBool profileCommandsA);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
266 267
  void setErrQuiet(GBool errQuietA);

268 269 270 271 272
  //----- security handlers

  void addSecurityHandler(XpdfSecurityHandler *handler);
  XpdfSecurityHandler *getSecurityHandler(char *name);

Kristian Høgsberg's avatar
Kristian Høgsberg committed
273 274
private:

275
  void parseNameToUnicode(GooString *name);
Kristian Høgsberg's avatar
Kristian Høgsberg committed
276 277 278
  GBool parseYesNo2(char *token, GBool *flag);
  UnicodeMap *getUnicodeMap2(GooString *encodingName);

279 280 281 282 283
  void scanEncodingDirs();
  void addCIDToUnicode(GooString *collection, GooString *fileName);
  void addUnicodeMap(GooString *encodingName, GooString *fileName);
  void addCMapDir(GooString *collection, GooString *dir);

Kristian Høgsberg's avatar
Kristian Høgsberg committed
284 285 286 287 288 289 290
  //----- static tables

  NameToCharCode *		// mapping from char name to
    macRomanReverseMap;		//   MacRomanEncoding index

  //----- user-modifiable settings

291
  GooString *baseDir;		// base directory - for plugins, etc.
Kristian Høgsberg's avatar
Kristian Høgsberg committed
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307
  NameToCharCode *		// mapping from char name to Unicode
    nameToUnicode;
  GooHash *cidToUnicodes;		// files for mappings from char collections
				//   to Unicode, indexed by collection name
				//   [GooString]
  GooHash *unicodeToUnicodes;	// files for Unicode-to-Unicode mappings,
				//   indexed by font name pattern [GooString]
  GooHash *residentUnicodeMaps;	// mappings from Unicode to char codes,
				//   indexed by encoding name [UnicodeMap]
  GooHash *unicodeMaps;		// files for mappings from Unicode to char
				//   codes, indexed by encoding name [GooString]
  GooHash *cMapDirs;		// list of CMap dirs, indexed by collection
				//   name [GooList[GooString]]
  GooList *toUnicodeDirs;		// list of ToUnicode CMap dirs [GooString]
  GooHash *displayFonts;		// display font info, indexed by font name
				//   [DisplayFontParam]
Kovid Goyal's avatar
Kovid Goyal committed
308
#ifdef _WIN32
309
  GBool baseFontsInitialized;
310 311
  WinFontList *winFontList;	// system TrueType fonts
#endif
Kristian Høgsberg's avatar
Kristian Høgsberg committed
312 313 314 315 316 317 318 319 320 321 322 323
  GBool psExpandSmaller;	// expand smaller pages to fill paper
  GBool psShrinkLarger;		// shrink larger pages to fit paper
  GBool psCenter;		// center pages on the paper
  PSLevel psLevel;		// PostScript level to generate
  GooHash *psFonts;		// PostScript font info, indexed by PDF
				//   font name [PSFontParam]
  GooList *psNamedFonts16;	// named 16-bit fonts [PSFontParam]
  GooList *psFonts16;		// generic 16-bit fonts [PSFontParam]
  GBool psEmbedType1;		// embed Type 1 fonts?
  GBool psEmbedTrueType;	// embed TrueType fonts?
  GBool psEmbedCIDPostScript;	// embed CID PostScript fonts?
  GBool psEmbedCIDTrueType;	// embed CID TrueType fonts?
324
  GBool psSubstFonts;		// substitute missing fonts?
325 326
  GBool psPreload;		// preload PostScript images and forms into
				//   memory
Kristian Høgsberg's avatar
Kristian Høgsberg committed
327 328 329 330 331 332 333 334 335 336 337
  GBool psOPI;			// generate PostScript OPI comments?
  GBool psASCIIHex;		// use ASCIIHex instead of ASCII85?
  GooString *textEncoding;	// encoding (unicodeMap) to use for text
				//   output
  EndOfLineKind textEOL;	// type of EOL marker to use for text
				//   output
  GBool textPageBreaks;		// insert end-of-page markers?
  GBool textKeepTinyChars;	// keep all characters in text output
  GooList *fontDirs;		// list of font dirs [GooString]
  GBool enableFreeType;		// FreeType enable flag
  GBool antialias;		// anti-aliasing enable flag
338
  GBool vectorAntialias;	// vector anti-aliasing enable flag
339
  GBool forceNoFTAutoHinting;  // force to disable FT autohinting
340 341 342 343 344 345 346
  GBool strokeAdjust;		// stroke adjustment enable flag
  ScreenType screenType;	// halftone screen type
  int screenSize;		// screen matrix size
  int screenDotRadius;		// screen dot radius
  double screenGamma;		// screen gamma correction
  double screenBlackThreshold;	// screen black clamping threshold
  double screenWhiteThreshold;	// screen white clamping threshold
Kristian Høgsberg's avatar
Kristian Høgsberg committed
347
  GBool mapNumericCharNames;	// map numeric char names (from font subsets)?
348
  GBool mapUnknownCharNames;	// map unknown char names?
Kristian Høgsberg's avatar
Kristian Høgsberg committed
349
  GBool printCommands;		// print the drawing commands
350
  GBool profileCommands;	// profile the drawing commands
Kristian Høgsberg's avatar
Kristian Høgsberg committed
351 352 353 354 355 356
  GBool errQuiet;		// suppress error messages?

  CharCodeToUnicodeCache *cidToUnicodeCache;
  CharCodeToUnicodeCache *unicodeToUnicodeCache;
  UnicodeMapCache *unicodeMapCache;
  CMapCache *cMapCache;
357
  
358
#ifndef _MSC_VER
359
  FcConfig *FCcfg;
360
#endif
Kristian Høgsberg's avatar
Kristian Høgsberg committed
361

362 363 364 365 366 367
#ifdef ENABLE_PLUGINS
  GList *plugins;		// list of plugins [Plugin]
  GList *securityHandlers;	// list of loaded security handlers
				//   [XpdfSecurityHandler]
#endif

Kristian Høgsberg's avatar
Kristian Høgsberg committed
368 369 370 371 372
#if MULTITHREADED
  GooMutex mutex;
  GooMutex unicodeMapCacheMutex;
  GooMutex cMapCacheMutex;
#endif
373 374

  const char *popplerDataDir;
Kristian Høgsberg's avatar
Kristian Høgsberg committed
375 376 377
};

#endif