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 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 30 CPDF_Font* AddNativeInterFormFont(CPDF_Dictionary*& pFormDict, 31 CPDF_Document* pDocument, 32 CFX_ByteString& csNameTag); 33 34 class CPDF_InterForm { 35 public: 36 explicit CPDF_InterForm(CPDF_Document* pDocument); 37 ~CPDF_InterForm(); 38 39 static void SetUpdateAP(bool bUpdateAP); 40 static bool IsUpdateAPEnabled(); 41 static CFX_ByteString GenerateNewResourceName(const CPDF_Dictionary* pResDict, 42 const FX_CHAR* csType, 43 int iMinLen, 44 const FX_CHAR* csPrefix); 45 static CPDF_Font* AddStandardFont(CPDF_Document* pDocument, 46 CFX_ByteString csFontName); 47 static CFX_ByteString GetNativeFont(uint8_t iCharSet, void* pLogFont); 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 52 size_t CountFields(const CFX_WideString& csFieldName) const; 53 CPDF_FormField* GetField(uint32_t index, 54 const CFX_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(CFX_ByteString csNameTag); 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 CFX_WideStringC& pdf_path, 75 bool bSimpleFileSpec) const; 76 77 std::unique_ptr<CFDF_Document> ExportToFDF( 78 const CFX_WideStringC& 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 92 private: 93 friend class CPDF_FormControl; 94 friend class CPDF_FormField; 95 96 void LoadField(CPDF_Dictionary* pFieldDict, int nLevel); 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 bool bNotify = false, 103 int nLevel = 0); 104 bool ValidateFieldName(CFX_WideString& csNewFieldName, 105 int iType, 106 const CPDF_FormField* pExcludedField, 107 const CPDF_FormControl* pExcludedControl) const; 108 109 static bool s_bUpdateAP; 110 111 CPDF_Document* const m_pDocument; 112 CPDF_Dictionary* m_pFormDict; 113 std::map<const CPDF_Dictionary*, std::unique_ptr<CPDF_FormControl>> 114 m_ControlMap; 115 std::unique_ptr<CFieldTree> m_pFieldTree; 116 CFX_ByteString m_bsEncoding; 117 IPDF_FormNotify* m_pFormNotify; 118 }; 119 120 #endif // CORE_FPDFDOC_CPDF_INTERFORM_H_ 121