Poppler Qt5  21.12.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-2021, 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  * Copyright (C) 2021, Theofilos Intzoglou <int.teo@gmail.com>
16  *
17  * This program is free software; you can redistribute it and/or modify
18  * it under the terms of the GNU General Public License as published by
19  * the Free Software Foundation; either version 2, or (at your option)
20  * any later version.
21  *
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25  * GNU General Public License for more details.
26  *
27  * You should have received a copy of the GNU General Public License
28  * along with this program; if not, write to the Free Software
29  * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
30  */
31 
32 #ifndef _POPPLER_QT5_FORM_H_
33 #define _POPPLER_QT5_FORM_H_
34 
35 #include <functional>
36 #include <memory>
37 #include <ctime>
38 #include <QtCore/QDateTime>
39 #include <QtCore/QVector>
40 #include <QtCore/QList>
41 #include <QtCore/QRectF>
42 #include <QtCore/QStringList>
43 #include <QtCore/QSharedPointer>
44 #include "poppler-export.h"
45 #include "poppler-annotation.h"
46 
47 class Object;
48 class Page;
49 class FormWidget;
50 class FormWidgetButton;
51 class FormWidgetText;
52 class FormWidgetChoice;
53 class FormWidgetSignature;
54 
55 namespace Poppler {
56 
57 class DocumentData;
58 class Link;
59 
60 class FormFieldData;
61 class FormFieldIconData;
62 
69 class POPPLER_QT5_EXPORT FormFieldIcon
70 {
71 
72  friend class FormFieldIconData;
73 
74 public:
75  explicit FormFieldIcon(FormFieldIconData *data);
76  FormFieldIcon(const FormFieldIcon &ffIcon);
77  ~FormFieldIcon();
78 
79  FormFieldIcon &operator=(const FormFieldIcon &ffIcon);
80 
81 private:
82  FormFieldIconData *d_ptr;
83 };
89 class POPPLER_QT5_EXPORT FormField
90 {
91 
92  friend class FormFieldData;
93 
94 public:
98  enum FormType
99  {
103  FormSignature
104  };
105 
106  virtual ~FormField();
107 
111  virtual FormType type() const = 0;
112 
117  QRectF rect() const;
118 
122  int id() const;
123 
127  QString name() const;
128 
133  void setName(const QString &name) const;
134 
139  QString fullyQualifiedName() const;
140 
145  QString uiName() const;
146 
150  bool isReadOnly() const;
151 
156  void setReadOnly(bool value);
157 
161  bool isVisible() const;
162 
167  void setVisible(bool value);
168 
173  bool isPrintable() const;
174 
179  void setPrintable(bool value);
180 
187 
194  {
199  };
206 
213 
214 protected:
216  explicit FormField(std::unique_ptr<FormFieldData> dd);
217 
218  std::unique_ptr<FormFieldData> m_formData;
220 
221 private:
222  Q_DISABLE_COPY(FormField)
223 };
224 
230 class POPPLER_QT5_EXPORT FormFieldButton : public FormField
231 {
232 public:
237  {
240  Radio
241  };
242 
244  FormFieldButton(DocumentData *doc, ::Page *p, ::FormWidgetButton *w);
246  ~FormFieldButton() override;
247 
248  FormType type() const override;
249 
254 
258  QString caption() const;
259 
266 
273  void setIcon(const FormFieldIcon &icon);
274 
278  bool state() const;
279 
283  void setState(bool state);
284 
291  QList<int> siblings() const;
292 
293 private:
294  Q_DISABLE_COPY(FormFieldButton)
295 };
296 
302 class POPPLER_QT5_EXPORT FormFieldText : public FormField
303 {
304 public:
308  enum TextType
309  {
312  FileSelect
313  };
314 
316  FormFieldText(DocumentData *doc, ::Page *p, ::FormWidgetText *w);
318  ~FormFieldText() override;
319 
320  FormType type() const override;
321 
326 
330  QString text() const;
331 
336  void setText(const QString &text);
337 
343  void setAppearanceText(const QString &text);
344 
351  bool isPassword() const;
352 
356  bool isRichText() const;
357 
361  int maximumLength() const;
362 
366  Qt::Alignment textAlignment() const;
367 
372  bool canBeSpellChecked() const;
373 
377  double getFontSize() const;
378 
382  void setFontSize(int fontSize);
383 
384 private:
385  Q_DISABLE_COPY(FormFieldText)
386 };
387 
393 class POPPLER_QT5_EXPORT FormFieldChoice : public FormField
394 {
395 public:
400  {
402  ListBox
403  };
404 
406  FormFieldChoice(DocumentData *doc, ::Page *p, ::FormWidgetChoice *w);
408  ~FormFieldChoice() override;
409 
410  FormType type() const override;
411 
416 
420  QStringList choices() const;
421 
428  QVector<QPair<QString, QString>> choicesWithExportValues() const;
429 
436  bool isEditable() const;
437 
444  bool multiSelect() const;
445 
449  QList<int> currentChoices() const;
450 
454  void setCurrentChoices(const QList<int> &choice);
455 
461  QString editChoice() const;
462 
468  void setEditChoice(const QString &text);
469 
473  Qt::Alignment textAlignment() const;
474 
481  bool canBeSpellChecked() const;
482 
483 private:
484  Q_DISABLE_COPY(FormFieldChoice)
485 };
486 
492 class CertificateInfoPrivate;
493 class POPPLER_QT5_EXPORT CertificateInfo
494 {
495 public:
500  {
501  RsaKey,
502  DsaKey,
503  EcKey,
504  OtherKey
505  };
506 
511  {
512  KuDigitalSignature = 0x80,
513  KuNonRepudiation = 0x40,
514  KuKeyEncipherment = 0x20,
515  KuDataEncipherment = 0x10,
516  KuKeyAgreement = 0x08,
517  KuKeyCertSign = 0x04,
518  KuClrSign = 0x02,
519  KuEncipherOnly = 0x01,
520  KuNone = 0x00
521  };
522  Q_DECLARE_FLAGS(KeyUsageExtensions, KeyUsageExtension)
523 
524 
528  {
529  CommonName,
530  DistinguishedName,
531  EmailAddress,
532  Organization,
533  };
534 
535  CertificateInfo();
536  explicit CertificateInfo(CertificateInfoPrivate *priv);
537  ~CertificateInfo();
538 
542  bool isNull() const;
543 
547  int version() const;
548 
552  QByteArray serialNumber() const;
553 
557  QString issuerInfo(EntityInfoKey key) const;
558 
562  QString subjectInfo(EntityInfoKey key) const;
563 
569  QString nickName() const;
570 
574  QDateTime validityStart() const;
575 
579  QDateTime validityEnd() const;
580 
584  KeyUsageExtensions keyUsageExtensions() const;
585 
589  QByteArray publicKey() const;
590 
595 
599  int publicKeyStrength() const;
600 
604  bool isSelfSigned() const;
605 
609  QByteArray certificateData() const;
610 
616  bool checkPassword(const QString &password) const;
617 
618  CertificateInfo(const CertificateInfo &other);
619  CertificateInfo &operator=(const CertificateInfo &other);
620 
621 private:
622  Q_DECLARE_PRIVATE(CertificateInfo)
623 
624  QSharedPointer<CertificateInfoPrivate> d_ptr;
625 };
626 Q_DECLARE_OPERATORS_FOR_FLAGS(CertificateInfo::KeyUsageExtensions)
627 
628 
633 class SignatureValidationInfoPrivate;
634 class POPPLER_QT5_EXPORT SignatureValidationInfo
635 {
636 public:
641  {
648  SignatureNotVerified
649  };
650 
655  {
662  CertificateNotVerified
663  };
664 
670  {
671  HashAlgorithmUnknown,
672  HashAlgorithmMd2,
673  HashAlgorithmMd5,
674  HashAlgorithmSha1,
675  HashAlgorithmSha256,
676  HashAlgorithmSha384,
677  HashAlgorithmSha512,
678  HashAlgorithmSha224
679  };
680 
682  explicit SignatureValidationInfo(SignatureValidationInfoPrivate *priv);
685 
690 
695 
699  QString signerName() const;
700 
705  QString signerSubjectDN() const;
706 
711  QString location() const;
712 
717  QString reason() const;
718 
724 
728  time_t signingTime() const;
729 
734  QByteArray signature() const;
735 
740  QList<qint64> signedRangeBounds() const;
741 
747  bool signsTotalDocument() const;
748 
754 
756  SignatureValidationInfo &operator=(const SignatureValidationInfo &other);
757 
758 private:
759  Q_DECLARE_PRIVATE(SignatureValidationInfo)
760 
761  QSharedPointer<SignatureValidationInfoPrivate> d_ptr;
762 };
763 
769 class POPPLER_QT5_EXPORT FormFieldSignature : public FormField
770 {
771 public:
777  {
778  AdbePkcs7sha1,
779  AdbePkcs7detached,
780  EtsiCAdESdetached,
781  UnknownSignatureType
782  };
783 
788  {
789  ValidateVerifyCertificate = 1,
790  ValidateForceRevalidation = 2,
791  ValidateWithoutOCSPRevocationCheck = 4,
792  ValidateUseAIACertFetch = 8
793  };
794 
796  FormFieldSignature(DocumentData *doc, ::Page *p, ::FormWidgetSignature *w);
798  ~FormFieldSignature() override;
799 
800  FormType type() const override;
801 
807 
814 
822  SignatureValidationInfo validate(int opt, const QDateTime &validationTime) const;
823 
824 private:
825  Q_DISABLE_COPY(FormFieldSignature)
826 };
827 
833 bool POPPLER_QT5_EXPORT hasNSSSupport();
834 
840 QVector<CertificateInfo> POPPLER_QT5_EXPORT getAvailableSigningCertificates();
841 
847 QString POPPLER_QT5_EXPORT getNSSDir();
848 
854 void POPPLER_QT5_EXPORT setNSSDir(const QString &pathURL);
855 
861 void POPPLER_QT5_EXPORT setNSSPasswordCallback(const std::function<char *(const char *)> &f);
862 }
863 
864 #endif
AdditionalActionType
Describes the flags from an annotations 'AA' dictionary.
Definition: poppler-annotation.h:481
Definition: poppler-form.h:494
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:511
PublicKeyType
The algorithm of public key.
Definition: poppler-form.h:500
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:528
QString nickName() const
The certificate internal database nickname.
A form field that represents a "button".
Definition: poppler-form.h:231
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:237
@ CheckBox
A check box.
Definition: poppler-form.h:239
@ Push
A simple push button.
Definition: poppler-form.h:238
bool state() const
The state of the button.
A form field that represents a choice field.
Definition: poppler-form.h:394
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:400
@ ComboBox
A simple singleline text field.
Definition: poppler-form.h:401
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:70
A form field that represents a signature.
Definition: poppler-form.h:770
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:777
ValidateOptions
The validation options of this signature.
Definition: poppler-form.h:788
A form field that represents a text input.
Definition: poppler-form.h:303
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:309
@ Multiline
A multiline text field.
Definition: poppler-form.h:311
@ Normal
A simple singleline text field.
Definition: poppler-form.h:310
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:90
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:194
@ CalculateField
A JavaScript action to be performed when the field needs to be recalculated.
Definition: poppler-form.h:198
@ FormatField
A JavaScript action to be performed before the field is formatted to display its value.
Definition: poppler-form.h:196
@ ValidateField
A JavaScript action to be performed when the field value changes.
Definition: poppler-form.h:197
@ FieldModified
A JavaScript action to be performed when the user modifies the field.
Definition: poppler-form.h:195
FormType
The different types of form field.
Definition: poppler-form.h:99
@ FormButton
A button field. See ButtonType.
Definition: poppler-form.h:100
@ FormText
A text field. See TextType.
Definition: poppler-form.h:101
@ FormChoice
A single choice field. See ChoiceType.
Definition: poppler-form.h:102
A page in a document.
Definition: poppler-qt5.h:433
Definition: poppler-form.h:635
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:655
@ CertificateUntrustedIssuer
The issuer of this certificate has been marked as untrusted by the user.
Definition: poppler-form.h:657
@ CertificateUnknownIssuer
The certificate trust chain has not finished in a trusted root certificate.
Definition: poppler-form.h:658
@ CertificateGenericError
The certificate could not be verified.
Definition: poppler-form.h:661
@ CertificateRevoked
The certificate was revoked by the issuing certificate authority.
Definition: poppler-form.h:659
@ CertificateTrusted
The certificate is considered trusted.
Definition: poppler-form.h:656
@ CertificateExpired
The signing time is outside the validity bounds of this certificate.
Definition: poppler-form.h:660
HashAlgorithm
The hash algorithm of the signature.
Definition: poppler-form.h:670
time_t signingTime() const
The signing time associated with the signature.
SignatureStatus
The verification result of the signature.
Definition: poppler-form.h:641
@ SignatureDigestMismatch
The document content was changed after the signature was applied.
Definition: poppler-form.h:644
@ SignatureGenericError
The signature could not be verified.
Definition: poppler-form.h:646
@ SignatureDecodingError
The signature CMS/PKCS7 structure is malformed.
Definition: poppler-form.h:645
@ SignatureValid
The signature is cryptographically valid.
Definition: poppler-form.h:642
@ SignatureNotFound
The requested signature is not present in the document.
Definition: poppler-form.h:647
@ SignatureInvalid
The signature is cryptographically invalid.
Definition: poppler-form.h:643
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:50
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.