dsinclair | cac704d | 2016-07-28 12:59:09 -0700 | [diff] [blame] | 1 | // Copyright 2016 PDFium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
dsinclair | 1727aee | 2016-09-29 13:12:56 -0700 | [diff] [blame] | 7 | #ifndef CORE_FPDFDOC_CPDF_INTERFORM_H_ |
| 8 | #define CORE_FPDFDOC_CPDF_INTERFORM_H_ |
dsinclair | cac704d | 2016-07-28 12:59:09 -0700 | [diff] [blame] | 9 | |
| 10 | #include <map> |
| 11 | #include <memory> |
| 12 | #include <vector> |
| 13 | |
dsinclair | 488b7ad | 2016-10-04 11:55:50 -0700 | [diff] [blame^] | 14 | #include "core/fpdfapi/parser/fpdf_parser_decode.h" |
dsinclair | 1727aee | 2016-09-29 13:12:56 -0700 | [diff] [blame] | 15 | #include "core/fpdfdoc/cpdf_defaultappearance.h" |
dsinclair | a52ab74 | 2016-09-29 13:59:29 -0700 | [diff] [blame] | 16 | #include "core/fxcrt/fx_string.h" |
| 17 | #include "core/fxcrt/fx_system.h" |
dsinclair | cac704d | 2016-07-28 12:59:09 -0700 | [diff] [blame] | 18 | |
| 19 | class CFieldTree; |
| 20 | class CFDF_Document; |
| 21 | class CPDF_Document; |
| 22 | class CPDF_Dictionary; |
| 23 | class CPDF_Font; |
| 24 | class CPDF_FormControl; |
| 25 | class CPDF_FormField; |
| 26 | class CPDF_Object; |
| 27 | class CPDF_Page; |
| 28 | class IPDF_FormNotify; |
| 29 | |
dsinclair | 27053d8 | 2016-08-02 15:43:46 -0700 | [diff] [blame] | 30 | CPDF_Font* AddNativeInterFormFont(CPDF_Dictionary*& pFormDict, |
| 31 | CPDF_Document* pDocument, |
| 32 | CFX_ByteString& csNameTag); |
| 33 | |
dsinclair | cac704d | 2016-07-28 12:59:09 -0700 | [diff] [blame] | 34 | class CPDF_InterForm { |
| 35 | public: |
| 36 | explicit CPDF_InterForm(CPDF_Document* pDocument); |
| 37 | ~CPDF_InterForm(); |
| 38 | |
thestig | 7c292e0 | 2016-09-28 14:14:26 -0700 | [diff] [blame] | 39 | static void SetUpdateAP(bool bUpdateAP); |
| 40 | static bool IsUpdateAPEnabled(); |
dsinclair | cac704d | 2016-07-28 12:59:09 -0700 | [diff] [blame] | 41 | static CFX_ByteString GenerateNewResourceName(const CPDF_Dictionary* pResDict, |
| 42 | const FX_CHAR* csType, |
thestig | 7c292e0 | 2016-09-28 14:14:26 -0700 | [diff] [blame] | 43 | int iMinLen, |
| 44 | const FX_CHAR* csPrefix); |
dsinclair | cac704d | 2016-07-28 12:59:09 -0700 | [diff] [blame] | 45 | static CPDF_Font* AddStandardFont(CPDF_Document* pDocument, |
| 46 | CFX_ByteString csFontName); |
thestig | 7c292e0 | 2016-09-28 14:14:26 -0700 | [diff] [blame] | 47 | static CFX_ByteString GetNativeFont(uint8_t iCharSet, void* pLogFont); |
dsinclair | cac704d | 2016-07-28 12:59:09 -0700 | [diff] [blame] | 48 | static uint8_t GetNativeCharSet(); |
| 49 | static CPDF_Font* AddNativeFont(uint8_t iCharSet, CPDF_Document* pDocument); |
| 50 | static CPDF_Font* AddNativeFont(CPDF_Document* pDocument); |
| 51 | |
thestig | 7c292e0 | 2016-09-28 14:14:26 -0700 | [diff] [blame] | 52 | size_t CountFields(const CFX_WideString& csFieldName) const; |
dsinclair | cac704d | 2016-07-28 12:59:09 -0700 | [diff] [blame] | 53 | CPDF_FormField* GetField(uint32_t index, |
thestig | 7c292e0 | 2016-09-28 14:14:26 -0700 | [diff] [blame] | 54 | const CFX_WideString& csFieldName) const; |
dsinclair | cac704d | 2016-07-28 12:59:09 -0700 | [diff] [blame] | 55 | CPDF_FormField* GetFieldByDict(CPDF_Dictionary* pFieldDict) const; |
| 56 | |
| 57 | CPDF_FormControl* GetControlAtPoint(CPDF_Page* pPage, |
| 58 | FX_FLOAT pdf_x, |
| 59 | FX_FLOAT pdf_y, |
| 60 | int* z_order) const; |
| 61 | CPDF_FormControl* GetControlByDict(const CPDF_Dictionary* pWidgetDict) const; |
| 62 | |
dsinclair | cac704d | 2016-07-28 12:59:09 -0700 | [diff] [blame] | 63 | FX_BOOL NeedConstructAP() const; |
| 64 | int CountFieldsInCalculationOrder(); |
| 65 | CPDF_FormField* GetFieldInCalculationOrder(int index); |
| 66 | int FindFieldInCalculationOrder(const CPDF_FormField* pField); |
| 67 | |
dsinclair | cac704d | 2016-07-28 12:59:09 -0700 | [diff] [blame] | 68 | CPDF_Font* GetFormFont(CFX_ByteString csNameTag); |
thestig | 7c292e0 | 2016-09-28 14:14:26 -0700 | [diff] [blame] | 69 | CPDF_DefaultAppearance GetDefaultAppearance() const; |
| 70 | int GetFormAlignment() const; |
dsinclair | cac704d | 2016-07-28 12:59:09 -0700 | [diff] [blame] | 71 | |
| 72 | CPDF_FormField* CheckRequiredFields( |
| 73 | const std::vector<CPDF_FormField*>* fields, |
| 74 | bool bIncludeOrExclude) const; |
| 75 | |
| 76 | CFDF_Document* ExportToFDF(const CFX_WideStringC& pdf_path, |
thestig | 7c292e0 | 2016-09-28 14:14:26 -0700 | [diff] [blame] | 77 | bool bSimpleFileSpec) const; |
dsinclair | cac704d | 2016-07-28 12:59:09 -0700 | [diff] [blame] | 78 | CFDF_Document* ExportToFDF(const CFX_WideStringC& pdf_path, |
| 79 | const std::vector<CPDF_FormField*>& fields, |
thestig | 7c292e0 | 2016-09-28 14:14:26 -0700 | [diff] [blame] | 80 | bool bIncludeOrExclude, |
| 81 | bool bSimpleFileSpec) const; |
dsinclair | cac704d | 2016-07-28 12:59:09 -0700 | [diff] [blame] | 82 | |
| 83 | bool ResetForm(const std::vector<CPDF_FormField*>& fields, |
thestig | 7c292e0 | 2016-09-28 14:14:26 -0700 | [diff] [blame] | 84 | bool bIncludeOrExclude, |
| 85 | bool bNotify); |
| 86 | bool ResetForm(bool bNotify); |
dsinclair | cac704d | 2016-07-28 12:59:09 -0700 | [diff] [blame] | 87 | |
| 88 | void SetFormNotify(IPDF_FormNotify* pNotify); |
| 89 | FX_BOOL HasXFAForm() const; |
| 90 | void FixPageFields(const CPDF_Page* pPage); |
| 91 | |
| 92 | private: |
| 93 | friend class CPDF_FormControl; |
| 94 | friend class CPDF_FormField; |
| 95 | |
thestig | 7c292e0 | 2016-09-28 14:14:26 -0700 | [diff] [blame] | 96 | void LoadField(CPDF_Dictionary* pFieldDict, int nLevel); |
dsinclair | cac704d | 2016-07-28 12:59:09 -0700 | [diff] [blame] | 97 | CPDF_FormField* AddTerminalField(CPDF_Dictionary* pFieldDict); |
| 98 | CPDF_FormControl* AddControl(CPDF_FormField* pField, |
| 99 | CPDF_Dictionary* pWidgetDict); |
| 100 | void FDF_ImportField(CPDF_Dictionary* pField, |
| 101 | const CFX_WideString& parent_name, |
| 102 | FX_BOOL bNotify = FALSE, |
| 103 | int nLevel = 0); |
thestig | 7c292e0 | 2016-09-28 14:14:26 -0700 | [diff] [blame] | 104 | bool ValidateFieldName(CFX_WideString& csNewFieldName, |
| 105 | int iType, |
| 106 | const CPDF_FormField* pExcludedField, |
| 107 | const CPDF_FormControl* pExcludedControl) const; |
dsinclair | cac704d | 2016-07-28 12:59:09 -0700 | [diff] [blame] | 108 | |
thestig | 7c292e0 | 2016-09-28 14:14:26 -0700 | [diff] [blame] | 109 | static bool s_bUpdateAP; |
dsinclair | cac704d | 2016-07-28 12:59:09 -0700 | [diff] [blame] | 110 | |
| 111 | CPDF_Document* const m_pDocument; |
| 112 | CPDF_Dictionary* m_pFormDict; |
| 113 | std::map<const CPDF_Dictionary*, CPDF_FormControl*> m_ControlMap; |
| 114 | std::unique_ptr<CFieldTree> m_pFieldTree; |
| 115 | CFX_ByteString m_bsEncoding; |
| 116 | IPDF_FormNotify* m_pFormNotify; |
| 117 | }; |
| 118 | |
dsinclair | 1727aee | 2016-09-29 13:12:56 -0700 | [diff] [blame] | 119 | #endif // CORE_FPDFDOC_CPDF_INTERFORM_H_ |