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
25class PODOFO_API PdfDifferenceMap final
26{
27 friend class PdfDifferenceEncoding;
28public:
29 using const_iterator = std::vector<PdfDifferenceMapping>::const_iterator;
30
31public:
34
35 PdfDifferenceMap(const PdfDifferenceMap& rhs) = default;
36 PdfDifferenceMap& operator=(const PdfDifferenceMap& rhs) = default;
37
45 void AddDifference(unsigned char code, char32_t codePoint);
46
54 void AddDifference(unsigned char code, const codepointview& codePoints);
55
62 bool TryGetMappedName(unsigned char code, const PdfName*& name) const;
63 bool TryGetMappedName(unsigned char code, const PdfName*& name, CodePointSpan& codePoints) const;
64
68 void ToArray(PdfArray& arr) const;
69
75 unsigned GetCount() const;
76
77 const_iterator begin() const { return m_differences.begin(); }
78
79 const_iterator end() const { return m_differences.end(); }
80
81private:
82 void AddDifference(unsigned char code, const std::string_view& name);
83
84 void addDifference(unsigned char code, const codepointview& codepoints, const PdfName& name);
85
86 struct DifferenceComparatorPredicate
87 {
88 public:
89 bool operator()(const PdfDifferenceMapping& diff1, const PdfDifferenceMapping& diff2) const
90 {
91 return diff1.Code < diff2.Code;
92 }
93 };
94
95 using DifferenceList = std::vector<PdfDifferenceMapping>;
96
97private:
98 DifferenceList m_differences;
99};
100
105{
106 friend class PdfDifferenceMap;
107
108public:
116
118
119public:
124 static bool TryCreateFromObject(const PdfObject& obj, const PdfFontMetrics& metrics,
125 std::unique_ptr<PdfDifferenceEncoding>& encoding);
126
133 static std::unique_ptr<PdfDifferenceEncoding> CreateFromObject(const PdfObject& obj, const PdfFontMetrics& metrics);
134
140 static bool TryGetCodePointsFromCharName(const std::string_view& name, CodePointSpan& codepoints);
141
146 const PdfDifferenceMap& GetDifferences() const { return m_differences; }
147
148protected:
149 void GetBaseEncoding(const PdfEncodingMap*& baseEncoding, const PdfDifferenceMap*& differences) const override;
150
151 void getExportObject(PdfIndirectObjectList& objects, PdfName& name, PdfObject*& obj) const override;
152 bool tryGetCharCode(char32_t codePoint, PdfCharCode& codeUnit) const override;
153 bool tryGetCharCodeSpan(const unicodeview& codePoints, PdfCharCode& codeUnit) const override;
154 bool tryGetNextCharCode(std::string_view::iterator& it,
155 const std::string_view::iterator& end, PdfCharCode& codeUnit) const override;
156 bool tryGetCodePoints(const PdfCharCode& codeUnit, const unsigned* cidId, CodePointSpan& codePoints) const override;
157
158private:
159 static bool TryGetCodePointsFromCharName(std::string_view charName, CodePointSpan& codepoints, const PdfName*& actualName);
160
161 void buildReverseMap();
162
163private:
164 PdfEncodingMapConstPtr m_baseEncoding;
165 PdfDifferenceMap m_differences;
166 CodePointMapNode* m_reverseMap;
167};
168
169};
170
171#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:119
This class represents a PdfArray Use it for all arrays that are written to a PDF file.
Definition PdfArray.h:76
PdfDifferenceEncoding is an encoding, which is based on either the fonts encoding or a predefined enc...
Definition PdfDifferenceEncoding.h:105
const PdfDifferenceMap & GetDifferences() const
Get read-only access to the object containing the actual differences.
Definition PdfDifferenceEncoding.h:146
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:26
PdfEncodingMap used by legacy encodings like PdfBuiltInEncoding or PdfDifferenceEncoding that can def...
Definition PdfEncodingMap.h:217
A PdfEncodingMap is a low level interface to convert between utf8 and encoded strings in and to deter...
Definition PdfEncodingMap.h:28
This abstract class provides access to font metrics information.
Definition PdfFontMetrics.h:31
A list of PdfObjects that constitutes the indirect object list of the document The PdfParser will rea...
Definition PdfIndirectObjectList.h:34
This class represents a PdfName.
Definition PdfName.h:21
This class represents a PDF indirect Object in memory.
Definition PdfObject.h:31
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
cspan< char32_t > unicodeview
Unicode code point view.
Definition basetypes.h:21
@ 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:311
A character code unit.
Definition PdfEncodingCommon.h:16