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