PoDoFo 1.2.0
Loading...
Searching...
No Matches
PdfAcroForm.h
1// SPDX-FileCopyrightText: 2007 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_ACRO_FORM_H
6#define PDF_ACRO_FORM_H
7
8#include "PdfField.h"
9
10namespace PoDoFo {
11
12class PdfDocument;
13
15{
16 None = 0,
18};
19
20enum class PdfAcroFormSigFlags
21{
22 None = 0,
23 SignaturesExist = 1,
24 AppendOnly = 2,
25};
26
27class PODOFO_API PdfAcroForm final : public PdfDictionaryElement
28{
29 friend class PdfField;
30 friend class PdfDocument;
31 friend class PdfSigningContext;
32 friend class PdfSignature;
33
34private:
38 PdfAcroForm(PdfDocument & doc,
39 PdfAcroFormDefaulAppearance defaultAppearance = PdfAcroFormDefaulAppearance::ArialBlack);
40
43 PdfAcroForm(PdfObject& obj);
44
45public:
52 void SetNeedAppearances(bool needAppearances);
53
60 bool GetNeedAppearances() const;
61
65 PdfAcroFormSigFlags GetSigFlags() const;
66
67 template <typename TField>
68 TField& CreateField(const std::string_view& name);
69
70 PdfField& CreateField(const std::string_view& name, PdfFieldType fieldType);
71
78 PdfField& GetFieldAt(unsigned index);
79
80 const PdfField& GetFieldAt(unsigned index) const;
81
82 PdfField& GetField(const PdfReference& ref);
83
84 const PdfField& GetField(const PdfReference& ref) const;
85
88 void RemoveFieldAt(unsigned index);
89
92 void RemoveField(const PdfReference& ref);
93
94 unsigned GetFieldCount() const;
95
96public:
97 using FieldList = std::vector<std::shared_ptr<PdfField>>;
98
99 template <typename TObject, typename TListIterator>
100 class Iterator final
101 {
102 friend class PdfAcroForm;
103 public:
104 using difference_type = void;
105 using value_type = TObject*;
106 using pointer = void;
107 using reference = void;
108 using iterator_category = std::forward_iterator_tag;
109 public:
110 Iterator() { }
111 private:
112 Iterator(const TListIterator& iterator) : m_iterator(iterator) { }
113 public:
114 Iterator(const Iterator&) = default;
115 Iterator& operator=(const Iterator&) = default;
116 bool operator==(const Iterator& rhs) const
117 {
118 return m_iterator == rhs.m_iterator;
119 }
120 bool operator!=(const Iterator& rhs) const
121 {
122 return m_iterator != rhs.m_iterator;
123 }
124 Iterator& operator++()
125 {
126 m_iterator++;
127 return *this;
128 }
129 Iterator operator++(int)
130 {
131 auto copy = *this;
132 m_iterator++;
133 return copy;
134 }
135 value_type operator*()
136 {
137 return (*m_iterator).get();
138 }
139 value_type operator->()
140 {
141 return (*m_iterator).get();
142 }
143 private:
144 TListIterator m_iterator;
145 };
146
147 using iterator = Iterator<PdfField, FieldList::iterator>;
148 using const_iterator = Iterator<const PdfField, FieldList::const_iterator>;
149
150public:
151 iterator begin();
152 iterator end();
153 const_iterator begin() const;
154 const_iterator end() const;
155
156private:
157 // To be called by PdfField
158 PdfField& CreateField(PdfObject& obj, PdfFieldType type);
159 PdfField& AddField(std::unique_ptr<PdfField>&& field);
160 std::shared_ptr<PdfField> GetFieldPtr(const PdfReference& ref);
161
162 // To be called by PdfSignature/PdfSigningContext
163 void SetSigFlags(PdfAcroFormSigFlags flags);
164
165private:
169 void init(PdfAcroFormDefaulAppearance defaultAppearance);
170
171 PdfArray* getFieldArray() const;
172
173 void initFields();
174
175 PdfField& getField(unsigned index) const;
176 PdfField& getField(const PdfReference& ref) const;
177
178 void fixIndices(unsigned index);
179
180private:
181 using FieldMap = std::map<PdfReference, unsigned>;
182
183private:
184 FieldList m_Fields;
185 std::unique_ptr<FieldMap> m_fieldMap;
186 PdfArray* m_fieldArray;
187};
188
189template<typename TField>
190TField& PdfAcroForm::CreateField(const std::string_view& name)
191{
192 return static_cast<TField&>(CreateField(name, PdfField::GetFieldType<TField>()));
193}
194
195};
196
197ENABLE_BITMASK_OPERATORS(PoDoFo::PdfAcroFormSigFlags);
198
199#endif // PDF_ACRO_FORM_H
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
PdfAcroFormDefaulAppearance
Definition PdfAcroForm.h:15
@ None
Do not add a default appearance.
@ ArialBlack
Add a default appearance with Arial embedded and black text if no other DA key is present.