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
51 struct PODOFO_API CodeSpaceRange final
52 {
54 CodeSpaceRange(unsigned codeLo, unsigned codeHi, unsigned char codeSpaceSize);
55
56 unsigned CodeLo;
57 unsigned CodeHi;
58 unsigned char CodeSpaceSize;
59
60 PdfCharCode GetSrcCodeLo() const;
61 PdfCharCode GetSrcCodeHi() const;
62 };
63
71 class PODOFO_API PdfCharCodeMap final
72 {
73 PODOFO_PRIVATE_FRIEND(class PdfCMapEncodingFactory);
74
75 public:
77
79
81
82 private:
83 PdfCharCodeMap(CodeUnitMap&& mapping, CodeUnitRanges&& ranges, const PdfEncodingLimits& limits);
84
85 public:
89 void PushMapping(const PdfCharCode& codeUnit, const codepointview& codePoints);
90
92 void PushMapping(const PdfCharCode& codeUnit, codepoint codePoint);
93
97 void PushRange(const PdfCharCode& srcCodeLo, unsigned size, codepoint dstCodeLo);
98
102 void PushRange(const PdfCharCode& srcCodeLo, unsigned size, const codepointview& dstCodeLo);
103
105 bool TryGetCodePoints(const PdfCharCode& codeUnit, CodePointSpan& codePoints) const;
106
110 bool TryGetNextCharCode(std::string_view::iterator& it,
111 const std::string_view::iterator& end, PdfCharCode& code) const;
112
115 bool TryGetCharCode(const codepointview& codePoints, PdfCharCode& code) const;
116
118 bool TryGetCharCode(codepoint codePoint, PdfCharCode& code) const;
119
120 PdfCharCodeMap& operator=(PdfCharCodeMap&& map) noexcept;
121
122 const PdfEncodingLimits& GetLimits() const { return m_Limits; }
123
124 bool IsEmpty() const;
125
127 bool IsTrivialIdentity() const;
128
129 std::vector<CodeSpaceRange> GetCodeSpaceRanges() const;
130
131 public:
133 const CodeUnitMap& GetMappings() const { return m_Mappings; }
134
136 const CodeUnitRanges& GetRanges() const { return m_Ranges; }
137
138 private:
139 void move(PdfCharCodeMap& map) noexcept;
140 void pushMapping(const PdfCharCode& codeUnit, const codepointview& codePoints);
141
142 private:
143 PdfCharCodeMap(const PdfCharCodeMap&) = delete;
144 PdfCharCodeMap& operator=(const PdfCharCodeMap&) = delete;
145
146 private:
147 void updateLimits(const PdfCharCode& codeUnit);
148 void reviseCodePointMap();
149 bool tryFixNextRanges(const CodeUnitRanges::iterator& it, unsigned prevRangeCodeUpper);
150
151 private:
152 PdfEncodingLimits m_Limits;
153 CodeUnitMap m_Mappings;
154 CodeUnitRanges m_Ranges;
155 bool m_MapDirty;
156 CodePointMapNode* m_codePointMapHead; // Head of a BST to lookup code points
157 };
158}
159
160#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:119
A bidirectional map from character code units to unspecified code points.
Definition PdfCharCodeMap.h:72
const CodeUnitMap & GetMappings() const
Provides direct mappings.
Definition PdfCharCodeMap.h:133
const CodeUnitRanges & GetRanges() const
Provides range mappings.
Definition PdfCharCodeMap.h:136
Convenient type for char array storage and/or buffer with std::string compatibility.
Definition basetypes.h:30
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:113
Represent a range in the "begincodespacerange" section.
Definition PdfCharCodeMap.h:52
A character code unit.
Definition PdfEncodingCommon.h:16