PoDoFo 1.0.0-dev
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:
94 void AddDifference(unsigned char code, const std::string_view& name);
95
96 void addDifference(unsigned char code, const codepointview& codepoints, const PdfName& name);
97
98 struct DifferenceComparatorPredicate
99 {
100 public:
101 bool operator()(const PdfDifferenceMapping& diff1, const PdfDifferenceMapping& diff2) const
102 {
103 return diff1.Code < diff2.Code;
104 }
105 };
106
107 using DifferenceList = std::vector<PdfDifferenceMapping>;
108
109private:
110 DifferenceList m_differences;
111};
112
118{
119 friend class PdfDifferenceMap;
120
121public:
130
132
133public:
139 static bool TryCreateFromObject(const PdfObject& obj, const PdfFontMetrics& metrics,
140 std::unique_ptr<PdfDifferenceEncoding>& encoding);
141
149 static std::unique_ptr<PdfDifferenceEncoding> CreateFromObject(const PdfObject& obj, const PdfFontMetrics& metrics);
150
157 static bool TryGetCodePointsFromCharName(const std::string_view& name, CodePointSpan& codepoints);
158
165 const PdfDifferenceMap& GetDifferences() const { return m_differences; }
166
167protected:
168 void GetBaseEncoding(const PdfEncodingMap*& baseEncoding, const PdfDifferenceMap*& differences) const override;
169
170 void getExportObject(PdfIndirectObjectList& objects, PdfName& name, PdfObject*& obj) const override;
171 bool tryGetCharCode(char32_t codePoint, PdfCharCode& codeUnit) const override;
172 bool tryGetCharCodeSpan(const unicodeview& codePoints, PdfCharCode& codeUnit) const override;
173 bool tryGetNextCharCode(std::string_view::iterator& it,
174 const std::string_view::iterator& end, PdfCharCode& codeUnit) const override;
175 bool tryGetCodePoints(const PdfCharCode& codeUnit, const unsigned* cidId, CodePointSpan& codePoints) const override;
176
177private:
178 static bool TryGetCodePointsFromCharName(std::string_view charName, CodePointSpan& codepoints, const PdfName*& actualName);
179
180 void buildReverseMap();
181
182private:
183 PdfEncodingMapConstPtr m_baseEncoding;
184 PdfDifferenceMap m_differences;
185 CodePointMapNode* m_reverseMap;
186};
187
188};
189
190#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:141
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:118
const PdfDifferenceMap & GetDifferences() const
Get read-only access to the object containing the actual differences.
Definition PdfDifferenceEncoding.h:165
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:30
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