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 7 #ifndef CORE_FPDFDOC_CPDF_INTERFORM_H_ 8 #define CORE_FPDFDOC_CPDF_INTERFORM_H_ 9 10 #include <map> 11 #include <memory> 12 #include <vector> 13 14 #include "core/fpdfapi/parser/fpdf_parser_decode.h" 15 #include "core/fpdfdoc/cpdf_defaultappearance.h" 16 #include "core/fxcrt/fx_string.h" 17 #include "core/fxcrt/fx_system.h" 18 #include "core/fxcrt/unowned_ptr.h" 19 20 class CFieldTree; 21 class CFDF_Document; 22 class CPDF_Document; 23 class CPDF_Dictionary; 24 class CPDF_Font; 25 class CPDF_FormControl; 26 class CPDF_FormField; 27 class CPDF_Object; 28 class CPDF_Page; 29 class IPDF_FormNotify; 30 31 CPDF_Font* AddNativeInterFormFont(CPDF_Dictionary*& pFormDict, 32 CPDF_Document* pDocument, 33 ByteString* csNameTag); 34 35 class CPDF_InterForm { 36 public: 37 explicit CPDF_InterForm(CPDF_Document* pDocument); 38 ~CPDF_InterForm(); 39 40 static void SetUpdateAP(bool bUpdateAP); 41 static bool IsUpdateAPEnabled(); 42 static ByteString GenerateNewResourceName(const CPDF_Dictionary* pResDict, 43 const char* csType, 44 int iMinLen, 45 const char* csPrefix); 46 static CPDF_Font* AddStandardFont(CPDF_Document* pDocument, 47 ByteString csFontName); 48 static ByteString GetNativeFont(uint8_t iCharSet, void* pLogFont); 49 static uint8_t GetNativeCharSet(); 50 static CPDF_Font* AddNativeFont(uint8_t iCharSet, CPDF_Document* pDocument); 51 static CPDF_Font* AddNativeFont(CPDF_Document* pDocument); 52 53 size_t CountFields(const WideString& csFieldName) const; 54 CPDF_FormField* GetField(uint32_t index, const WideString& csFieldName) const; 55 CPDF_FormField* GetFieldByDict(CPDF_Dictionary* pFieldDict) const; 56 57 CPDF_FormControl* GetControlAtPoint(CPDF_Page* pPage, 58 const CFX_PointF& point, 59 int* z_order) const; 60 CPDF_FormControl* GetControlByDict(const CPDF_Dictionary* pWidgetDict) const; 61 62 bool NeedConstructAP() const; 63 int CountFieldsInCalculationOrder(); 64 CPDF_FormField* GetFieldInCalculationOrder(int index); 65 int FindFieldInCalculationOrder(const CPDF_FormField* pField); 66 67 CPDF_Font* GetFormFont(ByteString csNameTag) const; 68 CPDF_DefaultAppearance GetDefaultAppearance() const; 69 int GetFormAlignment() const; 70 71 bool CheckRequiredFields(const std::vector<CPDF_FormField*>* fields, 72 bool bIncludeOrExclude) const; 73 74 std::unique_ptr<CFDF_Document> ExportToFDF(const WideString& pdf_path, 75 bool bSimpleFileSpec) const; 76 77 std::unique_ptr<CFDF_Document> ExportToFDF( 78 const WideString& pdf_path, 79 const std::vector<CPDF_FormField*>& fields, 80 bool bIncludeOrExclude, 81 bool bSimpleFileSpec) const; 82 83 bool ResetForm(const std::vector<CPDF_FormField*>& fields, 84 bool bIncludeOrExclude, 85 bool bNotify); 86 bool ResetForm(bool bNotify); 87 88 void SetFormNotify(IPDF_FormNotify* pNotify); 89 bool HasXFAForm() const; 90 void FixPageFields(const CPDF_Page* pPage); 91 GetFormNotify()92 IPDF_FormNotify* GetFormNotify() const { return m_pFormNotify.Get(); } GetDocument()93 CPDF_Document* GetDocument() const { return m_pDocument.Get(); } GetFormDict()94 CPDF_Dictionary* GetFormDict() const { return m_pFormDict.Get(); } 95 96 private: 97 void LoadField(CPDF_Dictionary* pFieldDict, int nLevel); 98 void AddTerminalField(CPDF_Dictionary* pFieldDict); 99 CPDF_FormControl* AddControl(CPDF_FormField* pField, 100 CPDF_Dictionary* pWidgetDict); 101 void FDF_ImportField(CPDF_Dictionary* pField, 102 const WideString& parent_name, 103 bool bNotify = false, 104 int nLevel = 0); 105 106 static bool s_bUpdateAP; 107 108 UnownedPtr<CPDF_Document> const m_pDocument; 109 UnownedPtr<CPDF_Dictionary> m_pFormDict; 110 std::map<const CPDF_Dictionary*, std::unique_ptr<CPDF_FormControl>> 111 m_ControlMap; 112 std::unique_ptr<CFieldTree> m_pFieldTree; 113 ByteString m_bsEncoding; 114 UnownedPtr<IPDF_FormNotify> m_pFormNotify; 115 }; 116 117 #endif // CORE_FPDFDOC_CPDF_INTERFORM_H_ 118