PoDoFo 1.1.0
Loading...
Searching...
No Matches
PdfDifferenceEncoding.h
1
7#ifndef PDF_DIFFERENCE_ENCODING_H
8#define PDF_DIFFERENCE_ENCODING_H
9
10#include "PdfEncodingMap.h"
11#include "PdfArray.h"
12
13namespace PoDoFo {
14
15class PdfFontMetrics;
16struct CodePointMapNode;
17
18struct PODOFO_API PdfDifferenceMapping final
19{
20 PdfName Name;
21 unsigned char Code = 0;
22 CodePointSpan CodePoints;
23};
24
28class PODOFO_API PdfDifferenceMap final
29{
30 friend class PdfDifferenceEncoding;
31public:
32 using const_iterator = std::vector<PdfDifferenceMapping>::const_iterator;
33
34public:
38
39 PdfDifferenceMap(const PdfDifferenceMap& rhs) = default;
40 PdfDifferenceMap& operator=(const PdfDifferenceMap& rhs) = default;
41
50 void AddDifference(unsigned char code, char32_t codePoint);
51
60 void AddDifference(unsigned char code, const codepointview& codePoints);
61
69 bool TryGetMappedName(unsigned char code, const PdfName*& name) const;
70 bool TryGetMappedName(unsigned char code, const PdfName*& name, CodePointSpan& codePoints) const;
71
76 void ToArray(PdfArray& arr) const;
77
84 unsigned GetCount() const;
85
86 const_iterator begin() const { return m_differences.begin(); }
87
88 const_iterator end() const { return m_differences.end(); }
89
90private:
91 void AddDifference(unsigned char code, const std::string_view& name);
92
93 void addDifference(unsigned char code, const codepointview& codepoints, const PdfName& name);
94
95 struct DifferenceComparatorPredicate
96 {
97 public:
98 bool operator()(const PdfDifferenceMapping& diff1, const PdfDifferenceMapping& diff2) const
99 {
100 return diff1.Code < diff2.Code;
101 }
102 };
103
104 using DifferenceList = std::vector<PdfDifferenceMapping>;
105
106private:
107 DifferenceList m_differences;
108};
109
115{
116 friend class PdfDifferenceMap;
117
118public:
127
129
130public:
136 static bool TryCreateFromObject(const PdfObject& obj, const PdfFontMetrics& metrics,
137 std::unique_ptr<PdfDifferenceEncoding>& encoding);
138
146 static std::unique_ptr<PdfDifferenceEncoding> CreateFromObject(const PdfObject& obj, const PdfFontMetrics& metrics);
147
154 static bool TryGetCodePointsFromCharName(const std::string_view& name, CodePointSpan& codepoints);
155
162 const PdfDifferenceMap& GetDifferences() const { return m_differences; }
163
164protected:
165 void GetBaseEncoding(const PdfEncodingMap*& baseEncoding, const PdfDifferenceMap*& differences) const override;
166
167 void getExportObject(PdfIndirectObjectList& objects, PdfName& name, PdfObject*& obj) const override;
168 bool tryGetCharCode(char32_t codePoint, PdfCharCode& codeUnit) const override;
169 bool tryGetCharCodeSpan(const unicodeview& codePoints, PdfCharCode& codeUnit) const override;
170 bool tryGetNextCharCode(std::string_view::iterator& it,
171 const std::string_view::iterator& end, PdfCharCode& codeUnit) const override;
172 bool tryGetCodePoints(const PdfCharCode& codeUnit, const unsigned* cidId, CodePointSpan& codePoints) const override;
173
174private:
175 static bool TryGetCodePointsFromCharName(std::string_view charName, CodePointSpan& codepoints, const PdfName*& actualName);
176
177 void buildReverseMap();
178
179private:
180 PdfEncodingMapConstPtr m_baseEncoding;
181 PdfDifferenceMap m_differences;
182 CodePointMapNode* m_reverseMap;
183};
184
185};
186
187#endif // PDF_DIFFERENCE_ENCODING_H
A memory owning immutable block of code points, optimized for small segments as up to 3 elements can ...
Definition PdfEncodingCommon.h:138
This class represents a PdfArray Use it for all arrays that are written to a PDF file.
Definition PdfArray.h:81
PdfDifferenceEncoding is an encoding, which is based on either the fonts encoding or a predefined enc...
Definition PdfDifferenceEncoding.h:115
const PdfDifferenceMap & GetDifferences() const
Get read-only access to the object containing the actual differences.
Definition PdfDifferenceEncoding.h:162
static bool TryGetCodePointsFromCharName(const std::string_view &name, CodePointSpan &codepoints)
Try to convert a standard character name to a unicode code points.
A helper class for PdfDifferenceEncoding that can be used to create a differences array.
Definition PdfDifferenceEncoding.h:29
PdfEncodingMap used by legacy encodings like PdfBuiltInEncoding or PdfDifferenceEncoding that can def...
Definition PdfEncodingMap.h:254
A PdfEncodingMap is a low level interface to convert between utf8 and encoded strings in and to deter...
Definition PdfEncodingMap.h:32
This abstract class provides access to font metrics information.
Definition PdfFontMetrics.h:36
A list of PdfObjects that constitutes the indirect object list of the document The PdfParser will rea...
Definition PdfIndirectObjectList.h:31
This class represents a PdfName.
Definition PdfName.h:24
This class represents a PDF indirect Object in memory.
Definition PdfObject.h:35
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
cspan< char32_t > unicodeview
Unicode code point view.
Definition basetypes.h:27
@ Name
Name datatype. Names are used as keys in dictionary to reference values.
std::shared_ptr< const PdfEncodingMap > PdfEncodingMapConstPtr
Convenience typedef for a const /Encoding map entry shared ptr.
Definition PdfEncodingMap.h:355
A character code unit.
Definition PdfEncodingCommon.h:20