PoDoFo 1.2.0
Loading...
Searching...
No Matches
PdfEncodingCommon.h
1// SPDX-FileCopyrightText: 2021 Francesco Pretto <ceztko@gmail.com>
2// SPDX-License-Identifier: LGPL-2.0-or-later OR MPL-2.0
3
4#ifndef PDF_ENCODING_COMMON_H
5#define PDF_ENCODING_COMMON_H
6
7#include "PdfString.h"
8
9namespace PoDoFo
10{
16 struct PODOFO_API PdfCharCode final
17 {
18 unsigned Code;
19
20 // RangeSize example <cd> -> 1, <00cd> -> 2
21 unsigned char CodeSpaceSize;
22
24
27 explicit PdfCharCode(unsigned code);
28
29 PdfCharCode(unsigned code, unsigned char codeSpaceSize);
30
31 bool operator<(const PdfCharCode& rhs) const;
32
33 bool operator==(const PdfCharCode& rhs) const;
34
35 bool operator!=(const PdfCharCode& rhs) const;
36
37 public:
38 unsigned GetByteCode(unsigned char byteIdx) const;
39 void AppendTo(std::string& str) const;
40 void WriteHexTo(std::string& str, bool wrap = true) const;
41 };
42
45 struct PODOFO_API PdfCID final
46 {
47 unsigned Id;
48 PdfCharCode Unit;
49
50 PdfCID();
51
55 explicit PdfCID(unsigned id);
56
57 PdfCID(unsigned id, const PdfCharCode& unit);
58
62 PdfCID(const PdfCharCode& unit);
63 };
64
67 struct PODOFO_API PdfGID final
68 {
69 unsigned Id = 0;
70 unsigned MetricsId = 0;
71
72 PdfGID();
73
74 PdfGID(unsigned id);
75
76 PdfGID(unsigned id, unsigned metricsId);
77 };
78
81 struct PODOFO_API PdfCharGIDInfo
82 {
83 unsigned Cid = 0;
84 unsigned OrigCid = 0;
86 };
87
88 struct PODOFO_API PdfEncodingLimits final
89 {
90 public:
91 PdfEncodingLimits(unsigned char minCodeSize, unsigned char maxCodeSize,
93
96 PdfEncodingLimits();
97
101 bool AreValid() const;
102
106 bool HaveValidCodeSizeRange() const;
107
108 PdfCharCode FirstChar; // The first defined character code
109 PdfCharCode LastChar; // The last defined character code
110 unsigned char MinCodeSize;
111 unsigned char MaxCodeSize;
112 };
113
114 struct PODOFO_API PdfCIDSystemInfo final
115 {
116 PdfString Registry;
117 PdfString Ordering;
118 int Supplement = 0;
119 };
120
129
134 class PODOFO_API CodePointSpan final
135 {
136 public:
140 CodePointSpan(std::initializer_list<codepoint> codepoints);
141 CodePointSpan(const codepointview& view);
142 CodePointSpan(const codepointview& view, codepoint codepoint);
144 void CopyTo(std::vector<codepoint>& codePoints) const;
145 codepointview view() const;
146 unsigned GetSize() const;
147 CodePointSpan& operator=(const CodePointSpan&);
148 size_t size() const;
149 const codepoint* data() const;
150
151 operator codepointview() const;
152
157 codepoint operator*() const;
158
159 private:
160 union
161 {
162 struct
163 {
164 uint32_t Size;
165 std::array<codepoint, 3> Data;
166 } m_Block;
167
168 struct
169 {
170 uint32_t Size;
171 std::unique_ptr<codepoint[]> Data;
172 } m_Array;
173 };
174 };
175
176 // Map code units -> code point(s)
177 // pp. 474-475 of PdfReference 1.7 "The value of dstString can be a string of up to 512 bytes"
178 using CodeUnitMap = std::unordered_map<PdfCharCode, CodePointSpan>;
179}
180
181namespace std
182{
185 template<>
186 struct hash<PoDoFo::PdfCharCode>
187 {
188 size_t operator()(const PoDoFo::PdfCharCode& code) const noexcept
189 {
190 return code.CodeSpaceSize << 24 | code.Code;
191 }
192 };
193}
194
195#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:135
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 CID (Character ID) with full code unit information.
Definition PdfEncodingCommon.h:46
A character code unit.
Definition PdfEncodingCommon.h:17
Represents a bundle of a CID and GID information.
Definition PdfEncodingCommon.h:82
PdfGID Gid
The identifier of the glyph in font program and PDF metrics.
Definition PdfEncodingCommon.h:85
Represents a GID (Glyph ID) with PDF metrics identifier.
Definition PdfEncodingCommon.h:68