diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/fpdfdoc/cpdf_formcontrol.cpp | 28 | ||||
-rw-r--r-- | core/fpdfdoc/cpdf_formcontrol.h | 4 | ||||
-rw-r--r-- | core/fpdfdoc/cpdf_formfield.cpp | 2 | ||||
-rw-r--r-- | core/fpdfdoc/cpdf_formfield.h | 21 | ||||
-rw-r--r-- | core/fpdfdoc/cpdf_interform.cpp | 19 | ||||
-rw-r--r-- | core/fpdfdoc/cpdf_interform.h | 2 |
6 files changed, 44 insertions, 32 deletions
diff --git a/core/fpdfdoc/cpdf_formcontrol.cpp b/core/fpdfdoc/cpdf_formcontrol.cpp index d8d6854b82..d9740f7c99 100644 --- a/core/fpdfdoc/cpdf_formcontrol.cpp +++ b/core/fpdfdoc/cpdf_formcontrol.cpp @@ -30,7 +30,7 @@ CPDF_FormControl::CPDF_FormControl(CPDF_FormField* pField, CPDF_Dictionary* pWidgetDict) : m_pField(pField), m_pWidgetDict(pWidgetDict), - m_pForm(m_pField->m_pForm) {} + m_pForm(m_pField->GetForm()) {} CFX_ByteString CPDF_FormControl::GetOnStateName() const { ASSERT(GetType() == CPDF_FormField::CheckBox || @@ -99,7 +99,7 @@ CFX_ByteString CPDF_FormControl::GetCheckedAPState() { CFX_ByteString csOn = GetOnStateName(); if (GetType() == CPDF_FormField::RadioButton || GetType() == CPDF_FormField::CheckBox) { - if (ToArray(FPDF_GetFieldAttr(m_pField->m_pDict, "Opt"))) { + if (ToArray(FPDF_GetFieldAttr(m_pField->GetDict(), "Opt"))) { int iIndex = m_pField->GetControlIndex(this); csOn.Format("%d", iIndex); } @@ -116,7 +116,7 @@ CFX_WideString CPDF_FormControl::GetExportValue() const { if (GetType() == CPDF_FormField::RadioButton || GetType() == CPDF_FormField::CheckBox) { if (CPDF_Array* pArray = - ToArray(FPDF_GetFieldAttr(m_pField->m_pDict, "Opt"))) { + ToArray(FPDF_GetFieldAttr(m_pField->GetDict(), "Opt"))) { int iIndex = m_pField->GetControlIndex(this); csOn = pArray->GetStringAt(iIndex); } @@ -137,7 +137,7 @@ bool CPDF_FormControl::IsChecked() const { bool CPDF_FormControl::IsDefaultChecked() const { ASSERT(GetType() == CPDF_FormField::CheckBox || GetType() == CPDF_FormField::RadioButton); - CPDF_Object* pDV = FPDF_GetFieldAttr(m_pField->m_pDict, "DV"); + CPDF_Object* pDV = FPDF_GetFieldAttr(m_pField->GetDict(), "DV"); if (!pDV) return false; @@ -178,8 +178,8 @@ void CPDF_FormControl::DrawControl(CFX_RenderDevice* pDevice, CFX_Matrix matrix; matrix.MatchRect(arect, form_bbox); matrix.Concat(*pMatrix); - CPDF_Form form(m_pField->m_pForm->m_pDocument, - m_pField->m_pForm->m_pFormDict->GetDictFor("DR"), pStream); + CPDF_Form form(m_pField->GetForm()->m_pDocument, + m_pField->GetForm()->m_pFormDict->GetDictFor("DR"), pStream); form.ParseContent(nullptr, nullptr, nullptr); CPDF_RenderContext context(pPage); context.AppendLayer(&form, &matrix); @@ -250,7 +250,7 @@ CPDF_Action CPDF_FormControl::GetAction() { if (m_pWidgetDict->KeyExist("A")) return CPDF_Action(m_pWidgetDict->GetDictFor("A")); - CPDF_Object* pObj = FPDF_GetFieldAttr(m_pField->m_pDict, "A"); + CPDF_Object* pObj = FPDF_GetFieldAttr(m_pField->GetDict(), "A"); if (!pObj) return CPDF_Action(); @@ -273,10 +273,10 @@ CPDF_DefaultAppearance CPDF_FormControl::GetDefaultAppearance() { if (m_pWidgetDict->KeyExist("DA")) return CPDF_DefaultAppearance(m_pWidgetDict->GetStringFor("DA")); - CPDF_Object* pObj = FPDF_GetFieldAttr(m_pField->m_pDict, "DA"); + CPDF_Object* pObj = FPDF_GetFieldAttr(m_pField->GetDict(), "DA"); if (pObj) return CPDF_DefaultAppearance(pObj->GetString()); - return m_pField->m_pForm->GetDefaultAppearance(); + return m_pField->GetForm()->GetDefaultAppearance(); } CPDF_Font* CPDF_FormControl::GetDefaultControlFont() { @@ -292,13 +292,13 @@ CPDF_Font* CPDF_FormControl::GetDefaultControlFont() { if (pFonts) { CPDF_Dictionary* pElement = pFonts->GetDictFor(csFontNameTag); if (pElement) { - CPDF_Font* pFont = m_pField->m_pForm->m_pDocument->LoadFont(pElement); + CPDF_Font* pFont = m_pField->GetForm()->m_pDocument->LoadFont(pElement); if (pFont) return pFont; } } } - if (CPDF_Font* pFormFont = m_pField->m_pForm->GetFormFont(csFontNameTag)) + if (CPDF_Font* pFormFont = m_pField->GetForm()->GetFormFont(csFontNameTag)) return pFormFont; CPDF_Dictionary* pPageDict = m_pWidgetDict->GetDictFor("P"); @@ -308,7 +308,7 @@ CPDF_Font* CPDF_FormControl::GetDefaultControlFont() { if (pFonts) { CPDF_Dictionary* pElement = pFonts->GetDictFor(csFontNameTag); if (pElement) { - CPDF_Font* pFont = m_pField->m_pForm->m_pDocument->LoadFont(pElement); + CPDF_Font* pFont = m_pField->GetForm()->m_pDocument->LoadFont(pElement); if (pFont) return pFont; } @@ -323,8 +323,8 @@ int CPDF_FormControl::GetControlAlignment() { if (m_pWidgetDict->KeyExist("Q")) return m_pWidgetDict->GetIntegerFor("Q", 0); - CPDF_Object* pObj = FPDF_GetFieldAttr(m_pField->m_pDict, "Q"); + CPDF_Object* pObj = FPDF_GetFieldAttr(m_pField->GetDict(), "Q"); if (pObj) return pObj->GetInteger(); - return m_pField->m_pForm->GetFormAlignment(); + return m_pField->GetForm()->GetFormAlignment(); } diff --git a/core/fpdfdoc/cpdf_formcontrol.h b/core/fpdfdoc/cpdf_formcontrol.h index fff77fb32d..154d592f32 100644 --- a/core/fpdfdoc/cpdf_formcontrol.h +++ b/core/fpdfdoc/cpdf_formcontrol.h @@ -49,7 +49,7 @@ class CPDF_FormControl { CPDF_FormControl(CPDF_FormField* pField, CPDF_Dictionary* pWidgetDict); CPDF_FormField::Type GetType() const { return m_pField->GetType(); } - CPDF_InterForm* GetInterForm() const { return m_pForm; } + const CPDF_InterForm* GetInterForm() const { return m_pForm; } CPDF_FormField* GetField() const { return m_pField; } CPDF_Dictionary* GetWidget() const { return m_pWidgetDict; } CFX_FloatRect GetRect() const { return m_pWidgetDict->GetRectFor("Rect"); } @@ -128,7 +128,7 @@ class CPDF_FormControl { CPDF_FormField* const m_pField; CPDF_Dictionary* const m_pWidgetDict; - CPDF_InterForm* const m_pForm; + const CPDF_InterForm* const m_pForm; }; #endif // CORE_FPDFDOC_CPDF_FORMCONTROL_H_ diff --git a/core/fpdfdoc/cpdf_formfield.cpp b/core/fpdfdoc/cpdf_formfield.cpp index e7ca7c6a8d..9007d8b0da 100644 --- a/core/fpdfdoc/cpdf_formfield.cpp +++ b/core/fpdfdoc/cpdf_formfield.cpp @@ -47,7 +47,7 @@ bool IsUnison(CPDF_FormField* pField) { } // namespace -CPDF_Object* FPDF_GetFieldAttr(CPDF_Dictionary* pFieldDict, +CPDF_Object* FPDF_GetFieldAttr(const CPDF_Dictionary* pFieldDict, const char* name, int nLevel) { if (nLevel > kMaxRecursion) diff --git a/core/fpdfdoc/cpdf_formfield.h b/core/fpdfdoc/cpdf_formfield.h index 951d31c792..6ec7a5b414 100644 --- a/core/fpdfdoc/cpdf_formfield.h +++ b/core/fpdfdoc/cpdf_formfield.h @@ -7,6 +7,8 @@ #ifndef CORE_FPDFDOC_CPDF_FORMFIELD_H_ #define CORE_FPDFDOC_CPDF_FORMFIELD_H_ +#include <memory> +#include <utility> #include <vector> #include "core/fpdfdoc/cpdf_aaction.h" @@ -35,7 +37,7 @@ class CPDF_FormControl; class CPDF_InterForm; class CPDF_String; -CPDF_Object* FPDF_GetFieldAttr(CPDF_Dictionary* pFieldDict, +CPDF_Object* FPDF_GetFieldAttr(const CPDF_Dictionary* pFieldDict, const char* name, int nLevel = 0); CFX_WideString FPDF_GetFullName(CPDF_Dictionary* pFieldDict); @@ -131,10 +133,20 @@ class CPDF_FormField { float GetFontSize() const { return m_FontSize; } CPDF_Font* GetFont() const { return m_pFont; } - private: - friend class CPDF_InterForm; - friend class CPDF_FormControl; + const CPDF_Dictionary* GetDict() const { return m_pDict; } + const CPDF_InterForm* GetForm() const { return m_pForm; } + + CFX_WideString GetCheckValue(bool bDefault) const; + + void AddFormControl(CPDF_FormControl* pFormControl) { + m_ControlList.push_back(pFormControl); + } + void SetOpt(std::unique_ptr<CPDF_Object> pOpt) { + m_pDict->SetFor("Opt", std::move(pOpt)); + } + + private: CFX_WideString GetValue(bool bDefault) const; bool SetValue(const CFX_WideString& value, bool bDefault, bool bNotify); @@ -143,7 +155,6 @@ class CPDF_FormField { CFX_WideString GetOptionText(int index, int sub_index) const; void LoadDA(); - CFX_WideString GetCheckValue(bool bDefault) const; bool SetCheckValue(const CFX_WideString& value, bool bDefault, bool bNotify); bool NotifyBeforeSelectionChange(const CFX_WideString& value); diff --git a/core/fpdfdoc/cpdf_interform.cpp b/core/fpdfdoc/cpdf_interform.cpp index 23102a20ad..dad25aa037 100644 --- a/core/fpdfdoc/cpdf_interform.cpp +++ b/core/fpdfdoc/cpdf_interform.cpp @@ -948,13 +948,13 @@ int CPDF_InterForm::FindFieldInCalculationOrder(const CPDF_FormField* pField) { for (size_t i = 0; i < pArray->GetCount(); i++) { CPDF_Object* pElement = pArray->GetDirectObjectAt(i); - if (pElement == pField->m_pDict) + if (pElement == pField->GetDict()) return i; } return -1; } -CPDF_Font* CPDF_InterForm::GetFormFont(CFX_ByteString csNameTag) { +CPDF_Font* CPDF_InterForm::GetFormFont(CFX_ByteString csNameTag) const { return GetFont(m_pFormDict, m_pDocument, csNameTag); } @@ -1133,7 +1133,7 @@ CPDF_FormControl* CPDF_InterForm::AddControl(CPDF_FormField* pField, auto pNew = pdfium::MakeUnique<CPDF_FormControl>(pField, pWidgetDict); CPDF_FormControl* pControl = pNew.get(); m_ControlMap[pWidgetDict] = std::move(pNew); - pField->m_ControlList.push_back(pControl); + pField->AddFormControl(pControl); return pControl; } @@ -1160,7 +1160,7 @@ bool CPDF_InterForm::CheckRequiredFields( if (fields) bFind = pdfium::ContainsValue(*fields, pField); if (bIncludeOrExclude == bFind) { - CPDF_Dictionary* pFieldDict = pField->m_pDict; + const CPDF_Dictionary* pFieldDict = pField->GetDict(); if ((dwFlags & FORMFLAG_REQUIRED) != 0 && pFieldDict->GetStringFor("V").IsEmpty()) { return false; @@ -1216,8 +1216,10 @@ std::unique_ptr<CFDF_Document> CPDF_InterForm::ExportToFDF( continue; if (bIncludeOrExclude == pdfium::ContainsValue(fields, pField)) { - if ((dwFlags & 0x02) != 0 && pField->m_pDict->GetStringFor("V").IsEmpty()) + if ((dwFlags & 0x02) != 0 && + pField->GetDict()->GetStringFor("V").IsEmpty()) { continue; + } CFX_WideString fullname = FPDF_GetFullName(pField->GetFieldDict()); auto pFieldDict = @@ -1227,13 +1229,13 @@ std::unique_ptr<CFDF_Document> CPDF_InterForm::ExportToFDF( pField->GetType() == CPDF_FormField::RadioButton) { CFX_WideString csExport = pField->GetCheckValue(false); CFX_ByteString csBExport = PDF_EncodeText(csExport); - CPDF_Object* pOpt = FPDF_GetFieldAttr(pField->m_pDict, "Opt"); + CPDF_Object* pOpt = FPDF_GetFieldAttr(pField->GetDict(), "Opt"); if (pOpt) pFieldDict->SetNewFor<CPDF_String>("V", csBExport, false); else pFieldDict->SetNewFor<CPDF_Name>("V", csBExport); } else { - CPDF_Object* pV = FPDF_GetFieldAttr(pField->m_pDict, "V"); + CPDF_Object* pV = FPDF_GetFieldAttr(pField->GetDict(), "V"); if (pV) pFieldDict->SetFor("V", pV->CloneDirectObject()); } @@ -1285,8 +1287,7 @@ void CPDF_InterForm::FDF_ImportField(CPDF_Dictionary* pFieldDict, CPDF_FormField::Type eType = pField->GetType(); if ((eType == CPDF_FormField::ListBox || eType == CPDF_FormField::ComboBox) && pFieldDict->KeyExist("Opt")) { - pField->m_pDict->SetFor( - "Opt", pFieldDict->GetDirectObjectFor("Opt")->CloneDirectObject()); + pField->SetOpt(pFieldDict->GetDirectObjectFor("Opt")->CloneDirectObject()); } if (bNotify && m_pFormNotify) { diff --git a/core/fpdfdoc/cpdf_interform.h b/core/fpdfdoc/cpdf_interform.h index 74e5b10864..5399392734 100644 --- a/core/fpdfdoc/cpdf_interform.h +++ b/core/fpdfdoc/cpdf_interform.h @@ -64,7 +64,7 @@ class CPDF_InterForm { CPDF_FormField* GetFieldInCalculationOrder(int index); int FindFieldInCalculationOrder(const CPDF_FormField* pField); - CPDF_Font* GetFormFont(CFX_ByteString csNameTag); + CPDF_Font* GetFormFont(CFX_ByteString csNameTag) const; CPDF_DefaultAppearance GetDefaultAppearance() const; int GetFormAlignment() const; |