Index: core/fpdfdoc/cpdf_interform.cpp |
diff --git a/core/fpdfdoc/cpdf_interform.cpp b/core/fpdfdoc/cpdf_interform.cpp |
index f541d7087c7f836067677213dbd1c285d13d37b0..4edcf1bea37c11f013cdfccd6c7b42ae107d1016 100644 |
--- a/core/fpdfdoc/cpdf_interform.cpp |
+++ b/core/fpdfdoc/cpdf_interform.cpp |
@@ -12,6 +12,7 @@ |
#include "core/fpdfapi/parser/cfdf_document.h" |
#include "core/fpdfapi/parser/cpdf_array.h" |
#include "core/fpdfapi/parser/cpdf_document.h" |
+#include "core/fpdfapi/parser/cpdf_name.h" |
#include "core/fpdfapi/parser/cpdf_reference.h" |
#include "core/fpdfapi/parser/cpdf_string.h" |
#include "core/fpdfdoc/cpdf_filespec.h" |
@@ -60,8 +61,8 @@ void InitDict(CPDF_Dictionary*& pFormDict, CPDF_Document* pDocument) { |
if (!pFormDict) { |
pFormDict = pDocument->NewIndirect<CPDF_Dictionary>(); |
- pDocument->GetRoot()->SetReferenceFor("AcroForm", pDocument, |
- pFormDict->GetObjNum()); |
+ pDocument->GetRoot()->SetNewFor<CPDF_Reference>("AcroForm", pDocument, |
+ pFormDict->GetObjNum()); |
} |
CFX_ByteString csDA; |
@@ -94,7 +95,7 @@ void InitDict(CPDF_Dictionary*& pFormDict, CPDF_Document* pDocument) { |
csDA += "0 g"; |
if (!pFormDict->KeyExist("DA")) |
- pFormDict->SetStringFor("DA", csDA); |
+ pFormDict->SetNewFor<CPDF_String>("DA", csDA, false); |
} |
CPDF_Font* GetFont(CPDF_Dictionary* pFormDict, |
@@ -138,11 +139,10 @@ CPDF_Font* GetNativeFont(CPDF_Dictionary* pFormDict, |
for (const auto& it : *pFonts) { |
const CFX_ByteString& csKey = it.first; |
- CPDF_Object* pObj = it.second; |
- if (!pObj) |
+ if (!it.second) |
continue; |
- CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect()); |
+ CPDF_Dictionary* pElement = ToDictionary(it.second->GetDirect()); |
if (!pElement) |
continue; |
if (pElement->GetStringFor("Type") != "Font") |
@@ -179,11 +179,9 @@ bool FindFont(CPDF_Dictionary* pFormDict, |
for (const auto& it : *pFonts) { |
const CFX_ByteString& csKey = it.first; |
- CPDF_Object* pObj = it.second; |
- if (!pObj) |
+ if (!it.second) |
continue; |
- |
- CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect()); |
+ CPDF_Dictionary* pElement = ToDictionary(it.second->GetDirect()); |
if (!pElement) |
continue; |
if (pElement->GetStringFor("Type") != "Font") |
@@ -216,16 +214,14 @@ bool FindFont(CPDF_Dictionary* pFormDict, |
for (const auto& it : *pFonts) { |
const CFX_ByteString& csKey = it.first; |
- CPDF_Object* pObj = it.second; |
- if (!pObj) |
+ if (!it.second) |
continue; |
- CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect()); |
+ CPDF_Dictionary* pElement = ToDictionary(it.second->GetDirect()); |
if (!pElement) |
continue; |
if (pElement->GetStringFor("Type") != "Font") |
continue; |
- |
pFont = pDocument->LoadFont(pElement); |
if (!pFont) |
continue; |
@@ -259,23 +255,21 @@ void AddFont(CPDF_Dictionary*& pFormDict, |
InitDict(pFormDict, pDocument); |
CPDF_Dictionary* pDR = pFormDict->GetDictFor("DR"); |
- if (!pDR) { |
- pDR = new CPDF_Dictionary(pDocument->GetByteStringPool()); |
- pFormDict->SetFor("DR", pDR); |
- } |
+ if (!pDR) |
+ pDR = pFormDict->SetNewFor<CPDF_Dictionary>("DR"); |
+ |
CPDF_Dictionary* pFonts = pDR->GetDictFor("Font"); |
- if (!pFonts) { |
- pFonts = new CPDF_Dictionary(pDocument->GetByteStringPool()); |
- pDR->SetFor("Font", pFonts); |
- } |
+ if (!pFonts) |
+ pFonts = pDR->SetNewFor<CPDF_Dictionary>("Font"); |
+ |
if (csNameTag.IsEmpty()) |
csNameTag = pFont->GetBaseFont(); |
csNameTag.Remove(' '); |
csNameTag = CPDF_InterForm::GenerateNewResourceName(pDR, "Font", 4, |
csNameTag.c_str()); |
- pFonts->SetReferenceFor(csNameTag, pDocument, |
- pFont->GetFontDict()->GetObjNum()); |
+ pFonts->SetNewFor<CPDF_Reference>(csNameTag, pDocument, |
+ pFont->GetFontDict()->GetObjNum()); |
} |
CPDF_Font* AddNativeFont(CPDF_Dictionary*& pFormDict, |
@@ -1105,13 +1099,13 @@ CPDF_FormField* CPDF_InterForm::AddTerminalField(CPDF_Dictionary* pFieldDict) { |
if (pFieldDict->KeyExist("FT")) { |
CPDF_Object* pFTValue = pFieldDict->GetDirectObjectFor("FT"); |
if (pFTValue) |
- pParent->SetFor("FT", pFTValue->Clone().release()); |
+ pParent->SetFor("FT", pFTValue->Clone()); |
} |
if (pFieldDict->KeyExist("Ff")) { |
CPDF_Object* pFfValue = pFieldDict->GetDirectObjectFor("Ff"); |
if (pFfValue) |
- pParent->SetFor("Ff", pFfValue->Clone().release()); |
+ pParent->SetFor("Ff", pFfValue->Clone()); |
} |
} |
@@ -1120,9 +1114,9 @@ CPDF_FormField* CPDF_InterForm::AddTerminalField(CPDF_Dictionary* pFieldDict) { |
if (ToReference(pTObj)) { |
std::unique_ptr<CPDF_Object> pClone = pTObj->CloneDirectObject(); |
if (pClone) |
- pDict->SetFor("T", pClone.release()); |
+ pDict->SetFor("T", std::move(pClone)); |
else |
- pDict->SetNameFor("T", ""); |
+ pDict->SetNewFor<CPDF_Name>("T", ""); |
} |
m_pFieldTree->SetField(csWName, pField); |
} |
@@ -1210,17 +1204,18 @@ CFDF_Document* CPDF_InterForm::ExportToFDF( |
if (!pdf_path.IsEmpty()) { |
if (bSimpleFileSpec) { |
CFX_WideString wsFilePath = CPDF_FileSpec::EncodeFileName(pdf_path); |
- pMainDict->SetStringFor("F", CFX_ByteString::FromUnicode(wsFilePath)); |
- pMainDict->SetStringFor("UF", PDF_EncodeText(wsFilePath)); |
+ pMainDict->SetNewFor<CPDF_String>( |
+ "F", CFX_ByteString::FromUnicode(wsFilePath), false); |
+ pMainDict->SetNewFor<CPDF_String>("UF", PDF_EncodeText(wsFilePath), |
+ false); |
} else { |
CPDF_FileSpec filespec(pDoc->GetByteStringPool()); |
filespec.SetFileName(pdf_path); |
- pMainDict->SetFor("F", filespec.GetObj()); |
+ pMainDict->SetFor("F", pdfium::WrapUnique(filespec.GetObj())); |
} |
} |
- CPDF_Array* pFields = new CPDF_Array; |
- pMainDict->SetFor("Fields", pFields); |
+ CPDF_Array* pFields = pMainDict->SetNewFor<CPDF_Array>("Fields"); |
size_t nCount = m_pFieldTree->m_Root.CountFields(); |
for (size_t i = 0; i < nCount; ++i) { |
CPDF_FormField* pField = m_pFieldTree->m_Root.GetFieldAtIndex(i); |
@@ -1238,20 +1233,20 @@ CFDF_Document* CPDF_InterForm::ExportToFDF( |
CFX_WideString fullname = FPDF_GetFullName(pField->GetFieldDict()); |
auto pFieldDict = |
pdfium::MakeUnique<CPDF_Dictionary>(pDoc->GetByteStringPool()); |
- pFieldDict->SetFor("T", new CPDF_String(fullname)); |
+ pFieldDict->SetNewFor<CPDF_String>("T", fullname); |
if (pField->GetType() == CPDF_FormField::CheckBox || |
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"); |
if (pOpt) |
- pFieldDict->SetStringFor("V", csBExport); |
+ pFieldDict->SetNewFor<CPDF_String>("V", csBExport, false); |
else |
- pFieldDict->SetNameFor("V", csBExport); |
+ pFieldDict->SetNewFor<CPDF_Name>("V", csBExport); |
} else { |
CPDF_Object* pV = FPDF_GetFieldAttr(pField->m_pDict, "V"); |
if (pV) |
- pFieldDict->SetFor("V", pV->CloneDirectObject().release()); |
+ pFieldDict->SetFor("V", pV->CloneDirectObject()); |
} |
pFields->Add(std::move(pFieldDict)); |
} |
@@ -1289,23 +1284,20 @@ void CPDF_InterForm::FDF_ImportField(CPDF_Dictionary* pFieldDict, |
CFX_WideString csWValue = GetFieldValue(*pFieldDict, m_bsEncoding); |
int iType = pField->GetFieldType(); |
if (bNotify && m_pFormNotify) { |
- int iRet = 0; |
- if (iType == FIELDTYPE_LISTBOX) |
- iRet = m_pFormNotify->BeforeSelectionChange(pField, csWValue); |
- else if (iType == FIELDTYPE_COMBOBOX || iType == FIELDTYPE_TEXTFIELD) |
- iRet = m_pFormNotify->BeforeValueChange(pField, csWValue); |
- |
- if (iRet < 0) |
- return; |
+ if (iType == FIELDTYPE_LISTBOX) { |
+ if (m_pFormNotify->BeforeSelectionChange(pField, csWValue) < 0) |
+ return; |
+ } else if (iType == FIELDTYPE_COMBOBOX || iType == FIELDTYPE_TEXTFIELD) { |
+ if (m_pFormNotify->BeforeValueChange(pField, csWValue) < 0) |
+ return; |
+ } |
} |
- |
pField->SetValue(csWValue); |
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().release()); |
+ "Opt", pFieldDict->GetDirectObjectFor("Opt")->CloneDirectObject()); |
} |
if (bNotify && m_pFormNotify) { |