PoDoFo 1.2.0
Loading...
Searching...
No Matches
PdfDifferenceEncoding.h
1// SPDX-FileCopyrightText: 2008 Dominik Seichter <domseichter@web.de>
2// SPDX-FileCopyrightText: 2020 Francesco Pretto <ceztko@gmail.com>
3// SPDX-License-Identifier: LGPL-2.0-or-later OR MPL-2.0
4
5#ifndef PDF_DIFFERENCE_ENCODING_H
6#define PDF_DIFFERENCE_ENCODING_H
7
8#include "PdfEncodingMap.h"
9#include "PdfArray.h"
10
11namespace PoDoFo {
12
13class PdfFontMetrics;
14struct CodePointMapNode;
15
16struct PODOFO_API PdfDifferenceMapping final
17{
18 PdfName Name;
19 unsigned char Code = 0;
20 CodePointSpan CodePoints;
21};
22
26class PODOFO_API PdfDifferenceMap final
27{
28 friend class PdfDifferenceEncoding;
29public:
30 using const_iterator = std::vector<PdfDifferenceMapping>::const_iterator;
31
32public:
36
37 PdfDifferenceMap(const PdfDifferenceMap& rhs) = default;
38 PdfDifferenceMap& operator=(const PdfDifferenceMap& rhs) = default;
39
48 void AddDifference(unsigned char code, char32_t codePoint);
49
58 void AddDifference(unsigned char code, const codepointview& codePoints);
59
67 bool TryGetMappedName(unsigned char code, const PdfName*& name) const;
68 bool TryGetMappedName(unsigned char code, const PdfName*& name, CodePointSpan& codePoints) const;
69
74 void ToArray(PdfArray& arr) const;
75
82 unsigned GetCount() const;
83
84 const_iterator begin() const { return m_differences.begin(); }
85
86 const_iterator end() const { return m_differences.end(); }
87
88private:
89 void AddDifference(unsigned char code, const std::string_view& name);
90
91 void addDifference(unsigned char code, const codepointview& codepoints, const PdfName& name);
92
93 struct DifferenceComparatorPredicate
94 {
95 public:
96 bool operator()(const PdfDifferenceMapping& diff1, const PdfDifferenceMapping& diff2) const
97 {
98 return diff1.Code < diff2.Code;
99 }
100 };
101
102 using DifferenceList = std::vector<PdfDifferenceMapping>;
103
104private:
105 DifferenceList m_differences;
106};
107
113{
114 friend class PdfDifferenceMap;
115
116public:
125
127
128public:
134 static bool TryCreateFromObject(const PdfObject& obj, const PdfFontMetrics& metrics,
135 std::unique_ptr<PdfDifferenceEncoding>& encoding);
136
144 static std::unique_ptr<PdfDifferenceEncoding> CreateFromObject(const PdfObject& obj, const PdfFontMetrics& metrics);
145
152 static bool TryGetCodePointsFromCharName(const std::string_view& name, CodePointSpan& codepoints);
153
160 const PdfDifferenceMap& GetDifferences() const { return m_differences; }
161
162protected:
163 void GetBaseEncoding(const PdfEncodingMap*& baseEncoding, const PdfDifferenceMap*& differences) const override;
164
165 void getExportObject(PdfIndirectObjectList& objects, PdfName& name, PdfObject*& obj) const override;
166 bool tryGetCharCode(char32_t codePoint, PdfCharCode& codeUnit) const override;
167 bool tryGetCharCodeSpan(const unicodeview& codePoints, PdfCharCode& codeUnit) const override;
168 bool tryGetNextCharCode(std::string_view::iterator& it,
169 const std::string_view::iterator& end, PdfCharCode& codeUnit) const override;
170 bool tryGetCodePoints(const PdfCharCode& codeUnit, const unsigned* cidId, CodePointSpan& codePoints) const override;
171
172private:
173 static bool TryGetCodePointsFromCharName(std::string_view charName, CodePointSpan& codepoints, const PdfName*& actualName);
174
175 void buildReverseMap();
176
177private:
178 PdfEncodingMapConstPtr m_baseEncoding;
179 PdfDifferenceMap m_differences;
180 CodePointMapNode* m_reverseMap;
181};
182
183};
184
185#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:135
This class represents a PdfArray Use it for all arrays that are written to a PDF file.
Definition PdfArray.h:79
PdfDifferenceEncoding is an encoding, which is based on either the fonts encoding or a predefined enc...
Definition PdfDifferenceEncoding.h:113
const PdfDifferenceMap & GetDifferences() const
Get read-only access to the object containing the actual differences.
Definition PdfDifferenceEncoding.h:160
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:27
PdfEncodingMap used by legacy encodings like PdfBuiltInEncoding or PdfDifferenceEncoding that can def...
Definition PdfEncodingMap.h:252
A PdfEncodingMap is a low level interface to convert between utf8 and encoded strings in and to deter...
Definition PdfEncodingMap.h:30
This abstract class provides access to font metrics information.
Definition PdfFontMetrics.h:34
A list of PdfObjects that constitutes the indirect object list of the document The PdfParser will rea...
Definition PdfIndirectObjectList.h:29
This class represents a PdfName.
Definition PdfName.h:22
This class represents a PDF indirect Object in memory.
Definition PdfObject.h:33
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
cspan< char32_t > unicodeview
Unicode code point view.
Definition basetypes.h:24
@ 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:353
A character code unit.
Definition PdfEncodingCommon.h:17