PoDoFo 1.2.0
Loading...
Searching...
No Matches
PdfCharCodeMap.h
1// SPDX-FileCopyrightText: 2022 Francesco Pretto <ceztko@gmail.com>
2// SPDX-License-Identifier: LGPL-2.0-or-later OR MPL-2.0
3
4#ifndef PDF_CHAR_CODE_MAP_H
5#define PDF_CHAR_CODE_MAP_H
6
7#include "PdfDeclarations.h"
8#include "PdfEncodingCommon.h"
9
10namespace PoDoFo
11{
12 struct CodePointMapNode;
13
14 struct PODOFO_API CodeUnitRange final
15 {
16 PdfCharCode SrcCodeLo;
17 unsigned Size = 0;
18 CodePointSpan DstCodeLo;
19
20 CodeUnitRange();
21
22 CodeUnitRange(PdfCharCode srcCodeLo, unsigned size, CodePointSpan dstCodeLo);
23
24 PdfCharCode GetSrcCodeHi() const;
25 };
26
27 struct PODOFO_API CodeUnitRangeInequality
28 {
29 using is_transparent = std::true_type;
30
31 bool operator()(const CodeUnitRange& lhs, const PdfCharCode& rhs) const
32 {
33 return lhs.SrcCodeLo < rhs;
34 }
35 bool operator()(const PdfCharCode& lhs, const CodeUnitRange& rhs) const
36 {
37 return lhs < rhs.SrcCodeLo;
38 }
39 bool operator()(const CodeUnitRange& lhs, const CodeUnitRange& rhs) const
40 {
41 return lhs.SrcCodeLo < rhs.SrcCodeLo;
42 }
43 };
44
45 using CodeUnitRanges = std::set<CodeUnitRange, CodeUnitRangeInequality>;
46
53 struct PODOFO_API CodeSpaceRange final
54 {
56 CodeSpaceRange(unsigned codeLo, unsigned codeHi, unsigned char codeSpaceSize);
57
58 unsigned CodeLo;
59 unsigned CodeHi;
60 unsigned char CodeSpaceSize;
61
62 PdfCharCode GetSrcCodeLo() const;
63 PdfCharCode GetSrcCodeHi() const;
64 };
65
75 class PODOFO_API PdfCharCodeMap final
76 {
77 PODOFO_PRIVATE_FRIEND(class PdfCMapEncodingFactory);
78
79 public:
81
83
85
86 private:
87 PdfCharCodeMap(CodeUnitMap&& mapping, CodeUnitRanges&& ranges, const PdfEncodingLimits& limits);
88
89 public:
94 void PushMapping(const PdfCharCode& codeUnit, const codepointview& codePoints);
95
98 void PushMapping(const PdfCharCode& codeUnit, codepoint codePoint);
99
104 void PushRange(const PdfCharCode& srcCodeLo, unsigned size, codepoint dstCodeLo);
105
110 void PushRange(const PdfCharCode& srcCodeLo, unsigned size, const codepointview& dstCodeLo);
111
114 bool TryGetCodePoints(const PdfCharCode& codeUnit, CodePointSpan& codePoints) const;
115
120 bool TryGetNextCharCode(std::string_view::iterator& it,
121 const std::string_view::iterator& end, PdfCharCode& code) const;
122
126 bool TryGetCharCode(const codepointview& codePoints, PdfCharCode& code) const;
127
130 bool TryGetCharCode(codepoint codePoint, PdfCharCode& code) const;
131
132 PdfCharCodeMap& operator=(PdfCharCodeMap&& map) noexcept;
133
134 const PdfEncodingLimits& GetLimits() const { return m_Limits; }
135
136 bool IsEmpty() const;
137
140 bool IsTrivialIdentity() const;
141
142 std::vector<CodeSpaceRange> GetCodeSpaceRanges() const;
143
144 public:
147 const CodeUnitMap& GetMappings() const { return m_Mappings; }
148
151 const CodeUnitRanges& GetRanges() const { return m_Ranges; }
152
153 private:
154 void move(PdfCharCodeMap& map) noexcept;
155 void pushMapping(const PdfCharCode& codeUnit, const codepointview& codePoints);
156
157 private:
158 PdfCharCodeMap(const PdfCharCodeMap&) = delete;
159 PdfCharCodeMap& operator=(const PdfCharCodeMap&) = delete;
160
161 private:
162 void updateLimits(const PdfCharCode& codeUnit);
163 void reviseCodePointMap();
164 bool tryFixNextRanges(const CodeUnitRanges::iterator& it, unsigned prevRangeCodeUpper);
165
166 private:
167 PdfEncodingLimits m_Limits;
168 CodeUnitMap m_Mappings;
169 CodeUnitRanges m_Ranges;
170 bool m_MapDirty;
171 CodePointMapNode* m_codePointMapHead; // Head of a BST to lookup code points
172 };
173}
174
175#endif // PDF_CHAR_CODE_MAP_H
This file should be included as the FIRST file in every header of PoDoFo lib.
A memory owning immutable block of code points, optimized for small segments as up to 3 elements can ...
Definition PdfEncodingCommon.h:135
A bidirectional map from character code units to unspecified code points.
Definition PdfCharCodeMap.h:76
const CodeUnitMap & GetMappings() const
Provides direct mappings.
Definition PdfCharCodeMap.h:147
const CodeUnitRanges & GetRanges() const
Provides range mappings.
Definition PdfCharCodeMap.h:151
Convenient type for char array storage and/or buffer with std::string compatibility.
Definition basetypes.h:35
All classes, functions, types and enums of PoDoFo are members of these namespace.
Definition basetypes.h:13
char32_t codepoint
A convenient typedef for an unspecified codepoint The underlying type is conveniently char32_t so it'...
Definition PdfEncodingCommon.h:127
Represent a range in the "begincodespacerange" section.
Definition PdfCharCodeMap.h:54
A character code unit.
Definition PdfEncodingCommon.h:17