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{
15 struct PODOFO_API PdfCharCode final
16 {
17 unsigned Code;
18
19 // RangeSize example <cd> -> 1, <00cd> -> 2
20 unsigned char CodeSpaceSize;
21
23
25 explicit PdfCharCode(unsigned code);
26
27 PdfCharCode(unsigned code, unsigned char codeSpaceSize);
28
29 bool operator<(const PdfCharCode& rhs) const;
30
31 bool operator==(const PdfCharCode& rhs) const;
32
33 bool operator!=(const PdfCharCode& rhs) const;
34
35 public:
36 unsigned GetByteCode(unsigned char byteIdx) const;
37 void AppendTo(std::string& str) const;
38 void WriteHexTo(std::string& str, bool wrap = true) const;
39 };
40
42 struct PODOFO_API PdfCID final
43 {
44 unsigned Id;
45 PdfCharCode Unit;
46
47 PdfCID();
48
50 explicit PdfCID(unsigned id);
51
52 PdfCID(unsigned id, const PdfCharCode& unit);
53
55 PdfCID(const PdfCharCode& unit);
56 };
57
59 struct PODOFO_API PdfGID final
60 {
61 unsigned Id = 0;
62 unsigned MetricsId = 0;
63
64 PdfGID();
65
66 PdfGID(unsigned id);
67
68 PdfGID(unsigned id, unsigned metricsId);
69 };
70
72 struct PODOFO_API PdfCharGIDInfo
73 {
74 unsigned Cid = 0;
75 unsigned OrigCid = 0;
77 };
78
79 struct PODOFO_API PdfEncodingLimits final
80 {
81 public:
82 PdfEncodingLimits(unsigned char minCodeSize, unsigned char maxCodeSize,
84
86 PdfEncodingLimits();
87
90 bool AreValid() const;
91
94 bool HaveValidCodeSizeRange() const;
95
96 PdfCharCode FirstChar; // The first defined character code
97 PdfCharCode LastChar; // The last defined character code
98 unsigned char MinCodeSize;
99 unsigned char MaxCodeSize;
100 };
101
102 struct PODOFO_API PdfCIDSystemInfo final
103 {
104 PdfString Registry;
105 PdfString Ordering;
106 int Supplement = 0;
107 };
108
115
118 class PODOFO_API CodePointSpan final
119 {
120 public:
124 CodePointSpan(std::initializer_list<codepoint> codepoints);
125 CodePointSpan(const codepointview& view);
126 CodePointSpan(const codepointview& view, codepoint codepoint);
128 void CopyTo(std::vector<codepoint>& codePoints) const;
129 codepointview view() const;
130 unsigned GetSize() const;
131 CodePointSpan& operator=(const CodePointSpan&);
132 size_t size() const;
133 const codepoint* data() const;
134
135 operator codepointview() const;
136
139 codepoint operator*() const;
140
141 private:
142 union
143 {
144 struct
145 {
146 uint32_t Size;
147 std::array<codepoint, 3> Data;
148 } m_Block;
149
150 struct
151 {
152 uint32_t Size;
153 std::unique_ptr<codepoint[]> Data;
154 } m_Array;
155 };
156 };
157
158 // Map code units -> code point(s)
159 // pp. 474-475 of PdfReference 1.7 "The value of dstString can be a string of up to 512 bytes"
160 using CodeUnitMap = std::unordered_map<PdfCharCode, CodePointSpan>;
161}
162
163namespace std
164{
166 template<>
167 struct hash<PoDoFo::PdfCharCode>
168 {
169 size_t operator()(const PoDoFo::PdfCharCode& code) const noexcept
170 {
171 return code.CodeSpaceSize << 24 | code.Code;
172 }
173 };
174}
175
176#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:119
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 CID (Character ID) with full code unit information.
Definition PdfEncodingCommon.h:43
A character code unit.
Definition PdfEncodingCommon.h:16
Represents a bundle of a CID and GID information.
Definition PdfEncodingCommon.h:73
PdfGID Gid
The identifier of the glyph in font program and PDF metrics.
Definition PdfEncodingCommon.h:76
Represents a GID (Glyph ID) with PDF metrics identifier.
Definition PdfEncodingCommon.h:60