PoDoFo 1.0.0-dev
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
46 // TODO: Optimize me
47 using PdfCharCodeList = std::vector<PdfCharCode>;
48
51 struct PODOFO_API PdfCID final
52 {
53 unsigned Id;
54 PdfCharCode Unit;
55
56 PdfCID();
57
61 explicit PdfCID(unsigned id);
62
63 PdfCID(unsigned id, const PdfCharCode& unit);
64
68 PdfCID(const PdfCharCode& unit);
69 };
70
73 struct PODOFO_API PdfGID final
74 {
75 unsigned Id = 0;
76 unsigned MetricsId = 0;
77
78 PdfGID();
79
80 PdfGID(unsigned id);
81
82 PdfGID(unsigned id, unsigned metricsId);
83 };
84
87 struct PODOFO_API PdfCharGIDInfo
88 {
89 unsigned Cid = 0;
90 unsigned OrigCid = 0;
92 };
93
94 struct PODOFO_API PdfEncodingLimits final
95 {
96 public:
97 PdfEncodingLimits(unsigned char minCodeSize, unsigned char maxCodeSize,
99
102 PdfEncodingLimits();
103
107 bool AreValid() const;
108
112 bool HaveValidCodeSizeRange() const;
113
114 PdfCharCode FirstChar; // The first defined character code
115 PdfCharCode LastChar; // The last defined character code
116 unsigned char MinCodeSize;
117 unsigned char MaxCodeSize;
118 };
119
120 struct PODOFO_API PdfCIDSystemInfo final
121 {
122 PdfString Registry;
123 PdfString Ordering;
124 int Supplement = 0;
125 };
126
135
140 class PODOFO_API CodePointSpan final
141 {
142 public:
146 CodePointSpan(std::initializer_list<codepoint> codepoints);
147 CodePointSpan(const codepointview& view);
148 CodePointSpan(const codepointview& view, codepoint codepoint);
150 void CopyTo(std::vector<codepoint>& codePoints) const;
151 codepointview view() const;
152 unsigned GetSize() const;
153 CodePointSpan& operator=(const CodePointSpan&);
154 size_t size() const;
155 const codepoint* data() const;
156
157 operator codepointview() const;
158
163 codepoint operator*() const;
164
165 private:
166 union
167 {
168 struct
169 {
170 uint32_t Size;
171 std::array<codepoint, 3> Data;
172 } m_Block;
173
174 struct
175 {
176 uint32_t Size;
177 std::unique_ptr<codepoint[]> Data;
178 } m_Array;
179 };
180 };
181
182 // Map code units -> code point(s)
183 // pp. 474-475 of PdfReference 1.7 "The value of dstString can be a string of up to 512 bytes"
184 using CodeUnitMap = std::unordered_map<PdfCharCode, CodePointSpan>;
185}
186
187namespace std
188{
191 template<>
192 struct hash<PoDoFo::PdfCharCode>
193 {
194 size_t operator()(const PoDoFo::PdfCharCode& code) const noexcept
195 {
196 return code.CodeSpaceSize << 24 | code.Code;
197 }
198 };
199}
200
201#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:141
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 CID (Character ID) with full code unit information.
Definition PdfEncodingCommon.h:52
A character code unit.
Definition PdfEncodingCommon.h:20
Represents a bundle of a CID and GID information.
Definition PdfEncodingCommon.h:88
PdfGID Gid
The identifier of the glyph in font program and PDF metrics.
Definition PdfEncodingCommon.h:91
Represents a GID (Glyph ID) with PDF metrics identifier.
Definition PdfEncodingCommon.h:74