PoDoFo 1.0.0-dev
Loading...
Searching...
No Matches
PdfCharCodeMap.h
1
7#ifndef PDF_CHAR_CODE_MAP_H
8#define PDF_CHAR_CODE_MAP_H
9
10#include "PdfDeclarations.h"
11#include "PdfEncodingCommon.h"
12
13namespace PoDoFo
14{
15 struct CodePointMapNode;
16
17 struct PODOFO_API CodeUnitRange final
18 {
19 PdfCharCode SrcCodeLo;
20 unsigned Size = 0;
21 CodePointSpan DstCodeLo;
22
23 CodeUnitRange();
24
25 CodeUnitRange(PdfCharCode srcCodeLo, unsigned size, CodePointSpan dstCodeLo);
26
27 PdfCharCode GetSrcCodeHi() const;
28 };
29
30 struct PODOFO_API CodeUnitRangeInequality
31 {
32 using is_transparent = std::true_type;
33
34 bool operator()(const CodeUnitRange& lhs, const PdfCharCode& rhs) const
35 {
36 return lhs.SrcCodeLo < rhs;
37 }
38 bool operator()(const PdfCharCode& lhs, const CodeUnitRange& rhs) const
39 {
40 return lhs < rhs.SrcCodeLo;
41 }
42 bool operator()(const CodeUnitRange& lhs, const CodeUnitRange& rhs) const
43 {
44 return lhs.SrcCodeLo < rhs.SrcCodeLo;
45 }
46 };
47
48 using CodeUnitRanges = std::set<CodeUnitRange, CodeUnitRangeInequality>;
49
56 struct PODOFO_API CodeSpaceRange final
57 {
59 CodeSpaceRange(unsigned codeLo, unsigned codeHi, unsigned char codeSpaceSize);
60
61 unsigned CodeLo;
62 unsigned CodeHi;
63 unsigned char CodeSpaceSize;
64
65 PdfCharCode GetSrcCodeLo() const;
66 PdfCharCode GetSrcCodeHi() const;
67 };
68
78 class PODOFO_API PdfCharCodeMap final
79 {
80 PODOFO_PRIVATE_FRIEND(class PdfCMapEncodingFactory);
81
82 public:
84
86
88
89 private:
90 PdfCharCodeMap(CodeUnitMap&& mapping, CodeUnitRanges&& ranges, const PdfEncodingLimits& limits);
91
92 public:
97 void PushMapping(const PdfCharCode& codeUnit, const codepointview& codePoints);
98
101 void PushMapping(const PdfCharCode& codeUnit, codepoint codePoint);
102
107 void PushRange(const PdfCharCode& srcCodeLo, unsigned size, codepoint dstCodeLo);
108
113 void PushRange(const PdfCharCode& srcCodeLo, unsigned size, const codepointview& dstCodeLo);
114
117 bool TryGetCodePoints(const PdfCharCode& codeUnit, CodePointSpan& codePoints) const;
118
123 bool TryGetNextCharCode(std::string_view::iterator& it,
124 const std::string_view::iterator& end, PdfCharCode& code) const;
125
129 bool TryGetCharCode(const codepointview& codePoints, PdfCharCode& code) const;
130
133 bool TryGetCharCode(codepoint codePoint, PdfCharCode& code) const;
134
135 PdfCharCodeMap& operator=(PdfCharCodeMap&& map) noexcept;
136
137 const PdfEncodingLimits& GetLimits() const { return m_Limits; }
138
139 bool IsEmpty() const;
140
143 bool IsTrivialIdentity() const;
144
145 std::vector<CodeSpaceRange> GetCodeSpaceRanges() const;
146
147 public:
150 const CodeUnitMap& GetMappings() const { return m_Mappings; }
151
154 const CodeUnitRanges& GetRanges() const { return m_Ranges; }
155
156 private:
157 void move(PdfCharCodeMap& map) noexcept;
158 void pushMapping(const PdfCharCode& codeUnit, const codepointview& codePoints);
159
160 private:
161 PdfCharCodeMap(const PdfCharCodeMap&) = delete;
162 PdfCharCodeMap& operator=(const PdfCharCodeMap&) = delete;
163
164 private:
165 void updateLimits(const PdfCharCode& codeUnit);
166 void reviseCodePointMap();
167 bool tryFixNextRanges(const CodeUnitRanges::iterator& it, unsigned prevRangeCodeUpper);
168
169 private:
170 PdfEncodingLimits m_Limits;
171 CodeUnitMap m_Mappings;
172 CodeUnitRanges m_Ranges;
173 bool m_MapDirty;
174 CodePointMapNode* m_codePointMapHead; // Head of a BST to lookup code points
175 };
176}
177
178#endif // PDF_CHAR_CODE_MAP_H
SPDX-FileCopyrightText: (C) 2005 Dominik Seichter domseichter@web.de SPDX-FileCopyrightText: (C) 2020...
A memory owning immutable block of code points, optimized for small segments as up to 3 elements can ...
Definition PdfEncodingCommon.h:141
A bidirectional map from character code units to unspecified code points.
Definition PdfCharCodeMap.h:79
const CodeUnitMap & GetMappings() const
Provides direct mappings.
Definition PdfCharCodeMap.h:150
const CodeUnitRanges & GetRanges() const
Provides range mappings.
Definition PdfCharCodeMap.h:154
Convenient type for char array storage and/or buffer with std::string compatibility.
Definition basetypes.h:38
SPDX-FileCopyrightText: (C) 2022 Francesco Pretto ceztko@gmail.com SPDX-License-Identifier: LGPL-2....
Definition basetypes.h:16
char32_t codepoint
A convenient typedef for an unspecified codepoint The underlying type is convenientely char32_t so it...
Definition PdfEncodingCommon.h:133
Represent a range in the "begincodespacerange" section.
Definition PdfCharCodeMap.h:57
A character code unit.
Definition PdfEncodingCommon.h:20