1 /************************************************************************* 2 ** CMap.h ** 3 ** ** 4 ** This file is part of dvisvgm -- the DVI to SVG converter ** 5 ** Copyright (C) 2005-2015 Martin Gieseking <martin.gieseking@uos.de> ** 6 ** ** 7 ** This program is free software; you can redistribute it and/or ** 8 ** modify it under the terms of the GNU General Public License as ** 9 ** published by the Free Software Foundation; either version 3 of ** 10 ** the License, or (at your option) any later version. ** 11 ** ** 12 ** This program is distributed in the hope that it will be useful, but ** 13 ** WITHOUT ANY WARRANTY; without even the implied warranty of ** 14 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** 15 ** GNU General Public License for more details. ** 16 ** ** 17 ** You should have received a copy of the GNU General Public License ** 18 ** along with this program; if not, see <http://www.gnu.org/licenses/>. ** 19 *************************************************************************/ 20 21 #ifndef DVISVGM_CMAP_H 22 #define DVISVGM_CMAP_H 23 24 #include <algorithm> 25 #include <ostream> 26 #include <vector> 27 #include "FontEncoding.h" 28 #include "RangeMap.h" 29 #include "types.h" 30 31 32 struct CMap : public NamedFontEncoding 33 { ~CMapCMap34 virtual ~CMap () {} 35 virtual bool vertical () const =0; 36 virtual bool mapsToCID () const =0; 37 virtual const char* path () const; 38 virtual UInt32 cid (UInt32 c) const =0; 39 virtual UInt32 bfcode (UInt32 cid) const =0; 40 virtual std::string getROString () const =0; 41 virtual const FontEncoding* findCompatibleBaseFontMap (const PhysicalFont *font, CharMapID &charmapID) const; mapsToCharIndexCMap42 virtual bool mapsToCharIndex () const {return mapsToCID();} 43 decodeCMap44 Character decode (UInt32 c) const { 45 if (mapsToCID()) 46 return Character(Character::INDEX, cid(c)); 47 return Character(Character::CHRCODE, bfcode(c)); 48 } 49 }; 50 51 52 struct IdentityCMap : public CMap 53 { cidIdentityCMap54 UInt32 cid (UInt32 c) const {return c;} bfcodeIdentityCMap55 UInt32 bfcode (UInt32 cid) const {return 0;} getROStringIdentityCMap56 std::string getROString () const {return "Adobe-Identity";} mapsToCIDIdentityCMap57 bool mapsToCID() const {return true;} 58 }; 59 60 61 struct IdentityHCMap : public IdentityCMap 62 { verticalIdentityHCMap63 bool vertical () const {return false;} nameIdentityHCMap64 const char* name () const {return "Identity-H";} 65 }; 66 67 68 struct IdentityVCMap : public IdentityCMap 69 { verticalIdentityVCMap70 bool vertical () const {return true;} nameIdentityVCMap71 const char* name () const {return "Identity-V";} 72 }; 73 74 75 struct UnicodeCMap : public CMap 76 { verticalUnicodeCMap77 bool vertical () const {return false;} nameUnicodeCMap78 const char* name () const {return "unicode";} mapsToCIDUnicodeCMap79 bool mapsToCID () const {return false;} pathUnicodeCMap80 const char* path () const {return 0;} cidUnicodeCMap81 UInt32 cid (UInt32 c) const {return c;} bfcodeUnicodeCMap82 UInt32 bfcode (UInt32 cid) const {return cid;} getROStringUnicodeCMap83 std::string getROString () const {return "";} 84 }; 85 86 87 class SegmentedCMap : public CMap 88 { 89 friend class CMapReader; 90 91 public: SegmentedCMap(const std::string & name)92 SegmentedCMap (const std::string &name) : _name(name), _basemap(0), _vertical(false), _mapsToCID(true) {} name()93 const char* name () const {return _name.c_str();} 94 UInt32 cid (UInt32 c) const; 95 UInt32 bfcode (UInt32 cid) const; addCIDRange(UInt32 first,UInt32 last,UInt32 cid)96 void addCIDRange (UInt32 first, UInt32 last, UInt32 cid) {_cidranges.addRange(first, last, cid);} addBFRange(UInt32 first,UInt32 last,UInt32 chrcode)97 void addBFRange (UInt32 first, UInt32 last, UInt32 chrcode) {_bfranges.addRange(first, last, chrcode);} 98 void write (std::ostream &os) const; vertical()99 bool vertical () const {return _vertical;} mapsToCID()100 bool mapsToCID () const {return _mapsToCID;} numCIDRanges()101 size_t numCIDRanges () const {return _cidranges.size();} numBFRanges()102 size_t numBFRanges () const {return _bfranges.size();} 103 std::string getROString () const; 104 105 private: 106 std::string _name; 107 std::string _registry; 108 std::string _ordering; 109 CMap *_basemap; 110 bool _vertical; 111 bool _mapsToCID; // true: chrcode->CID, false: CID->charcode 112 RangeMap _cidranges; 113 RangeMap _bfranges; 114 }; 115 116 #endif 117