Poppler Qt5  21.05.0
poppler-form.h
1 /* poppler-form.h: qt interface to poppler
2  * Copyright (C) 2007-2008, Pino Toscano <pino@kde.org>
3  * Copyright (C) 2008, 2011, 2016, 2017, 2019, 2020, Albert Astals Cid <aacid@kde.org>
4  * Copyright (C) 2012, Adam Reichold <adamreichold@myopera.com>
5  * Copyright (C) 2016, Hanno Meyer-Thurow <h.mth@web.de>
6  * Copyright (C) 2017, Hans-Ulrich Jüttner <huj@froreich-bioscientia.de>
7  * Copyright (C) 2017, Tobias C. Berner <tcberner@freebsd.org>
8  * Copyright (C) 2018, Andre Heinecke <aheinecke@intevation.de>
9  * Copyright (C) 2018, Chinmoy Ranjan Pradhan <chinmoyrp65@protonmail.com>
10  * Copyright (C) 2018, Oliver Sander <oliver.sander@tu-dresden.de>
11  * Copyright (C) 2019 João Netto <joaonetto901@gmail.com>
12  * Copyright (C) 2019, Adrian Johnson <ajohnson@redneon.com>
13  * Copyright (C) 2020, Thorsten Behrens <Thorsten.Behrens@CIB.de>
14  * Copyright (C) 2020, Klarälvdalens Datakonsult AB, a KDAB Group company, <info@kdab.com>. Work sponsored by Technische Universität Dresden
15  *
16  * This program is free software; you can redistribute it and/or modify
17  * it under the terms of the GNU General Public License as published by
18  * the Free Software Foundation; either version 2, or (at your option)
19  * any later version.
20  *
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24  * GNU General Public License for more details.
25  *
26  * You should have received a copy of the GNU General Public License
27  * along with this program; if not, write to the Free Software
28  * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
29  */
30 
31 #ifndef _POPPLER_QT5_FORM_H_
32 #define _POPPLER_QT5_FORM_H_
33 
34 #include <functional>
35 #include <memory>
36 #include <ctime>
37 #include <QtCore/QDateTime>
38 #include <QtCore/QVector>
39 #include <QtCore/QList>
40 #include <QtCore/QRectF>
41 #include <QtCore/QStringList>
42 #include <QtCore/QSharedPointer>
43 #include "poppler-export.h"
44 #include "poppler-annotation.h"
45 
46 class Object;
47 class Page;
48 class FormWidget;
49 class FormWidgetButton;
50 class FormWidgetText;
51 class FormWidgetChoice;
52 class FormWidgetSignature;
53 
54 namespace Poppler {
55 
56 class DocumentData;
57 class Link;
58 
59 class FormFieldData;
60 class FormFieldIconData;
61 
68 class POPPLER_QT5_EXPORT FormFieldIcon
69 {
70 
71  friend class FormFieldIconData;
72 
73 public:
74  FormFieldIcon(FormFieldIconData *data);
75  FormFieldIcon(const FormFieldIcon &ffIcon);
76  ~FormFieldIcon();
77 
78  FormFieldIcon &operator=(const FormFieldIcon &ffIcon);
79 
80 private:
81  FormFieldIconData *d_ptr;
82 };
88 class POPPLER_QT5_EXPORT FormField
89 {
90 
91  friend class FormFieldData;
92 
93 public:
97  enum FormType
98  {
102  FormSignature
103  };
104 
105  virtual ~FormField();
106 
110  virtual FormType type() const = 0;
111 
116  QRectF rect() const;
117 
121  int id() const;
122 
126  QString name() const;
127 
132  void setName(const QString &name) const;
133 
138  QString fullyQualifiedName() const;
139 
144  QString uiName() const;
145 
149  bool isReadOnly() const;
150 
155  void setReadOnly(bool value);
156 
160  bool isVisible() const;
161 
166  void setVisible(bool value);
167 
172  bool isPrintable() const;
173 
178  void setPrintable(bool value);
179 
186 
193  {
198  };
205 
212 
213 protected:
215  FormField(std::unique_ptr<FormFieldData> dd);
216 
217  std::unique_ptr<FormFieldData> m_formData;
219 
220 private:
221  Q_DISABLE_COPY(FormField)
222 };
223 
229 class POPPLER_QT5_EXPORT FormFieldButton : public FormField
230 {
231 public:
236  {
239  Radio
240  };
241 
243  FormFieldButton(DocumentData *doc, ::Page *p, ::FormWidgetButton *w);
245  ~FormFieldButton() override;
246 
247  FormType type() const override;
248 
253 
257  QString caption() const;
258 
265 
272  void setIcon(const FormFieldIcon &icon);
273 
277  bool state() const;
278 
282  void setState(bool state);
283 
290  QList<int> siblings() const;
291 
292 private:
293  Q_DISABLE_COPY(FormFieldButton)
294 };
295 
301 class POPPLER_QT5_EXPORT FormFieldText : public FormField
302 {
303 public:
307  enum TextType
308  {
311  FileSelect
312  };
313 
315  FormFieldText(DocumentData *doc, ::Page *p, ::FormWidgetText *w);
317  ~FormFieldText() override;
318 
319  FormType type() const override;
320 
325 
329  QString text() const;
330 
335  void setText(const QString &text);
336 
342  void setAppearanceText(const QString &text);
343 
350  bool isPassword() const;
351 
355  bool isRichText() const;
356 
360  int maximumLength() const;
361 
365  Qt::Alignment textAlignment() const;
366 
371  bool canBeSpellChecked() const;
372 
376  double getFontSize() const;
377 
381  void setFontSize(int fontSize);
382 
383 private:
384  Q_DISABLE_COPY(FormFieldText)
385 };
386 
392 class POPPLER_QT5_EXPORT FormFieldChoice : public FormField
393 {
394 public:
399  {
401  ListBox
402  };
403 
405  FormFieldChoice(DocumentData *doc, ::Page *p, ::FormWidgetChoice *w);
407  ~FormFieldChoice() override;
408 
409  FormType type() const override;
410 
415 
419  QStringList choices() const;
420 
427  QVector<QPair<QString, QString>> choicesWithExportValues() const;
428 
435  bool isEditable() const;
436 
443  bool multiSelect() const;
444 
448  QList<int> currentChoices() const;
449 
453  void setCurrentChoices(const QList<int> &choice);
454 
460  QString editChoice() const;
461 
467  void setEditChoice(const QString &text);
468 
472  Qt::Alignment textAlignment() const;
473 
480  bool canBeSpellChecked() const;
481 
482 private:
483  Q_DISABLE_COPY(FormFieldChoice)
484 };
485 
491 class CertificateInfoPrivate;
492 class POPPLER_QT5_EXPORT CertificateInfo
493 {
494 public:
499  {
500  RsaKey,
501  DsaKey,
502  EcKey,
503  OtherKey
504  };
505 
510  {
511  KuDigitalSignature = 0x80,
512  KuNonRepudiation = 0x40,
513  KuKeyEncipherment = 0x20,
514  KuDataEncipherment = 0x10,
515  KuKeyAgreement = 0x08,
516  KuKeyCertSign = 0x04,
517  KuClrSign = 0x02,
518  KuEncipherOnly = 0x01,
519  KuNone = 0x00
520  };
521  Q_DECLARE_FLAGS(KeyUsageExtensions, KeyUsageExtension)
522 
523 
527  {
528  CommonName,
529  DistinguishedName,
530  EmailAddress,
531  Organization,
532  };
533 
534  CertificateInfo();
535  CertificateInfo(CertificateInfoPrivate *priv);
536  ~CertificateInfo();
537 
541  bool isNull() const;
542 
546  int version() const;
547 
551  QByteArray serialNumber() const;
552 
556  QString issuerInfo(EntityInfoKey key) const;
557 
561  QString subjectInfo(EntityInfoKey key) const;
562 
568  QString nickName() const;
569 
573  QDateTime validityStart() const;
574 
578  QDateTime validityEnd() const;
579 
583  KeyUsageExtensions keyUsageExtensions() const;
584 
588  QByteArray publicKey() const;
589 
594 
598  int publicKeyStrength() const;
599 
603  bool isSelfSigned() const;
604 
608  QByteArray certificateData() const;
609 
615  bool checkPassword(const QString &password) const;
616 
617  CertificateInfo(const CertificateInfo &other);
618  CertificateInfo &operator=(const CertificateInfo &other);
619 
620 private:
621  Q_DECLARE_PRIVATE(CertificateInfo)
622 
623  QSharedPointer<CertificateInfoPrivate> d_ptr;
624 };
625 Q_DECLARE_OPERATORS_FOR_FLAGS(CertificateInfo::KeyUsageExtensions)
626 
627 
632 class SignatureValidationInfoPrivate;
633 class POPPLER_QT5_EXPORT SignatureValidationInfo
634 {
635 public:
640  {
647  SignatureNotVerified
648  };
649 
654  {
661  CertificateNotVerified
662  };
663 
669  {
670  HashAlgorithmUnknown,
671  HashAlgorithmMd2,
672  HashAlgorithmMd5,
673  HashAlgorithmSha1,
674  HashAlgorithmSha256,
675  HashAlgorithmSha384,
676  HashAlgorithmSha512,
677  HashAlgorithmSha224
678  };
679 
681  SignatureValidationInfo(SignatureValidationInfoPrivate *priv);
684 
689 
694 
698  QString signerName() const;
699 
704  QString signerSubjectDN() const;
705 
710  QString location() const;
711 
716  QString reason() const;
717 
723 
727  time_t signingTime() const;
728 
733  QByteArray signature() const;
734 
739  QList<qint64> signedRangeBounds() const;
740 
746  bool signsTotalDocument() const;
747 
753 
755  SignatureValidationInfo &operator=(const SignatureValidationInfo &other);
756 
757 private:
758  Q_DECLARE_PRIVATE(SignatureValidationInfo)
759 
760  QSharedPointer<SignatureValidationInfoPrivate> d_ptr;
761 };
762 
768 class POPPLER_QT5_EXPORT FormFieldSignature : public FormField
769 {
770 public:
776  {
777  AdbePkcs7sha1,
778  AdbePkcs7detached,
779  EtsiCAdESdetached,
780  UnknownSignatureType
781  };
782 
787  {
788  ValidateVerifyCertificate = 1,
789  ValidateForceRevalidation = 2,
790  };
791 
793  FormFieldSignature(DocumentData *doc, ::Page *p, ::FormWidgetSignature *w);
795  ~FormFieldSignature() override;
796 
797  FormType type() const override;
798 
804 
811 
819  SignatureValidationInfo validate(int opt, const QDateTime &validationTime) const;
820 
821 private:
822  Q_DISABLE_COPY(FormFieldSignature)
823 };
824 
830 bool POPPLER_QT5_EXPORT hasNSSSupport();
831 
837 QVector<CertificateInfo> POPPLER_QT5_EXPORT getAvailableSigningCertificates();
838 
844 QString POPPLER_QT5_EXPORT getNSSDir();
845 
851 void POPPLER_QT5_EXPORT setNSSDir(const QString &pathURL);
852 
858 void POPPLER_QT5_EXPORT setNSSPasswordCallback(const std::function<char *(const char *)> &f);
859 }
860 
861 #endif
AdditionalActionType
Describes the flags from an annotations 'AA' dictionary.
Definition: poppler-annotation.h:438
Definition: poppler-form.h:493
PublicKeyType publicKeyType() const
The public key type.
bool isSelfSigned() const
Returns true if certificate is self-signed otherwise returns false.
QByteArray certificateData() const
The DER encoded certificate.
QString issuerInfo(EntityInfoKey key) const
Information about the issuer.
QString subjectInfo(EntityInfoKey key) const
Information about the subject.
bool checkPassword(const QString &password) const
Checks if the given password is the correct one for this certificate.
int version() const
The certificate version string.
int publicKeyStrength() const
The strength of public key in bits.
bool isNull() const
Returns true if certificate has no contents; otherwise returns false.
QDateTime validityEnd() const
The date-time when certificate expires.
QByteArray serialNumber() const
The certificate serial number.
KeyUsageExtension
Certificate key usage extensions.
Definition: poppler-form.h:510
PublicKeyType
The algorithm of public key.
Definition: poppler-form.h:499
KeyUsageExtensions keyUsageExtensions() const
The uses allowed for the certificate.
QDateTime validityStart() const
The date-time when certificate becomes valid.
QByteArray publicKey() const
The public key value.
EntityInfoKey
Predefined keys for elements in an entity's distinguished name.
Definition: poppler-form.h:527
QString nickName() const
The certificate internal database nickname.
A form field that represents a "button".
Definition: poppler-form.h:230
ButtonType buttonType() const
The particular type of the button field.
QString caption() const
The caption to be used for the button.
QList< int > siblings() const
The list with the IDs of siblings (ie, buttons belonging to the same group as the current one.
void setIcon(const FormFieldIcon &icon)
Sets a new icon for the button, it has to be a icon returned by FormFieldButton::icon.
FormType type() const override
The type of the field.
void setState(bool state)
Sets the state of the button to the new state .
FormFieldIcon icon() const
Gets the icon used by the button.
ButtonType
The types of button field.
Definition: poppler-form.h:236
@ CheckBox
A check box.
Definition: poppler-form.h:238
@ Push
A simple push button.
Definition: poppler-form.h:237
bool state() const
The state of the button.
A form field that represents a choice field.
Definition: poppler-form.h:393
QList< int > currentChoices() const
The currently selected choices.
bool canBeSpellChecked() const
Whether the text inserted manually in the field (where possible) can be spell-checked.
ChoiceType
The particular type of this choice field.
Definition: poppler-form.h:399
@ ComboBox
A simple singleline text field.
Definition: poppler-form.h:400
ChoiceType choiceType() const
The choice type of the choice field.
bool multiSelect() const
Whether more than one choice of this FormFieldChoice::ListBox can be selected at the same time.
void setEditChoice(const QString &text)
Sets the text entered into an editable combo box choice field.
QString editChoice() const
The text entered into an editable combo box choice field.
void setCurrentChoices(const QList< int > &choice)
Sets the selected choices to choice.
Qt::Alignment textAlignment() const
The horizontal alignment for the text of this text field.
QVector< QPair< QString, QString > > choicesWithExportValues() const
The possible choices of the choice field.
FormType type() const override
The type of the field.
QStringList choices() const
The possible choices of the choice field.
bool isEditable() const
Whether this FormFieldChoice::ComboBox is editable, i.e.
The class containing the appearance information.
Definition: poppler-form.h:69
A form field that represents a signature.
Definition: poppler-form.h:769
SignatureValidationInfo validate(ValidateOptions opt) const
Validate the signature with now as validation time.
FormType type() const override
The type of the field.
SignatureType signatureType() const
The signature type.
SignatureValidationInfo validate(int opt, const QDateTime &validationTime) const
Validate the signature with validationTime as validation time.
SignatureType
The types of signature fields.
Definition: poppler-form.h:776
ValidateOptions
The validation options of this signature.
Definition: poppler-form.h:787
A form field that represents a text input.
Definition: poppler-form.h:302
void setAppearanceText(const QString &text)
Sets the text inside the Appearance Stream to the specified text.
TextType
The particular type of this text field.
Definition: poppler-form.h:308
@ Multiline
A multiline text field.
Definition: poppler-form.h:310
@ Normal
A simple singleline text field.
Definition: poppler-form.h:309
void setText(const QString &text)
Sets the text associated with the text field to the specified text.
QString text() const
The text associated with the text field.
double getFontSize() const
The font size of the text in the form field.
void setFontSize(int fontSize)
Set the font size of the text in the form field (currently only as integer)
bool canBeSpellChecked() const
Whether the text inserted manually in the field (where possible) can be spell-checked.
bool isPassword() const
Whether this text field is a password input, eg its text must be replaced with asterisks.
TextType textType() const
The text type of the text field.
Qt::Alignment textAlignment() const
The horizontal alignment for the text of this text field.
FormType type() const override
The type of the field.
int maximumLength() const
The maximum length for the text of this field, or -1 if not set.
bool isRichText() const
Whether this text field should allow rich text.
The base class representing a form field.
Definition: poppler-form.h:89
bool isPrintable() const
Whether this field is printable.
int id() const
The ID of the field.
Link * additionalAction(AdditionalActionType type) const
Returns a given form additional action.
QString name() const
The internal name (T) of the field.
void setVisible(bool value)
Set whether this form field is visible.
bool isVisible() const
Whether this form field is visible.
void setReadOnly(bool value)
Set whether this form field is read-only.
Link * additionalAction(Annotation::AdditionalActionType type) const
Returns a given widget annotation additional action.
void setPrintable(bool value)
Set whether this field is printable.
QRectF rect() const
bool isReadOnly() const
Whether this form field is read-only.
QString fullyQualifiedName() const
The internal fully qualified name of the field.
QString uiName() const
The name of the field to be used in user interface (eg messages to the user).
void setName(const QString &name) const
Sets the internal name (T) of the field.
Link * activationAction() const
The activation action of this form field.
virtual FormType type() const =0
The type of the field.
AdditionalActionType
Describes the flags from the form 'AA' dictionary.
Definition: poppler-form.h:193
@ CalculateField
A JavaScript action to be performed when the field needs to be recalculated.
Definition: poppler-form.h:197
@ FormatField
A JavaScript action to be performed before the field is formatted to display its value.
Definition: poppler-form.h:195
@ ValidateField
A JavaScript action to be performed when the field value changes.
Definition: poppler-form.h:196
@ FieldModified
A JavaScript action to be performed when the user modifies the field.
Definition: poppler-form.h:194
FormType
The different types of form field.
Definition: poppler-form.h:98
@ FormButton
A button field. See ButtonType.
Definition: poppler-form.h:99
@ FormText
A text field. See TextType.
Definition: poppler-form.h:100
@ FormChoice
A single choice field. See ChoiceType.
Definition: poppler-form.h:101
A page in a document.
Definition: poppler-qt5.h:429
Definition: poppler-form.h:634
QString signerName() const
The signer name associated with the signature.
QList< qint64 > signedRangeBounds() const
Get the bounds of the ranges of the document which are signed.
QByteArray signature() const
Get the signature binary data.
HashAlgorithm hashAlgorithm() const
The hash algorithm used for the signature.
bool signsTotalDocument() const
Checks whether the signature authenticates the total document except for the signature itself.
CertificateInfo certificateInfo() const
The signer certificate info.
CertificateStatus
The verification result of the certificate.
Definition: poppler-form.h:654
@ CertificateUntrustedIssuer
The issuer of this certificate has been marked as untrusted by the user.
Definition: poppler-form.h:656
@ CertificateUnknownIssuer
The certificate trust chain has not finished in a trusted root certificate.
Definition: poppler-form.h:657
@ CertificateGenericError
The certificate could not be verified.
Definition: poppler-form.h:660
@ CertificateRevoked
The certificate was revoked by the issuing certificate authority.
Definition: poppler-form.h:658
@ CertificateTrusted
The certificate is considered trusted.
Definition: poppler-form.h:655
@ CertificateExpired
The signing time is outside the validity bounds of this certificate.
Definition: poppler-form.h:659
HashAlgorithm
The hash algorithm of the signature.
Definition: poppler-form.h:669
time_t signingTime() const
The signing time associated with the signature.
SignatureStatus
The verification result of the signature.
Definition: poppler-form.h:640
@ SignatureDigestMismatch
The document content was changed after the signature was applied.
Definition: poppler-form.h:643
@ SignatureGenericError
The signature could not be verified.
Definition: poppler-form.h:645
@ SignatureDecodingError
The signature CMS/PKCS7 structure is malformed.
Definition: poppler-form.h:644
@ SignatureValid
The signature is cryptographically valid.
Definition: poppler-form.h:641
@ SignatureNotFound
The requested signature is not present in the document.
Definition: poppler-form.h:646
@ SignatureInvalid
The signature is cryptographically invalid.
Definition: poppler-form.h:642
SignatureStatus signatureStatus() const
The signature status of the signature.
QString signerSubjectDN() const
The signer subject distinguished name associated with the signature.
QString reason() const
Get signing reason.
CertificateStatus certificateStatus() const
The certificate status of the signature.
QString location() const
Get signing location.
The Poppler Qt5 binding.
Definition: poppler-annotation.h:47
QString getNSSDir()
Gets the current NSS CertDB directory.
void setNSSPasswordCallback(const std::function< char *(const char *)> &f)
Sets the callback for NSS password requests.
void setNSSDir(const QString &pathURL)
Set a custom NSS CertDB directory.
bool hasNSSSupport()
Returns is poppler was compiled with NSS support.
QVector< CertificateInfo > getAvailableSigningCertificates()
Return vector of suitable signing certificates.