Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-10 10:23:47

0001 //========================================================================
0002 //
0003 // GlobalParams.h
0004 //
0005 // Copyright 2001-2003 Glyph & Cog, LLC
0006 //
0007 //========================================================================
0008 
0009 //========================================================================
0010 //
0011 // Modified under the Poppler project - http://poppler.freedesktop.org
0012 //
0013 // All changes made under the Poppler project to this file are licensed
0014 // under GPL version 2 or later
0015 //
0016 // Copyright (C) 2005, 2007-2010, 2012, 2015, 2017-2022 Albert Astals Cid <aacid@kde.org>
0017 // Copyright (C) 2005 Jonathan Blandford <jrb@redhat.com>
0018 // Copyright (C) 2006 Takashi Iwai <tiwai@suse.de>
0019 // Copyright (C) 2006 Kristian Høgsberg <krh@redhat.com>
0020 // Copyright (C) 2007 Krzysztof Kowalczyk <kkowalczyk@gmail.com>
0021 // Copyright (C) 2009 Jonathan Kew <jonathan_kew@sil.org>
0022 // Copyright (C) 2009 Petr Gajdos <pgajdos@novell.com>
0023 // Copyright (C) 2009, 2011, 2012, 2014, 2015 William Bader <williambader@hotmail.com>
0024 // Copyright (C) 2010 Hib Eris <hib@hiberis.nl>
0025 // Copyright (C) 2011 Pino Toscano <pino@kde.org>
0026 // Copyright (C) 2012, 2017 Adrian Johnson <ajohnson@redneon.com>
0027 // Copyright (C) 2012 Thomas Freitag <Thomas.Freitag@alfa.de>
0028 // Copyright (C) 2013 Jason Crain <jason@aquaticape.us>
0029 // Copyright (C) 2018, 2020 Adam Reichold <adam.reichold@t-online.de>
0030 // Copyright (C) 2019 Oliver Sander <oliver.sander@tu-dresden.de>
0031 //
0032 // To see a description of the changes please see the Changelog file that
0033 // came with your tarball or type make ChangeLog if you are building from git
0034 //
0035 //========================================================================
0036 
0037 #ifndef GLOBALPARAMS_H
0038 #define GLOBALPARAMS_H
0039 
0040 #include <cassert>
0041 #include "poppler-config.h"
0042 #include "poppler_private_export.h"
0043 #include <cstdio>
0044 #include "CharTypes.h"
0045 #include "UnicodeMap.h"
0046 #include "Error.h"
0047 #include <unordered_map>
0048 #include <string>
0049 #include <memory>
0050 #include <mutex>
0051 #include <vector>
0052 
0053 class GooString;
0054 class NameToCharCode;
0055 class CharCodeToUnicode;
0056 class CharCodeToUnicodeCache;
0057 class UnicodeMapCache;
0058 class CMap;
0059 class CMapCache;
0060 class GlobalParams;
0061 class GfxFont;
0062 class Stream;
0063 class SysFontList;
0064 
0065 //------------------------------------------------------------------------
0066 
0067 // The global parameters object.
0068 extern std::unique_ptr<GlobalParams> POPPLER_PRIVATE_EXPORT globalParams;
0069 
0070 //------------------------------------------------------------------------
0071 
0072 enum SysFontType
0073 {
0074     sysFontPFA,
0075     sysFontPFB,
0076     sysFontTTF,
0077     sysFontTTC
0078 };
0079 
0080 //------------------------------------------------------------------------
0081 
0082 struct FamilyStyleFontSearchResult
0083 {
0084     FamilyStyleFontSearchResult() = default;
0085 
0086     FamilyStyleFontSearchResult(const std::string &filepathA, int faceIndexA) : filepath(filepathA), faceIndex(faceIndexA) { }
0087 
0088     std::string filepath;
0089     int faceIndex = 0;
0090 };
0091 
0092 //------------------------------------------------------------------------
0093 
0094 struct UCharFontSearchResult
0095 {
0096     UCharFontSearchResult() = default;
0097 
0098     UCharFontSearchResult(const std::string &filepathA, int faceIndexA, const std::string &familyA, const std::string &styleA) : filepath(filepathA), faceIndex(faceIndexA), family(familyA), style(styleA) { }
0099 
0100     const std::string filepath;
0101     const int faceIndex = 0;
0102     const std::string family;
0103     const std::string style;
0104 };
0105 
0106 //------------------------------------------------------------------------
0107 
0108 class POPPLER_PRIVATE_EXPORT GlobalParams
0109 {
0110 public:
0111     // Initialize the global parameters
0112     explicit GlobalParams(const char *customPopplerDataDir = nullptr);
0113 
0114     ~GlobalParams();
0115 
0116     GlobalParams(const GlobalParams &) = delete;
0117     GlobalParams &operator=(const GlobalParams &) = delete;
0118 
0119     void setupBaseFonts(const char *dir);
0120 
0121     //----- accessors
0122 
0123     CharCode getMacRomanCharCode(const char *charName);
0124 
0125     // Return Unicode values for character names.  Used for general text
0126     // extraction.
0127     Unicode mapNameToUnicodeText(const char *charName);
0128 
0129     // Return Unicode values for character names.  Used for glyph
0130     // lookups or text extraction with ZapfDingbats fonts.
0131     Unicode mapNameToUnicodeAll(const char *charName);
0132 
0133     UnicodeMap *getResidentUnicodeMap(const std::string &encodingName);
0134     FILE *getUnicodeMapFile(const std::string &encodingName);
0135     FILE *findCMapFile(const GooString *collection, const GooString *cMapName);
0136     FILE *findToUnicodeFile(const GooString *name);
0137     GooString *findFontFile(const std::string &fontName);
0138     GooString *findBase14FontFile(const GooString *base14Name, const GfxFont *font);
0139     GooString *findSystemFontFile(const GfxFont *font, SysFontType *type, int *fontNum, GooString *substituteFontName = nullptr, const GooString *base14Name = nullptr);
0140     FamilyStyleFontSearchResult findSystemFontFileForFamilyAndStyle(const std::string &fontFamily, const std::string &fontStyle, const std::vector<std::string> &filesToIgnore = {});
0141     UCharFontSearchResult findSystemFontFileForUChar(Unicode uChar, const GfxFont &fontToEmulate);
0142     std::string getTextEncodingName() const;
0143     bool getPrintCommands();
0144     bool getProfileCommands();
0145     bool getErrQuiet();
0146 
0147     CharCodeToUnicode *getCIDToUnicode(const GooString *collection);
0148     const UnicodeMap *getUnicodeMap(const std::string &encodingName);
0149     std::shared_ptr<CMap> getCMap(const GooString *collection, const GooString *cMapName);
0150     const UnicodeMap *getTextEncoding();
0151 
0152     const UnicodeMap *getUtf8Map();
0153 
0154     std::vector<std::string> getEncodingNames();
0155 
0156     //----- functions to set parameters
0157     void addFontFile(const GooString *fontName, const GooString *path);
0158     void setTextEncoding(const char *encodingName);
0159     void setPrintCommands(bool printCommandsA);
0160     void setProfileCommands(bool profileCommandsA);
0161     void setErrQuiet(bool errQuietA);
0162 
0163     static bool parseYesNo2(const char *token, bool *flag);
0164 
0165 private:
0166     void parseNameToUnicode(const GooString *name);
0167 
0168     void scanEncodingDirs();
0169     void addCIDToUnicode(const GooString *collection, const GooString *fileName);
0170     void addUnicodeMap(const GooString *encodingName, const GooString *fileName);
0171     void addCMapDir(const GooString *collection, const GooString *dir);
0172 
0173     //----- static tables
0174 
0175     NameToCharCode * // mapping from char name to
0176             macRomanReverseMap; //   MacRomanEncoding index
0177 
0178     //----- user-modifiable settings
0179 
0180     NameToCharCode * // mapping from char name to Unicode for ZapfDingbats
0181             nameToUnicodeZapfDingbats;
0182     NameToCharCode * // mapping from char name to Unicode for text
0183             nameToUnicodeText; // extraction
0184     // files for mappings from char collections
0185     // to Unicode, indexed by collection name
0186     std::unordered_map<std::string, std::string> cidToUnicodes;
0187     // mappings from Unicode to char codes,
0188     // indexed by encoding name
0189     std::unordered_map<std::string, UnicodeMap> residentUnicodeMaps;
0190     // files for mappings from Unicode to char
0191     // codes, indexed by encoding name
0192     std::unordered_map<std::string, std::string> unicodeMaps;
0193     // list of CMap dirs, indexed by collection
0194     std::unordered_multimap<std::string, std::string> cMapDirs;
0195     std::vector<GooString *> toUnicodeDirs; // list of ToUnicode CMap dirs
0196     bool baseFontsInitialized;
0197 #ifdef _WIN32
0198     // windows font substitutes (for CID fonts)
0199     std::unordered_map<std::string, std::string> substFiles;
0200 #endif
0201     // font files: font name mapped to path
0202     std::unordered_map<std::string, std::string> fontFiles;
0203     SysFontList *sysFonts; // system fonts
0204     GooString *textEncoding; // encoding (unicodeMap) to use for text
0205                              //   output
0206     bool printCommands; // print the drawing commands
0207     bool profileCommands; // profile the drawing commands
0208     bool errQuiet; // suppress error messages?
0209 
0210     CharCodeToUnicodeCache *cidToUnicodeCache;
0211     CharCodeToUnicodeCache *unicodeToUnicodeCache;
0212     UnicodeMapCache *unicodeMapCache;
0213     CMapCache *cMapCache;
0214 
0215     const UnicodeMap *utf8Map;
0216 
0217     mutable std::recursive_mutex mutex;
0218     mutable std::recursive_mutex unicodeMapCacheMutex;
0219     mutable std::recursive_mutex cMapCacheMutex;
0220 
0221     const char *popplerDataDir;
0222 };
0223 
0224 class POPPLER_PRIVATE_EXPORT GlobalParamsIniter
0225 {
0226 public:
0227     explicit GlobalParamsIniter(ErrorCallback errorCallback);
0228     ~GlobalParamsIniter();
0229 
0230     GlobalParamsIniter(const GlobalParamsIniter &) = delete;
0231     GlobalParamsIniter &operator=(const GlobalParamsIniter &) = delete;
0232 
0233     static bool setCustomDataDir(const std::string &dir);
0234 
0235 private:
0236     static std::mutex mutex;
0237     static int count;
0238 
0239     static std::string customDataDir;
0240 };
0241 
0242 #endif