Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-10 10:23:46

0001 //========================================================================
0002 //
0003 // Form.h
0004 //
0005 // This file is licensed under the GPLv2 or later
0006 //
0007 // Copyright 2006 Julien Rebetez <julienr@svn.gnome.org>
0008 // Copyright 2007, 2008, 2011 Carlos Garcia Campos <carlosgc@gnome.org>
0009 // Copyright 2007-2010, 2012, 2015-2023 Albert Astals Cid <aacid@kde.org>
0010 // Copyright 2010 Mark Riedesel <mark@klowner.com>
0011 // Copyright 2011 Pino Toscano <pino@kde.org>
0012 // Copyright 2012 Fabio D'Urso <fabiodurso@hotmail.it>
0013 // Copyright 2013 Adrian Johnson <ajohnson@redneon.com>
0014 // Copyright 2015 André Guerreiro <aguerreiro1985@gmail.com>
0015 // Copyright 2015 André Esser <bepandre@hotmail.com>
0016 // Copyright 2017 Roland Hieber <r.hieber@pengutronix.de>
0017 // Copyright 2017 Hans-Ulrich Jüttner <huj@froreich-bioscientia.de>
0018 // Copyright 2018 Andre Heinecke <aheinecke@intevation.de>
0019 // Copyright 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <info@kdab.com>. Work sponsored by the LiMux project of the city of Munich
0020 // Copyright 2018 Chinmoy Ranjan Pradhan <chinmoyrp65@protonmail.com>
0021 // Copyright 2019, 2020 Oliver Sander <oliver.sander@tu-dresden.de>
0022 // Copyright 2019 João Netto <joaonetto901@gmail.com>
0023 // Copyright 2020, 2021 Nelson Benítez León <nbenitezl@gmail.com>
0024 // Copyright 2020 Marek Kasik <mkasik@redhat.com>
0025 // Copyright 2020 Thorsten Behrens <Thorsten.Behrens@CIB.de>
0026 // Copyright 2020 Klarälvdalens Datakonsult AB, a KDAB Group company, <info@kdab.com>. Work sponsored by Technische Universität Dresden
0027 // Copyright 2021 Georgiy Sgibnev <georgiy@sgibnev.com>. Work sponsored by lab50.net.
0028 // Copyright 2021 Theofilos Intzoglou <int.teo@gmail.com>
0029 // Copyright 2022 Alexander Sulfrian <asulfrian@zedat.fu-berlin.de>
0030 // Copyright 2023 g10 Code GmbH, Author: Sune Stolborg Vuorela <sune@vuorela.dk>
0031 //
0032 //========================================================================
0033 
0034 #ifndef FORM_H
0035 #define FORM_H
0036 
0037 #include "Annot.h"
0038 #include "CharTypes.h"
0039 #include "Object.h"
0040 #include "poppler_private_export.h"
0041 
0042 #include <ctime>
0043 
0044 #include <optional>
0045 #include <set>
0046 #include <vector>
0047 
0048 class GooString;
0049 class Array;
0050 class Dict;
0051 class Annot;
0052 class AnnotWidget;
0053 class Annots;
0054 class LinkAction;
0055 class GfxResources;
0056 class PDFDoc;
0057 class SignatureInfo;
0058 class X509CertificateInfo;
0059 class SignatureVerificationHandler;
0060 
0061 enum FormFieldType
0062 {
0063     formButton,
0064     formText,
0065     formChoice,
0066     formSignature,
0067     formUndef
0068 };
0069 
0070 enum FormButtonType
0071 {
0072     formButtonCheck,
0073     formButtonPush,
0074     formButtonRadio
0075 };
0076 
0077 enum FormSignatureType
0078 {
0079     adbe_pkcs7_sha1,
0080     adbe_pkcs7_detached,
0081     ETSI_CAdES_detached,
0082     unknown_signature_type,
0083     unsigned_signature_field
0084 };
0085 
0086 enum FillValueType
0087 {
0088     fillValue,
0089     fillDefaultValue
0090 };
0091 
0092 class Form;
0093 class FormField;
0094 class FormFieldButton;
0095 class FormFieldText;
0096 class FormFieldSignature;
0097 class FormFieldChoice;
0098 
0099 //------------------------------------------------------------------------
0100 // FormWidget
0101 // A FormWidget represents the graphical part of a field and is "attached"
0102 // to a page.
0103 //------------------------------------------------------------------------
0104 
0105 class POPPLER_PRIVATE_EXPORT FormWidget
0106 {
0107 public:
0108     virtual ~FormWidget();
0109 
0110     // Check if point is inside the field bounding rect
0111     bool inRect(double x, double y) const;
0112 
0113     // Get the field bounding rect
0114     void getRect(double *x1, double *y1, double *x2, double *y2) const;
0115 
0116     unsigned getID() { return ID; }
0117     void setID(unsigned int i) { ID = i; }
0118 
0119     FormField *getField() { return field; }
0120     FormFieldType getType() { return type; }
0121 
0122     Object *getObj() { return &obj; }
0123     Ref getRef() { return ref; }
0124 
0125     void setChildNum(unsigned i) { childNum = i; }
0126     unsigned getChildNum() { return childNum; }
0127 
0128     const GooString *getPartialName() const;
0129     void setPartialName(const GooString &name);
0130     const GooString *getAlternateUiName() const;
0131     const GooString *getMappingName() const;
0132     GooString *getFullyQualifiedName();
0133 
0134     bool isModified() const;
0135 
0136     bool isReadOnly() const;
0137     void setReadOnly(bool value);
0138 
0139     LinkAction *getActivationAction(); // The caller should not delete the result
0140     std::unique_ptr<LinkAction> getAdditionalAction(Annot::FormAdditionalActionsType type);
0141     bool setAdditionalAction(Annot::FormAdditionalActionsType t, const GooString &js);
0142 
0143     // return the unique ID corresponding to pageNum/fieldNum
0144     static int encodeID(unsigned pageNum, unsigned fieldNum);
0145     // decode id and retrieve pageNum and fieldNum
0146     static void decodeID(unsigned id, unsigned *pageNum, unsigned *fieldNum);
0147 
0148     void createWidgetAnnotation();
0149     AnnotWidget *getWidgetAnnotation() const { return widget; }
0150     void setWidgetAnnotation(AnnotWidget *_widget) { widget = _widget; }
0151 
0152     virtual void updateWidgetAppearance() = 0;
0153 
0154     void print(int indent = 0);
0155 
0156 protected:
0157     FormWidget(PDFDoc *docA, Object *aobj, unsigned num, Ref aref, FormField *fieldA);
0158 
0159     AnnotWidget *widget;
0160     FormField *field;
0161     FormFieldType type;
0162     Object obj;
0163     Ref ref;
0164     PDFDoc *doc;
0165     XRef *xref;
0166 
0167     // index of this field in the parent's child list
0168     unsigned childNum;
0169 
0170     /*
0171     Field ID is an (unsigned) integer, calculated as follow :
0172     the first sizeof/2 bits are the field number, relative to the page
0173     the last sizeof/2 bits are the page number
0174     [page number | field number]
0175     (encoding) id = (pageNum << 4*sizeof(unsigned)) + fieldNum;
0176     (decoding) pageNum = id >> 4*sizeof(unsigned); fieldNum = (id << 4*sizeof(unsigned)) >> 4*sizeof(unsigned);
0177     */
0178     unsigned ID;
0179 };
0180 
0181 //------------------------------------------------------------------------
0182 // FormWidgetButton
0183 //------------------------------------------------------------------------
0184 
0185 class POPPLER_PRIVATE_EXPORT FormWidgetButton : public FormWidget
0186 {
0187 public:
0188     FormWidgetButton(PDFDoc *docA, Object *dictObj, unsigned num, Ref ref, FormField *p);
0189     ~FormWidgetButton() override;
0190 
0191     FormButtonType getButtonType() const;
0192 
0193     void setState(bool state);
0194     bool getState() const;
0195 
0196     const char *getOnStr() const;
0197     void setAppearanceState(const char *state);
0198     void updateWidgetAppearance() override;
0199 
0200 protected:
0201     FormFieldButton *parent() const;
0202     GooString *onStr;
0203 };
0204 
0205 //------------------------------------------------------------------------
0206 // FormWidgetText
0207 //------------------------------------------------------------------------
0208 
0209 class POPPLER_PRIVATE_EXPORT FormWidgetText : public FormWidget
0210 {
0211 public:
0212     FormWidgetText(PDFDoc *docA, Object *dictObj, unsigned num, Ref ref, FormField *p);
0213     // return the field's content (UTF16BE)
0214     const GooString *getContent() const;
0215 
0216     // expects a UTF16BE string
0217     void setContent(const GooString *new_content);
0218     // sets the text inside the field appearance stream
0219     void setAppearanceContent(const GooString *new_content);
0220 
0221     void updateWidgetAppearance() override;
0222 
0223     bool isMultiline() const;
0224     bool isPassword() const;
0225     bool isFileSelect() const;
0226     bool noSpellCheck() const;
0227     bool noScroll() const;
0228     bool isComb() const;
0229     bool isRichText() const;
0230     int getMaxLen() const;
0231     // return the font size of the field's text
0232     double getTextFontSize();
0233     // set the font size of the field's text (currently only integer values)
0234     void setTextFontSize(int fontSize);
0235 
0236 protected:
0237     FormFieldText *parent() const;
0238 };
0239 
0240 //------------------------------------------------------------------------
0241 // FormWidgetChoice
0242 //------------------------------------------------------------------------
0243 
0244 class POPPLER_PRIVATE_EXPORT FormWidgetChoice : public FormWidget
0245 {
0246 public:
0247     FormWidgetChoice(PDFDoc *docA, Object *dictObj, unsigned num, Ref ref, FormField *p);
0248     ~FormWidgetChoice() override;
0249 
0250     int getNumChoices() const;
0251     // return the display name of the i-th choice (UTF16BE)
0252     const GooString *getChoice(int i) const;
0253     const GooString *getExportVal(int i) const;
0254     // select the i-th choice
0255     void select(int i);
0256 
0257     // toggle selection of the i-th choice
0258     void toggle(int i);
0259 
0260     // deselect everything
0261     void deselectAll();
0262 
0263     // except a UTF16BE string
0264     // only work for editable combo box, set the user-entered text as the current choice
0265     void setEditChoice(const GooString *new_content);
0266 
0267     const GooString *getEditChoice() const;
0268 
0269     void updateWidgetAppearance() override;
0270     bool isSelected(int i) const;
0271 
0272     bool isCombo() const;
0273     bool hasEdit() const;
0274     bool isMultiSelect() const;
0275     bool noSpellCheck() const;
0276     bool commitOnSelChange() const;
0277     bool isListBox() const;
0278 
0279 protected:
0280     bool _checkRange(int i) const;
0281     FormFieldChoice *parent() const;
0282 };
0283 
0284 //------------------------------------------------------------------------
0285 // FormWidgetSignature
0286 //------------------------------------------------------------------------
0287 
0288 class POPPLER_PRIVATE_EXPORT FormWidgetSignature : public FormWidget
0289 {
0290 public:
0291     FormWidgetSignature(PDFDoc *docA, Object *dictObj, unsigned num, Ref ref, FormField *p);
0292     void updateWidgetAppearance() override;
0293 
0294     FormSignatureType signatureType() const;
0295     void setSignatureType(FormSignatureType fst);
0296 
0297     // Use -1 for now as validationTime
0298     SignatureInfo *validateSignature(bool doVerifyCert, bool forceRevalidation, time_t validationTime, bool ocspRevocationCheck, bool enableAIA);
0299 
0300     // returns a list with the boundaries of the signed ranges
0301     // the elements of the list are of type Goffset
0302     std::vector<Goffset> getSignedRangeBounds() const;
0303 
0304     // Creates or replaces the dictionary name "V" in the signature dictionary and
0305     // fills it with the fields of the signature; the field "Contents" is the signature
0306     // in PKCS#7 format, which is calculated over the byte range encompassing the whole
0307     // document except for the signature itself; this byte range is specified in the
0308     // field "ByteRange" in the dictionary "V".
0309     // Arguments reason and location are UTF-16 big endian strings with BOM. An empty string and nullptr are acceptable too.
0310     // Returns success.
0311     bool signDocument(const std::string &filename, const std::string &certNickname, const std::string &password, const GooString *reason = nullptr, const GooString *location = nullptr, const std::optional<GooString> &ownerPassword = {},
0312                       const std::optional<GooString> &userPassword = {});
0313 
0314     // Same as above but adds text, font color, etc.
0315     bool signDocumentWithAppearance(const std::string &filename, const std::string &certNickname, const std::string &password, const GooString *reason = nullptr, const GooString *location = nullptr,
0316                                     const std::optional<GooString> &ownerPassword = {}, const std::optional<GooString> &userPassword = {}, const GooString &signatureText = {}, const GooString &signatureTextLeft = {}, double fontSize = {},
0317                                     double leftFontSize = {}, std::unique_ptr<AnnotColor> &&fontColor = {}, double borderWidth = {}, std::unique_ptr<AnnotColor> &&borderColor = {}, std::unique_ptr<AnnotColor> &&backgroundColor = {});
0318 
0319     // checks the length encoding of the signature and returns the hex encoded signature
0320     // if the check passed (and the checked file size as output parameter in checkedFileSize)
0321     // otherwise a nullptr is returned
0322     std::optional<GooString> getCheckedSignature(Goffset *checkedFileSize);
0323 
0324     const GooString *getSignature() const;
0325 
0326 private:
0327     bool createSignature(Object &vObj, Ref vRef, const GooString &name, int placeholderLength, const GooString *reason = nullptr, const GooString *location = nullptr);
0328     bool getObjectStartEnd(const GooString &filename, int objNum, Goffset *objStart, Goffset *objEnd, const std::optional<GooString> &ownerPassword, const std::optional<GooString> &userPassword);
0329     bool updateOffsets(FILE *f, Goffset objStart, Goffset objEnd, Goffset *sigStart, Goffset *sigEnd, Goffset *fileSize);
0330 
0331     bool updateSignature(FILE *f, Goffset sigStart, Goffset sigEnd, const GooString *signature);
0332 };
0333 
0334 //------------------------------------------------------------------------
0335 // FormField
0336 // A FormField implements the logical side of a field and is "attached" to
0337 // the Catalog. This is an internal class and client applications should
0338 // only interact with FormWidgets.
0339 //------------------------------------------------------------------------
0340 
0341 class POPPLER_PRIVATE_EXPORT FormField
0342 {
0343 public:
0344     FormField(PDFDoc *docA, Object &&aobj, const Ref aref, FormField *parent, std::set<int> *usedParents, FormFieldType t = formUndef);
0345 
0346     virtual ~FormField();
0347 
0348     // Accessors.
0349     FormFieldType getType() const { return type; }
0350     Object *getObj() { return &obj; }
0351     Ref getRef() { return ref; }
0352 
0353     void setReadOnly(bool value);
0354     bool isReadOnly() const { return readOnly; }
0355     void setStandAlone(bool value) { standAlone = value; }
0356     bool isStandAlone() const { return standAlone; }
0357 
0358     GooString *getDefaultAppearance() const { return defaultAppearance; }
0359     void setDefaultAppearance(const std::string &appearance);
0360 
0361     bool hasTextQuadding() const { return hasQuadding; }
0362     VariableTextQuadding getTextQuadding() const { return quadding; }
0363 
0364     const GooString *getPartialName() const { return partialName; }
0365     void setPartialName(const GooString &name);
0366     const GooString *getAlternateUiName() const { return alternateUiName; }
0367     const GooString *getMappingName() const { return mappingName; }
0368     GooString *getFullyQualifiedName();
0369 
0370     FormWidget *findWidgetByRef(Ref aref);
0371     int getNumWidgets() const { return terminal ? numChildren : 0; }
0372     FormWidget *getWidget(int i) const { return terminal ? widgets[i] : nullptr; }
0373     int getNumChildren() const { return !terminal ? numChildren : 0; }
0374     FormField *getChildren(int i) const { return children[i]; }
0375 
0376     // only implemented in FormFieldButton
0377     virtual void fillChildrenSiblingsID();
0378 
0379     void createWidgetAnnotations();
0380 
0381     void printTree(int indent = 0);
0382     virtual void print(int indent = 0);
0383     virtual void reset(const std::vector<std::string> &excludedFields);
0384     void resetChildren(const std::vector<std::string> &excludedFields);
0385     FormField *findFieldByRef(Ref aref);
0386     FormField *findFieldByFullyQualifiedName(const std::string &name);
0387 
0388 protected:
0389     void _createWidget(Object *obj, Ref aref);
0390     void createChildren(std::set<int> *usedParents);
0391     void updateChildrenAppearance();
0392     bool isAmongExcludedFields(const std::vector<std::string> &excludedFields);
0393 
0394     FormFieldType type; // field type
0395     Ref ref;
0396     bool terminal;
0397     Object obj;
0398     PDFDoc *doc;
0399     XRef *xref;
0400     FormField **children;
0401     FormField *parent;
0402     int numChildren;
0403     FormWidget **widgets;
0404     bool readOnly;
0405 
0406     GooString *partialName; // T field
0407     GooString *alternateUiName; // TU field
0408     GooString *mappingName; // TM field
0409     GooString *fullyQualifiedName;
0410 
0411     // Variable Text
0412     GooString *defaultAppearance;
0413     bool hasQuadding;
0414     VariableTextQuadding quadding;
0415 
0416     // True when FormField is not part of Catalog's Field array (or there isn't one).
0417     bool standAlone;
0418 
0419 private:
0420     FormField() { }
0421 };
0422 
0423 //------------------------------------------------------------------------
0424 // FormFieldButton
0425 //------------------------------------------------------------------------
0426 
0427 class FormFieldButton : public FormField
0428 {
0429 public:
0430     FormFieldButton(PDFDoc *docA, Object &&dict, const Ref ref, FormField *parent, std::set<int> *usedParents);
0431 
0432     FormButtonType getButtonType() const { return btype; }
0433 
0434     bool noToggleToOff() const { return noAllOff; }
0435 
0436     // returns true if the state modification is accepted
0437     bool setState(const char *state, bool ignoreToggleOff = false);
0438     bool getState(const char *state) const;
0439 
0440     const char *getAppearanceState() const { return appearanceState.isName() ? appearanceState.getName() : nullptr; }
0441     const char *getDefaultAppearanceState() const { return defaultAppearanceState.isName() ? defaultAppearanceState.getName() : nullptr; }
0442 
0443     void fillChildrenSiblingsID() override;
0444 
0445     void setNumSiblings(int num);
0446     void setSibling(int i, FormFieldButton *id) { siblings[i] = id; }
0447 
0448     // For radio buttons, return the fields of the other radio buttons in the same group
0449     FormFieldButton *getSibling(int i) const { return siblings[i]; }
0450     int getNumSiblings() const { return numSiblings; }
0451 
0452     void print(int indent) override;
0453     void reset(const std::vector<std::string> &excludedFields) override;
0454 
0455     ~FormFieldButton() override;
0456 
0457 protected:
0458     void updateState(const char *state);
0459 
0460     FormFieldButton **siblings; // IDs of dependent buttons (each button of a radio field has all the others buttons
0461                                 // of the same field in this array)
0462     int numSiblings;
0463 
0464     FormButtonType btype;
0465     int size;
0466     int active_child; // only used for combo box
0467     bool noAllOff;
0468     Object appearanceState; // V
0469     Object defaultAppearanceState; // DV
0470 };
0471 
0472 //------------------------------------------------------------------------
0473 // FormFieldText
0474 //------------------------------------------------------------------------
0475 
0476 class FormFieldText : public FormField
0477 {
0478 public:
0479     FormFieldText(PDFDoc *docA, Object &&dictObj, const Ref ref, FormField *parent, std::set<int> *usedParents);
0480 
0481     const GooString *getContent() const { return content; }
0482     const GooString *getAppearanceContent() const { return internalContent ? internalContent : content; }
0483     void setContentCopy(const GooString *new_content);
0484     void setAppearanceContentCopy(const GooString *new_content);
0485     ~FormFieldText() override;
0486 
0487     bool isMultiline() const { return multiline; }
0488     bool isPassword() const { return password; }
0489     bool isFileSelect() const { return fileSelect; }
0490     bool noSpellCheck() const { return doNotSpellCheck; }
0491     bool noScroll() const { return doNotScroll; }
0492     bool isComb() const { return comb; }
0493     bool isRichText() const { return richText; }
0494 
0495     int getMaxLen() const { return maxLen; }
0496 
0497     // return the font size of the field's text
0498     double getTextFontSize();
0499     // set the font size of the field's text (currently only integer values)
0500     void setTextFontSize(int fontSize);
0501 
0502     void print(int indent) override;
0503     void reset(const std::vector<std::string> &excludedFields) override;
0504 
0505     static int tokenizeDA(const std::string &daString, std::vector<std::string> *daToks, const char *searchTok);
0506 
0507 protected:
0508     int parseDA(std::vector<std::string> *daToks);
0509     void fillContent(FillValueType fillType);
0510 
0511     GooString *content;
0512     GooString *internalContent;
0513     GooString *defaultContent;
0514     bool multiline;
0515     bool password;
0516     bool fileSelect;
0517     bool doNotSpellCheck;
0518     bool doNotScroll;
0519     bool comb;
0520     bool richText;
0521     int maxLen;
0522 };
0523 
0524 //------------------------------------------------------------------------
0525 // FormFieldChoice
0526 //------------------------------------------------------------------------
0527 
0528 class FormFieldChoice : public FormField
0529 {
0530 public:
0531     FormFieldChoice(PDFDoc *docA, Object &&aobj, const Ref ref, FormField *parent, std::set<int> *usedParents);
0532 
0533     ~FormFieldChoice() override;
0534 
0535     int getNumChoices() const { return numChoices; }
0536     const GooString *getChoice(int i) const { return choices ? choices[i].optionName : nullptr; }
0537     const GooString *getExportVal(int i) const { return choices ? choices[i].exportVal : nullptr; }
0538     // For multi-select choices it returns the first one
0539     const GooString *getSelectedChoice() const;
0540 
0541     // select the i-th choice
0542     void select(int i);
0543 
0544     // toggle selection of the i-th choice
0545     void toggle(int i);
0546 
0547     // deselect everything
0548     void deselectAll();
0549 
0550     // only work for editable combo box, set the user-entered text as the current choice
0551     void setEditChoice(const GooString *new_content);
0552 
0553     const GooString *getEditChoice() const;
0554 
0555     bool isSelected(int i) const { return choices[i].selected; }
0556 
0557     int getNumSelected();
0558 
0559     bool isCombo() const { return combo; }
0560     bool hasEdit() const { return edit; }
0561     bool isMultiSelect() const { return multiselect; }
0562     bool noSpellCheck() const { return doNotSpellCheck; }
0563     bool commitOnSelChange() const { return doCommitOnSelChange; }
0564     bool isListBox() const { return !combo; }
0565 
0566     int getTopIndex() const { return topIdx; }
0567 
0568     void print(int indent) override;
0569     void reset(const std::vector<std::string> &excludedFields) override;
0570 
0571 protected:
0572     void unselectAll();
0573     void updateSelection();
0574     void fillChoices(FillValueType fillType);
0575 
0576     bool combo;
0577     bool edit;
0578     bool multiselect;
0579     bool doNotSpellCheck;
0580     bool doCommitOnSelChange;
0581 
0582     struct ChoiceOpt
0583     {
0584         GooString *exportVal; // the export value ("internal" name)
0585         GooString *optionName; // displayed name
0586         bool selected; // if this choice is selected
0587     };
0588 
0589     int numChoices;
0590     ChoiceOpt *choices;
0591     bool *defaultChoices;
0592     GooString *editedChoice;
0593     int topIdx; // TI
0594 };
0595 
0596 //------------------------------------------------------------------------
0597 // FormFieldSignature
0598 //------------------------------------------------------------------------
0599 
0600 class POPPLER_PRIVATE_EXPORT FormFieldSignature : public FormField
0601 {
0602 public:
0603     FormFieldSignature(PDFDoc *docA, Object &&dict, const Ref ref, FormField *parent, std::set<int> *usedParents);
0604 
0605     // Use -1 for now as validationTime
0606     SignatureInfo *validateSignature(bool doVerifyCert, bool forceRevalidation, time_t validationTime, bool ocspRevocationCheck, bool enableAIA);
0607 
0608     // returns a list with the boundaries of the signed ranges
0609     // the elements of the list are of type Goffset
0610     std::vector<Goffset> getSignedRangeBounds() const;
0611 
0612     // checks the length encoding of the signature and returns the hex encoded signature
0613     // if the check passed (and the checked file size as output parameter in checkedFileSize)
0614     // otherwise a nullptr is returned
0615     std::optional<GooString> getCheckedSignature(Goffset *checkedFileSize);
0616 
0617     ~FormFieldSignature() override;
0618     Object *getByteRange() { return &byte_range; }
0619     const GooString *getSignature() const { return signature; }
0620     void setSignature(const GooString &sig);
0621     FormSignatureType getSignatureType() const { return signature_type; }
0622     void setSignatureType(FormSignatureType t) { signature_type = t; }
0623 
0624     const GooString &getCustomAppearanceContent() const;
0625     void setCustomAppearanceContent(const GooString &s);
0626 
0627     const GooString &getCustomAppearanceLeftContent() const;
0628     void setCustomAppearanceLeftContent(const GooString &s);
0629 
0630     double getCustomAppearanceLeftFontSize() const;
0631     void setCustomAppearanceLeftFontSize(double size);
0632 
0633     // Background image (ref to an object of type XObject). Invalid ref if not required.
0634     Ref getImageResource() const;
0635     void setImageResource(const Ref imageResourceA);
0636 
0637     void setCertificateInfo(std::unique_ptr<X509CertificateInfo> &);
0638 
0639     FormWidget *getCreateWidget();
0640 
0641 private:
0642     void parseInfo();
0643     void hashSignedDataBlock(SignatureVerificationHandler *handler, Goffset block_len);
0644 
0645     FormSignatureType signature_type;
0646     Object byte_range;
0647     GooString *signature;
0648     SignatureInfo *signature_info;
0649     GooString customAppearanceContent;
0650     GooString customAppearanceLeftContent;
0651     double customAppearanceLeftFontSize = 20;
0652     Ref imageResource = Ref::INVALID();
0653     std::unique_ptr<X509CertificateInfo> certificate_info;
0654 
0655     void print(int indent) override;
0656 };
0657 
0658 //------------------------------------------------------------------------
0659 // Form
0660 // This class handle the document-wide part of Form (things in the acroForm
0661 // Catalog entry).
0662 //------------------------------------------------------------------------
0663 
0664 class POPPLER_PRIVATE_EXPORT Form
0665 {
0666 public:
0667     explicit Form(PDFDoc *doc);
0668 
0669     ~Form();
0670 
0671     Form(const Form &) = delete;
0672     Form &operator=(const Form &) = delete;
0673 
0674     // Look up an inheritable field dictionary entry.
0675     static Object fieldLookup(Dict *field, const char *key);
0676 
0677     /* Creates a new Field of the type specified in obj's dict.
0678        used in Form::Form , FormField::FormField and
0679        Page::loadStandaloneFields */
0680     static FormField *createFieldFromDict(Object &&obj, PDFDoc *docA, const Ref aref, FormField *parent, std::set<int> *usedParents);
0681 
0682     // Finds in the default resources dictionary a font named popplerfontXXX that
0683     // has the given fontFamily and fontStyle. This makes us relatively sure that we added that font ourselves
0684     std::string findFontInDefaultResources(const std::string &fontFamily, const std::string &fontStyle) const;
0685 
0686     struct AddFontResult
0687     {
0688         std::string fontName;
0689         Ref ref;
0690     };
0691 
0692     // Finds in the system a font name matching the given fontFamily and fontStyle
0693     // And adds it to the default resources dictionary, font name there will be popplerfontXXX
0694     AddFontResult addFontToDefaultResources(const std::string &fontFamily, const std::string &fontStyle);
0695 
0696     // Finds in the default resources dictionary a font named popplerfontXXX that
0697     // emulates fontToEmulate and can draw the given char
0698     std::string getFallbackFontForChar(Unicode uChar, const GfxFont &fontToEmulate) const;
0699 
0700     // Makes sure the default resources has fonts to draw all the given chars and as close as possible to the given pdfFontNameToEmulate
0701     // If needed adds fonts to the default resources dictionary, font names will be popplerfontXXX
0702     // If fieldResources is not nullptr, it is used instead of the to query the font to emulate instead of the default resources
0703     // Returns a list of all the added fonts (if any)
0704     std::vector<AddFontResult> ensureFontsForAllCharacters(const GooString *unicodeText, const std::string &pdfFontNameToEmulate, GfxResources *fieldResources = nullptr);
0705 
0706     bool getNeedAppearances() const { return needAppearances; }
0707     int getNumFields() const { return numFields; }
0708     FormField *getRootField(int i) const { return rootFields[i]; }
0709     const GooString *getDefaultAppearance() const { return defaultAppearance; }
0710     VariableTextQuadding getTextQuadding() const { return quadding; }
0711     GfxResources *getDefaultResources() const { return defaultResources; }
0712     Object *getDefaultResourcesObj() { return &resDict; }
0713 
0714     FormWidget *findWidgetByRef(Ref aref);
0715     FormField *findFieldByRef(Ref aref) const;
0716     FormField *findFieldByFullyQualifiedName(const std::string &name) const;
0717 
0718     void postWidgetsLoad();
0719 
0720     const std::vector<Ref> &getCalculateOrder() const { return calculateOrder; }
0721 
0722     void reset(const std::vector<std::string> &fields, bool excludeFields);
0723 
0724 private:
0725     // Finds in the system a font name matching the given fontFamily and fontStyle
0726     // And adds it to the default resources dictionary, font name there will be popplerfontXXX
0727     AddFontResult addFontToDefaultResources(const std::string &filepath, int faceIndex, const std::string &fontFamily, const std::string &fontStyle);
0728 
0729     AddFontResult doGetAddFontToDefaultResources(Unicode uChar, const GfxFont &fontToEmulate);
0730 
0731     FormField **rootFields;
0732     int numFields;
0733     int size;
0734     PDFDoc *const doc;
0735     bool needAppearances;
0736     GfxResources *defaultResources;
0737     Object resDict;
0738     std::vector<Ref> calculateOrder;
0739 
0740     // Variable Text
0741     GooString *defaultAppearance;
0742     VariableTextQuadding quadding;
0743 };
0744 
0745 //------------------------------------------------------------------------
0746 // FormPageWidgets
0747 //------------------------------------------------------------------------
0748 
0749 class POPPLER_PRIVATE_EXPORT FormPageWidgets
0750 {
0751 public:
0752     FormPageWidgets(Annots *annots, unsigned int page, Form *form);
0753     ~FormPageWidgets();
0754 
0755     FormPageWidgets(const FormPageWidgets &) = delete;
0756     FormPageWidgets &operator=(const FormPageWidgets &) = delete;
0757 
0758     int getNumWidgets() const { return numWidgets; }
0759     FormWidget *getWidget(int i) const { return widgets[i]; }
0760     void addWidgets(const std::vector<FormField *> &addedWidgets, unsigned int page);
0761 
0762 private:
0763     FormWidget **widgets;
0764     int numWidgets;
0765     int size;
0766 };
0767 
0768 #endif