PoDoFo 1.1.0
Loading...
Searching...
No Matches
PdfEncodingCommon.h
1
7#ifndef PDF_ENCODING_COMMON_H
8#define PDF_ENCODING_COMMON_H
9
10#include "PdfString.h"
11
12namespace PoDoFo
13{
19 struct PODOFO_API PdfCharCode final
20 {
21 unsigned Code;
22
23 // RangeSize example <cd> -> 1, <00cd> -> 2
24 unsigned char CodeSpaceSize;
25
27
30 explicit PdfCharCode(unsigned code);
31
32 PdfCharCode(unsigned code, unsigned char codeSpaceSize);
33
34 bool operator<(const PdfCharCode& rhs) const;
35
36 bool operator==(const PdfCharCode& rhs) const;
37
38 bool operator!=(const PdfCharCode& rhs) const;
39
40 public:
41 unsigned GetByteCode(unsigned char byteIdx) const;
42 void AppendTo(std::string& str) const;
43 void WriteHexTo(std::string& str, bool wrap = true) const;
44 };
45
48 struct PODOFO_API PdfCID final
49 {
50 unsigned Id;
51 PdfCharCode Unit;
52
53 PdfCID();
54
58 explicit PdfCID(unsigned id);
59
60 PdfCID(unsigned id, const PdfCharCode& unit);
61
65 PdfCID(const PdfCharCode& unit);
66 };
67
70 struct PODOFO_API PdfGID final
71 {
72 unsigned Id = 0;
73 unsigned MetricsId = 0;
74
75 PdfGID();
76
77 PdfGID(unsigned id);
78
79 PdfGID(unsigned id, unsigned metricsId);
80 };
81
84 struct PODOFO_API PdfCharGIDInfo
85 {
86 unsigned Cid = 0;
87 unsigned OrigCid = 0;
89 };
90
91 struct PODOFO_API PdfEncodingLimits final
92 {
93 public:
94 PdfEncodingLimits(unsigned char minCodeSize, unsigned char maxCodeSize,
96
99 PdfEncodingLimits();
100
104 bool AreValid() const;
105
109 bool HaveValidCodeSizeRange() const;
110
111 PdfCharCode FirstChar; // The first defined character code
112 PdfCharCode LastChar; // The last defined character code
113 unsigned char MinCodeSize;
114 unsigned char MaxCodeSize;
115 };
116
117 struct PODOFO_API PdfCIDSystemInfo final
118 {
119 PdfString Registry;
120 PdfString Ordering;
121 int Supplement = 0;
122 };
123
132
137 class PODOFO_API CodePointSpan final
138 {
139 public:
143 CodePointSpan(std::initializer_list<codepoint> codepoints);
144 CodePointSpan(const codepointview& view);
145 CodePointSpan(const codepointview& view, codepoint codepoint);
147 void CopyTo(std::vector<codepoint>& codePoints) const;
148 codepointview view() const;
149 unsigned GetSize() const;
150 CodePointSpan& operator=(const CodePointSpan&);
151 size_t size() const;
152 const codepoint* data() const;
153
154 operator codepointview() const;
155
160 codepoint operator*() const;
161
162 private:
163 union
164 {
165 struct
166 {
167 uint32_t Size;
168 std::array<codepoint, 3> Data;
169 } m_Block;
170
171 struct
172 {
173 uint32_t Size;
174 std::unique_ptr<codepoint[]> Data;
175 } m_Array;
176 };
177 };
178
179 // Map code units -> code point(s)
180 // pp. 474-475 of PdfReference 1.7 "The value of dstString can be a string of up to 512 bytes"
181 using CodeUnitMap = std::unordered_map<PdfCharCode, CodePointSpan>;
182}
183
184namespace std
185{
188 template<>
189 struct hash<PoDoFo::PdfCharCode>
190 {
191 size_t operator()(const PoDoFo::PdfCharCode& code) const noexcept
192 {
193 return code.CodeSpaceSize << 24 | code.Code;
194 }
195 };
196}
197
198#endif // PDF_ENCODING_COMMON_H
A memory owning immutable block of code points, optimized for small segments as up to 3 elements can ...
Definition PdfEncodingCommon.h:138
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:130
Represent a CID (Character ID) with full code unit information.
Definition PdfEncodingCommon.h:49
A character code unit.
Definition PdfEncodingCommon.h:20
Represents a bundle of a CID and GID information.
Definition PdfEncodingCommon.h:85
PdfGID Gid
The identifier of the glyph in font program and PDF metrics.
Definition PdfEncodingCommon.h:88
Represents a GID (Glyph ID) with PDF metrics identifier.
Definition PdfEncodingCommon.h:71