summaryrefslogtreecommitdiff
path: root/core/fpdfdoc/cpdf_interform.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/fpdfdoc/cpdf_interform.cpp')
-rw-r--r--core/fpdfdoc/cpdf_interform.cpp92
1 files changed, 43 insertions, 49 deletions
diff --git a/core/fpdfdoc/cpdf_interform.cpp b/core/fpdfdoc/cpdf_interform.cpp
index f541d7087c..377a360d9e 100644
--- a/core/fpdfdoc/cpdf_interform.cpp
+++ b/core/fpdfdoc/cpdf_interform.cpp
@@ -4,6 +4,9 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+#include "core/fpdfdoc/cpdf_interform.h"
+
+#include <utility>
#include <vector>
#include "core/fpdfapi/font/cpdf_font.h"
@@ -12,11 +15,11 @@
#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"
#include "core/fpdfdoc/cpdf_formcontrol.h"
-#include "core/fpdfdoc/cpdf_interform.h"
#include "core/fxge/cfx_substfont.h"
#include "core/fxge/fx_font.h"
#include "third_party/base/stl_util.h"
@@ -60,8 +63,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 +97,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 +141,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 +181,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 +216,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 +257,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 +1101,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 +1116,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 +1206,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 +1235,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 +1286,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) {