summaryrefslogtreecommitdiff
path: root/core/fpdfdoc
diff options
context:
space:
mode:
Diffstat (limited to 'core/fpdfdoc')
-rw-r--r--core/fpdfdoc/cpdf_annot.cpp3
-rw-r--r--core/fpdfdoc/cpdf_annotlist.cpp14
-rw-r--r--core/fpdfdoc/cpdf_filespec.cpp9
-rw-r--r--core/fpdfdoc/cpdf_filespec_unittest.cpp9
-rw-r--r--core/fpdfdoc/cpdf_formcontrol.cpp9
-rw-r--r--core/fpdfdoc/cpdf_formfield.cpp48
-rw-r--r--core/fpdfdoc/cpdf_formfield_unittest.cpp17
-rw-r--r--core/fpdfdoc/cpdf_interform.cpp92
-rw-r--r--core/fpdfdoc/cpvt_fontmap.cpp5
-rw-r--r--core/fpdfdoc/cpvt_generateap.cpp103
10 files changed, 154 insertions, 155 deletions
diff --git a/core/fpdfdoc/cpdf_annot.cpp b/core/fpdfdoc/cpdf_annot.cpp
index a213f51a6d..a7d2101364 100644
--- a/core/fpdfdoc/cpdf_annot.cpp
+++ b/core/fpdfdoc/cpdf_annot.cpp
@@ -9,6 +9,7 @@
#include "core/fpdfapi/page/cpdf_form.h"
#include "core/fpdfapi/page/cpdf_page.h"
#include "core/fpdfapi/parser/cpdf_array.h"
+#include "core/fpdfapi/parser/cpdf_boolean.h"
#include "core/fpdfapi/parser/cpdf_document.h"
#include "core/fpdfapi/render/cpdf_rendercontext.h"
#include "core/fpdfapi/render/cpdf_renderoptions.h"
@@ -109,7 +110,7 @@ void CPDF_Annot::GenerateAPIfNeeded() {
result = CPVT_GenerateAP::GenerateUnderlineAP(m_pDocument, m_pAnnotDict);
if (result) {
- m_pAnnotDict->SetBooleanFor(kPDFiumKey_HasGeneratedAP, result);
+ m_pAnnotDict->SetNewFor<CPDF_Boolean>(kPDFiumKey_HasGeneratedAP, result);
m_bHasGeneratedAP = result;
}
}
diff --git a/core/fpdfdoc/cpdf_annotlist.cpp b/core/fpdfdoc/cpdf_annotlist.cpp
index 91cff454e3..e68e08a1f6 100644
--- a/core/fpdfdoc/cpdf_annotlist.cpp
+++ b/core/fpdfdoc/cpdf_annotlist.cpp
@@ -11,7 +11,10 @@
#include "core/fpdfapi/page/cpdf_page.h"
#include "core/fpdfapi/parser/cpdf_document.h"
+#include "core/fpdfapi/parser/cpdf_name.h"
+#include "core/fpdfapi/parser/cpdf_number.h"
#include "core/fpdfapi/parser/cpdf_reference.h"
+#include "core/fpdfapi/parser/cpdf_string.h"
#include "core/fpdfapi/render/cpdf_renderoptions.h"
#include "core/fpdfdoc/cpdf_annot.h"
#include "core/fpdfdoc/cpdf_interform.h"
@@ -36,10 +39,11 @@ std::unique_ptr<CPDF_Annot> CreatePopupAnnot(CPDF_Annot* pAnnot,
auto pAnnotDict =
pdfium::MakeUnique<CPDF_Dictionary>(pDocument->GetByteStringPool());
- pAnnotDict->SetNameFor("Type", "Annot");
- pAnnotDict->SetNameFor("Subtype", "Popup");
- pAnnotDict->SetStringFor("T", pParentDict->GetStringFor("T"));
- pAnnotDict->SetStringFor("Contents", sContents.UTF8Encode());
+ pAnnotDict->SetNewFor<CPDF_Name>("Type", "Annot");
+ pAnnotDict->SetNewFor<CPDF_Name>("Subtype", "Popup");
+ pAnnotDict->SetNewFor<CPDF_String>("T", pParentDict->GetStringFor("T"),
+ false);
+ pAnnotDict->SetNewFor<CPDF_String>("Contents", sContents.UTF8Encode(), false);
CFX_FloatRect rect = pParentDict->GetRectFor("Rect");
rect.Normalize();
@@ -47,7 +51,7 @@ std::unique_ptr<CPDF_Annot> CreatePopupAnnot(CPDF_Annot* pAnnot,
popupRect.Translate(rect.left, rect.bottom - popupRect.Height());
pAnnotDict->SetRectFor("Rect", popupRect);
- pAnnotDict->SetIntegerFor("F", 0);
+ pAnnotDict->SetNewFor<CPDF_Number>("F", 0);
auto pPopupAnnot =
pdfium::MakeUnique<CPDF_Annot>(std::move(pAnnotDict), pDocument);
diff --git a/core/fpdfdoc/cpdf_filespec.cpp b/core/fpdfdoc/cpdf_filespec.cpp
index 46b7f8a446..d6a66f7b73 100644
--- a/core/fpdfdoc/cpdf_filespec.cpp
+++ b/core/fpdfdoc/cpdf_filespec.cpp
@@ -7,7 +7,9 @@
#include "core/fpdfdoc/cpdf_filespec.h"
#include "core/fpdfapi/parser/cpdf_dictionary.h"
+#include "core/fpdfapi/parser/cpdf_name.h"
#include "core/fpdfapi/parser/cpdf_object.h"
+#include "core/fpdfapi/parser/cpdf_string.h"
#include "core/fpdfapi/parser/fpdf_parser_decode.h"
#include "core/fxcrt/fx_system.h"
@@ -112,7 +114,7 @@ bool CPDF_FileSpec::GetFileName(CFX_WideString* csFileName) const {
CPDF_FileSpec::CPDF_FileSpec(const CFX_WeakPtr<CFX_ByteStringPool>& pPool) {
m_pObj = new CPDF_Dictionary(pPool);
- m_pObj->AsDictionary()->SetNameFor("Type", "Filespec");
+ m_pObj->AsDictionary()->SetNewFor<CPDF_Name>("Type", "Filespec");
}
CFX_WideString CPDF_FileSpec::EncodeFileName(const CFX_WideStringC& filepath) {
@@ -161,7 +163,8 @@ void CPDF_FileSpec::SetFileName(const CFX_WideStringC& wsFileName) {
if (m_pObj->IsString()) {
m_pObj->SetString(CFX_ByteString::FromUnicode(wsStr));
} else if (CPDF_Dictionary* pDict = m_pObj->AsDictionary()) {
- pDict->SetStringFor("F", CFX_ByteString::FromUnicode(wsStr));
- pDict->SetStringFor("UF", PDF_EncodeText(wsStr));
+ pDict->SetNewFor<CPDF_String>("F", CFX_ByteString::FromUnicode(wsStr),
+ false);
+ pDict->SetNewFor<CPDF_String>("UF", PDF_EncodeText(wsStr), false);
}
}
diff --git a/core/fpdfdoc/cpdf_filespec_unittest.cpp b/core/fpdfdoc/cpdf_filespec_unittest.cpp
index 4da5019314..d164165f00 100644
--- a/core/fpdfdoc/cpdf_filespec_unittest.cpp
+++ b/core/fpdfdoc/cpdf_filespec_unittest.cpp
@@ -67,7 +67,8 @@ TEST(cpdf_filespec, GetFileName) {
L"/docs/test.pdf"
#endif
};
- std::unique_ptr<CPDF_Object> str_obj(new CPDF_String(test_data.input));
+ std::unique_ptr<CPDF_Object> str_obj(
+ new CPDF_String(nullptr, test_data.input));
CPDF_FileSpec file_spec(str_obj.get());
CFX_WideString file_name;
EXPECT_TRUE(file_spec.GetFileName(&file_name));
@@ -102,13 +103,13 @@ TEST(cpdf_filespec, GetFileName) {
CPDF_FileSpec file_spec(dict_obj.get());
CFX_WideString file_name;
for (int i = 0; i < 5; ++i) {
- dict_obj->SetFor(keywords[i], new CPDF_String(test_data[i].input));
+ dict_obj->SetNewFor<CPDF_String>(keywords[i], test_data[i].input);
EXPECT_TRUE(file_spec.GetFileName(&file_name));
EXPECT_TRUE(file_name == test_data[i].expected);
}
// With all the former fields and 'FS' field suggests 'URL' type.
- dict_obj->SetStringFor("FS", "URL");
+ dict_obj->SetNewFor<CPDF_String>("FS", "URL", false);
EXPECT_TRUE(file_spec.GetFileName(&file_name));
// Url string is not decoded.
EXPECT_TRUE(file_name == test_data[4].input);
@@ -136,7 +137,7 @@ TEST(cpdf_filespec, SetFileName) {
#endif
};
// String object.
- std::unique_ptr<CPDF_Object> str_obj(new CPDF_String(L"babababa"));
+ std::unique_ptr<CPDF_Object> str_obj(new CPDF_String(nullptr, L"babababa"));
CPDF_FileSpec file_spec1(str_obj.get());
file_spec1.SetFileName(test_data.input);
// Check internal object value.
diff --git a/core/fpdfdoc/cpdf_formcontrol.cpp b/core/fpdfdoc/cpdf_formcontrol.cpp
index b01784b8dd..54edb4910c 100644
--- a/core/fpdfdoc/cpdf_formcontrol.cpp
+++ b/core/fpdfdoc/cpdf_formcontrol.cpp
@@ -11,6 +11,7 @@
#include "core/fpdfapi/page/cpdf_form.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_stream.h"
#include "core/fpdfapi/parser/fpdf_parser_decode.h"
#include "core/fpdfapi/render/cpdf_rendercontext.h"
@@ -61,14 +62,14 @@ void CPDF_FormControl::SetOnStateName(const CFX_ByteString& csOn) {
CFX_ByteString csAS = m_pWidgetDict->GetStringFor("AS", "Off");
if (csAS != "Off")
- m_pWidgetDict->SetNameFor("AS", csValue);
+ m_pWidgetDict->SetNewFor<CPDF_Name>("AS", csValue);
CPDF_Dictionary* pAP = m_pWidgetDict->GetDictFor("AP");
if (!pAP)
return;
for (const auto& it : *pAP) {
- CPDF_Object* pObj1 = it.second;
+ CPDF_Object* pObj1 = it.second.get();
if (!pObj1)
continue;
@@ -80,7 +81,7 @@ void CPDF_FormControl::SetOnStateName(const CFX_ByteString& csOn) {
auto subdict_it = pSubDict->begin();
while (subdict_it != pSubDict->end()) {
const CFX_ByteString& csKey2 = subdict_it->first;
- CPDF_Object* pObj2 = subdict_it->second;
+ CPDF_Object* pObj2 = subdict_it->second.get();
++subdict_it;
if (!pObj2)
continue;
@@ -155,7 +156,7 @@ void CPDF_FormControl::CheckControl(bool bChecked) {
csAS = csOn;
if (csOldAS == csAS)
return;
- m_pWidgetDict->SetNameFor("AS", csAS);
+ m_pWidgetDict->SetNewFor<CPDF_Name>("AS", csAS);
}
void CPDF_FormControl::DrawControl(CFX_RenderDevice* pDevice,
diff --git a/core/fpdfdoc/cpdf_formfield.cpp b/core/fpdfdoc/cpdf_formfield.cpp
index 3a2213f1ae..cc7054dfaf 100644
--- a/core/fpdfdoc/cpdf_formfield.cpp
+++ b/core/fpdfdoc/cpdf_formfield.cpp
@@ -6,11 +6,14 @@
#include "core/fpdfdoc/cpdf_formfield.h"
+#include <memory>
#include <set>
+#include <utility>
#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_number.h"
#include "core/fpdfapi/parser/cpdf_simple_parser.h"
#include "core/fpdfapi/parser/cpdf_string.h"
@@ -223,11 +226,9 @@ bool CPDF_FormField::ResetField(bool bNotify) {
if (!pClone)
return false;
- m_pDict->SetFor("V", pClone.release());
- if (pRV) {
- std::unique_ptr<CPDF_Object> pCloneR = pDV->Clone();
- m_pDict->SetFor("RV", pCloneR.release());
- }
+ m_pDict->SetFor("V", std::move(pClone));
+ if (pRV)
+ m_pDict->SetFor("RV", pDV->Clone());
} else {
m_pDict->RemoveFor("V");
m_pDict->RemoveFor("RV");
@@ -361,15 +362,16 @@ bool CPDF_FormField::SetValue(const CFX_WideString& value,
if (bNotify && !NotifyBeforeValueChange(csValue))
return false;
+ CFX_ByteString key(bDefault ? "DV" : "V");
int iIndex = FindOptionValue(csValue);
if (iIndex < 0) {
CFX_ByteString bsEncodeText = PDF_EncodeText(csValue);
- m_pDict->SetStringFor(bDefault ? "DV" : "V", bsEncodeText);
+ m_pDict->SetNewFor<CPDF_String>(key, bsEncodeText, false);
if (m_Type == RichText && !bDefault)
- m_pDict->SetStringFor("RV", bsEncodeText);
+ m_pDict->SetNewFor<CPDF_String>("RV", bsEncodeText, false);
m_pDict->RemoveFor("I");
} else {
- m_pDict->SetStringFor(bDefault ? "DV" : "V", PDF_EncodeText(csValue));
+ m_pDict->SetNewFor<CPDF_String>(key, PDF_EncodeText(csValue), false);
if (!bDefault) {
ClearSelection();
SetItemSelection(iIndex, true);
@@ -549,22 +551,20 @@ bool CPDF_FormField::SetItemSelection(int index, bool bSelected, bool bNotify) {
if (GetType() == ListBox) {
SelectOption(index, true);
if (!(m_Flags & kFormListMultiSelect)) {
- m_pDict->SetStringFor("V", PDF_EncodeText(opt_value));
+ m_pDict->SetNewFor<CPDF_String>("V", PDF_EncodeText(opt_value), false);
} else {
- CPDF_Array* pArray = new CPDF_Array;
+ CPDF_Array* pArray = m_pDict->SetNewFor<CPDF_Array>("V");
for (int i = 0; i < CountOptions(); i++) {
if (i == index || IsItemSelected(i)) {
opt_value = GetOptionValue(i);
pArray->AddNew<CPDF_String>(PDF_EncodeText(opt_value), false);
}
}
- m_pDict->SetFor("V", pArray);
}
} else {
- m_pDict->SetStringFor("V", PDF_EncodeText(opt_value));
- CPDF_Array* pI = new CPDF_Array;
+ m_pDict->SetNewFor<CPDF_String>("V", PDF_EncodeText(opt_value), false);
+ CPDF_Array* pI = m_pDict->SetNewFor<CPDF_Array>("I");
pI->AddNew<CPDF_Number>(index);
- m_pDict->SetFor("I", pI);
}
} else {
CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V");
@@ -583,7 +583,7 @@ bool CPDF_FormField::SetItemSelection(int index, bool bSelected, bool bNotify) {
}
}
if (pArray->GetCount() > 0)
- m_pDict->SetFor("V", pArray.release()); // std::move someday
+ m_pDict->SetFor("V", std::move(pArray));
}
} else {
m_pDict->RemoveFor("V");
@@ -675,12 +675,9 @@ int CPDF_FormField::InsertOption(CFX_WideString csOptLabel,
CFX_ByteString csStr =
PDF_EncodeText(csOptLabel.c_str(), csOptLabel.GetLength());
- CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "Opt");
- CPDF_Array* pOpt = ToArray(pValue);
- if (!pOpt) {
- pOpt = new CPDF_Array;
- m_pDict->SetFor("Opt", pOpt);
- }
+ CPDF_Array* pOpt = ToArray(FPDF_GetFieldAttr(m_pDict, "Opt"));
+ if (!pOpt)
+ pOpt = m_pDict->SetNewFor<CPDF_Array>("Opt");
int iCount = pdfium::base::checked_cast<int>(pOpt->GetCount());
if (index >= iCount) {
@@ -755,19 +752,19 @@ bool CPDF_FormField::CheckControl(int iControlIndex,
CPDF_Object* pOpt = FPDF_GetFieldAttr(m_pDict, "Opt");
if (!ToArray(pOpt)) {
if (bChecked) {
- m_pDict->SetNameFor("V", csBExport);
+ m_pDict->SetNewFor<CPDF_Name>("V", csBExport);
} else {
CFX_ByteString csV;
CPDF_Object* pV = FPDF_GetFieldAttr(m_pDict, "V");
if (pV)
csV = pV->GetString();
if (csV == csBExport)
- m_pDict->SetNameFor("V", "Off");
+ m_pDict->SetNewFor<CPDF_Name>("V", "Off");
}
} else if (bChecked) {
CFX_ByteString csIndex;
csIndex.Format("%d", iControlIndex);
- m_pDict->SetNameFor("V", csIndex);
+ m_pDict->SetNewFor<CPDF_Name>("V", csIndex);
}
if (bNotify && m_pForm->m_pFormNotify)
m_pForm->m_pFormNotify->AfterCheckedStatusChange(this);
@@ -848,8 +845,7 @@ bool CPDF_FormField::SelectOption(int iOptIndex, bool bSelected, bool bNotify) {
if (!bSelected)
return true;
- pArray = new CPDF_Array;
- m_pDict->SetFor("I", pArray);
+ pArray = m_pDict->SetNewFor<CPDF_Array>("I");
}
bool bReturn = false;
diff --git a/core/fpdfdoc/cpdf_formfield_unittest.cpp b/core/fpdfdoc/cpdf_formfield_unittest.cpp
index f69df1d064..4aeda84c88 100644
--- a/core/fpdfdoc/cpdf_formfield_unittest.cpp
+++ b/core/fpdfdoc/cpdf_formfield_unittest.cpp
@@ -4,6 +4,8 @@
#include "core/fpdfapi/parser/cpdf_dictionary.h"
#include "core/fpdfapi/parser/cpdf_indirect_object_holder.h"
+#include "core/fpdfapi/parser/cpdf_name.h"
+#include "core/fpdfapi/parser/cpdf_reference.h"
#include "core/fpdfdoc/cpdf_formfield.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -13,29 +15,28 @@ TEST(cpdf_formfield, FPDF_GetFullName) {
CPDF_IndirectObjectHolder obj_holder;
CPDF_Dictionary* root = obj_holder.NewIndirect<CPDF_Dictionary>();
- root->SetNameFor("T", "foo");
+ root->SetNewFor<CPDF_Name>("T", "foo");
name = FPDF_GetFullName(root);
EXPECT_STREQ("foo", name.UTF8Encode().c_str());
CPDF_Dictionary* dict1 = obj_holder.NewIndirect<CPDF_Dictionary>();
- root->SetReferenceFor("Parent", &obj_holder, dict1);
- dict1->SetNameFor("T", "bar");
+ root->SetNewFor<CPDF_Reference>("Parent", &obj_holder, dict1->GetObjNum());
+ dict1->SetNewFor<CPDF_Name>("T", "bar");
name = FPDF_GetFullName(root);
EXPECT_STREQ("bar.foo", name.UTF8Encode().c_str());
- CPDF_Dictionary* dict2 = new CPDF_Dictionary();
- dict1->SetFor("Parent", dict2);
+ CPDF_Dictionary* dict2 = dict1->SetNewFor<CPDF_Dictionary>("Parent");
name = FPDF_GetFullName(root);
EXPECT_STREQ("bar.foo", name.UTF8Encode().c_str());
CPDF_Dictionary* dict3 = obj_holder.NewIndirect<CPDF_Dictionary>();
- dict2->SetReferenceFor("Parent", &obj_holder, dict3);
+ dict2->SetNewFor<CPDF_Reference>("Parent", &obj_holder, dict3->GetObjNum());
- dict3->SetNameFor("T", "qux");
+ dict3->SetNewFor<CPDF_Name>("T", "qux");
name = FPDF_GetFullName(root);
EXPECT_STREQ("qux.bar.foo", name.UTF8Encode().c_str());
- dict3->SetReferenceFor("Parent", &obj_holder, root->GetObjNum());
+ dict3->SetNewFor<CPDF_Reference>("Parent", &obj_holder, root->GetObjNum());
name = FPDF_GetFullName(root);
EXPECT_STREQ("qux.bar.foo", name.UTF8Encode().c_str());
name = FPDF_GetFullName(dict1);
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) {
diff --git a/core/fpdfdoc/cpvt_fontmap.cpp b/core/fpdfdoc/cpvt_fontmap.cpp
index a47595a6ac..283f60011b 100644
--- a/core/fpdfdoc/cpvt_fontmap.cpp
+++ b/core/fpdfdoc/cpvt_fontmap.cpp
@@ -9,6 +9,7 @@
#include "core/fpdfapi/font/cpdf_font.h"
#include "core/fpdfapi/parser/cpdf_dictionary.h"
#include "core/fpdfapi/parser/cpdf_document.h"
+#include "core/fpdfapi/parser/cpdf_reference.h"
#include "core/fpdfdoc/cpdf_interform.h"
CPVT_FontMap::CPVT_FontMap(CPDF_Document* pDoc,
@@ -39,8 +40,8 @@ void CPVT_FontMap::GetAnnotSysPDFFont(CPDF_Document* pDoc,
CPDF_Dictionary* pFontList = pResDict->GetDictFor("Font");
if (pFontList && !pFontList->KeyExist(sSysFontAlias)) {
- pFontList->SetReferenceFor(sSysFontAlias, pDoc,
- pPDFFont->GetFontDict()->GetObjNum());
+ pFontList->SetNewFor<CPDF_Reference>(sSysFontAlias, pDoc,
+ pPDFFont->GetFontDict()->GetObjNum());
}
pSysFont = pPDFFont;
}
diff --git a/core/fpdfdoc/cpvt_generateap.cpp b/core/fpdfdoc/cpvt_generateap.cpp
index 31d2242235..4bb244f29e 100644
--- a/core/fpdfdoc/cpvt_generateap.cpp
+++ b/core/fpdfdoc/cpvt_generateap.cpp
@@ -11,10 +11,15 @@
#include <utility>
#include "core/fpdfapi/font/cpdf_font.h"
+#include "core/fpdfapi/parser/cpdf_boolean.h"
#include "core/fpdfapi/parser/cpdf_dictionary.h"
#include "core/fpdfapi/parser/cpdf_document.h"
+#include "core/fpdfapi/parser/cpdf_name.h"
+#include "core/fpdfapi/parser/cpdf_number.h"
+#include "core/fpdfapi/parser/cpdf_reference.h"
#include "core/fpdfapi/parser/cpdf_simple_parser.h"
#include "core/fpdfapi/parser/cpdf_stream.h"
+#include "core/fpdfapi/parser/cpdf_string.h"
#include "core/fpdfapi/parser/fpdf_parser_decode.h"
#include "core/fpdfdoc/cpdf_annot.h"
#include "core/fpdfdoc/cpdf_formfield.h"
@@ -62,11 +67,12 @@ bool GenerateWidgetAP(CPDF_Document* pDoc,
CPDF_Dictionary* pFontDict = pDRFontDict->GetDictFor(sFontName.Mid(1));
if (!pFontDict) {
pFontDict = pDoc->NewIndirect<CPDF_Dictionary>();
- pFontDict->SetNameFor("Type", "Font");
- pFontDict->SetNameFor("Subtype", "Type1");
- pFontDict->SetNameFor("BaseFont", "Helvetica");
- pFontDict->SetNameFor("Encoding", "WinAnsiEncoding");
- pDRFontDict->SetReferenceFor(sFontName.Mid(1), pDoc, pFontDict);
+ pFontDict->SetNewFor<CPDF_Name>("Type", "Font");
+ pFontDict->SetNewFor<CPDF_Name>("Subtype", "Type1");
+ pFontDict->SetNewFor<CPDF_Name>("BaseFont", "Helvetica");
+ pFontDict->SetNewFor<CPDF_Name>("Encoding", "WinAnsiEncoding");
+ pDRFontDict->SetNewFor<CPDF_Reference>(sFontName.Mid(1), pDoc,
+ pFontDict->GetObjNum());
}
CPDF_Font* pDefFont = pDoc->LoadFont(pFontDict);
if (!pDefFont)
@@ -163,18 +169,15 @@ bool GenerateWidgetAP(CPDF_Document* pDoc,
CFX_FloatRect(rcBBox.left + fBorderWidth, rcBBox.bottom + fBorderWidth,
rcBBox.right - fBorderWidth, rcBBox.top - fBorderWidth);
rcBody.Normalize();
+
CPDF_Dictionary* pAPDict = pAnnotDict->GetDictFor("AP");
- if (!pAPDict) {
- auto pNewAPDict =
- pdfium::MakeUnique<CPDF_Dictionary>(pDoc->GetByteStringPool());
- // Ownership passes to |pAnnotDict|.
- pAPDict = pNewAPDict.release();
- pAnnotDict->SetFor("AP", pAPDict);
- }
+ if (!pAPDict)
+ pAPDict = pAnnotDict->SetNewFor<CPDF_Dictionary>("AP");
+
CPDF_Stream* pNormalStream = pAPDict->GetStreamFor("N");
if (!pNormalStream) {
pNormalStream = pDoc->NewIndirect<CPDF_Stream>();
- pAPDict->SetReferenceFor("N", pDoc, pNormalStream);
+ pAPDict->SetNewFor<CPDF_Reference>("N", pDoc, pNormalStream->GetObjNum());
}
CPDF_Dictionary* pStreamDict = pNormalStream->GetDict();
if (pStreamDict) {
@@ -183,18 +186,14 @@ bool GenerateWidgetAP(CPDF_Document* pDoc,
CPDF_Dictionary* pStreamResList = pStreamDict->GetDictFor("Resources");
if (pStreamResList) {
CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDictFor("Font");
- if (!pStreamResFontList) {
- auto pNewStreamResFontList =
- pdfium::MakeUnique<CPDF_Dictionary>(pDoc->GetByteStringPool());
- // Ownership passes to |pStreamResList|.
- pStreamResFontList = pNewStreamResFontList.release();
- pStreamResList->SetFor("Font", pStreamResFontList);
+ if (!pStreamResFontList)
+ pStreamResFontList = pStreamResList->SetNewFor<CPDF_Dictionary>("Font");
+ if (!pStreamResFontList->KeyExist(sFontName)) {
+ pStreamResFontList->SetNewFor<CPDF_Reference>(sFontName, pDoc,
+ pFontDict->GetObjNum());
}
- if (!pStreamResFontList->KeyExist(sFontName))
- pStreamResFontList->SetReferenceFor(sFontName, pDoc, pFontDict);
} else {
- pStreamDict->SetFor("Resources",
- pFormDict->GetDictFor("DR")->Clone().release());
+ pStreamDict->SetFor("Resources", pFormDict->GetDictFor("DR")->Clone());
pStreamResList = pStreamDict->GetDictFor("Resources");
}
}
@@ -438,17 +437,15 @@ bool GenerateWidgetAP(CPDF_Document* pDoc,
CPDF_Dictionary* pStreamResFontList =
pStreamResList->GetDictFor("Font");
if (!pStreamResFontList) {
- auto pNewStreamResFontList =
- pdfium::MakeUnique<CPDF_Dictionary>(pDoc->GetByteStringPool());
- // Ownership passes to |pStreamResList|.
- pStreamResFontList = pNewStreamResFontList.release();
- pStreamResList->SetFor("Font", pStreamResFontList);
+ pStreamResFontList =
+ pStreamResList->SetNewFor<CPDF_Dictionary>("Font");
+ }
+ if (!pStreamResFontList->KeyExist(sFontName)) {
+ pStreamResFontList->SetNewFor<CPDF_Reference>(sFontName, pDoc,
+ pFontDict->GetObjNum());
}
- if (!pStreamResFontList->KeyExist(sFontName))
- pStreamResFontList->SetReferenceFor(sFontName, pDoc, pFontDict);
} else {
- pStreamDict->SetFor("Resources",
- pFormDict->GetDictFor("DR")->Clone().release());
+ pStreamDict->SetFor("Resources", pFormDict->GetDictFor("DR")->Clone());
pStreamResList = pStreamDict->GetDictFor("Resources");
}
}
@@ -554,18 +551,18 @@ std::unique_ptr<CPDF_Dictionary> GenerateExtGStateDict(
const CFX_ByteString& sBlendMode) {
auto pGSDict =
pdfium::MakeUnique<CPDF_Dictionary>(pAnnotDict.GetByteStringPool());
- pGSDict->SetStringFor("Type", "ExtGState");
+ pGSDict->SetNewFor<CPDF_String>("Type", "ExtGState", false);
FX_FLOAT fOpacity =
pAnnotDict.KeyExist("CA") ? pAnnotDict.GetNumberFor("CA") : 1;
- pGSDict->SetNumberFor("CA", fOpacity);
- pGSDict->SetNumberFor("ca", fOpacity);
- pGSDict->SetBooleanFor("AIS", false);
- pGSDict->SetStringFor("BM", sBlendMode);
+ pGSDict->SetNewFor<CPDF_Number>("CA", fOpacity);
+ pGSDict->SetNewFor<CPDF_Number>("ca", fOpacity);
+ pGSDict->SetNewFor<CPDF_Boolean>("AIS", false);
+ pGSDict->SetNewFor<CPDF_String>("BM", sBlendMode, false);
auto pExtGStateDict =
pdfium::MakeUnique<CPDF_Dictionary>(pAnnotDict.GetByteStringPool());
- pExtGStateDict->SetFor(sExtGSDictName, pGSDict.release());
+ pExtGStateDict->SetFor(sExtGSDictName, std::move(pGSDict));
return pExtGStateDict;
}
@@ -573,14 +570,15 @@ std::unique_ptr<CPDF_Dictionary> GenerateResourceFontDict(
CPDF_Document* pDoc,
const CFX_ByteString& sFontDictName) {
CPDF_Dictionary* pFontDict = pDoc->NewIndirect<CPDF_Dictionary>();
- pFontDict->SetNameFor("Type", "Font");
- pFontDict->SetNameFor("Subtype", "Type1");
- pFontDict->SetNameFor("BaseFont", "Helvetica");
- pFontDict->SetNameFor("Encoding", "WinAnsiEncoding");
+ pFontDict->SetNewFor<CPDF_Name>("Type", "Font");
+ pFontDict->SetNewFor<CPDF_Name>("Subtype", "Type1");
+ pFontDict->SetNewFor<CPDF_Name>("BaseFont", "Helvetica");
+ pFontDict->SetNewFor<CPDF_Name>("Encoding", "WinAnsiEncoding");
auto pResourceFontDict =
pdfium::MakeUnique<CPDF_Dictionary>(pDoc->GetByteStringPool());
- pResourceFontDict->SetReferenceFor(sFontDictName, pDoc, pFontDict);
+ pResourceFontDict->SetNewFor<CPDF_Reference>(sFontDictName, pDoc,
+ pFontDict->GetObjNum());
return pResourceFontDict;
}
@@ -591,9 +589,9 @@ std::unique_ptr<CPDF_Dictionary> GenerateResourceDict(
auto pResourceDict =
pdfium::MakeUnique<CPDF_Dictionary>(pDoc->GetByteStringPool());
if (pExtGStateDict)
- pResourceDict->SetFor("ExtGState", pExtGStateDict.release());
+ pResourceDict->SetFor("ExtGState", std::move(pExtGStateDict));
if (pResourceFontDict)
- pResourceDict->SetFor("Font", pResourceFontDict.release());
+ pResourceDict->SetFor("Font", std::move(pResourceFontDict));
return pResourceDict;
}
@@ -605,20 +603,19 @@ void GenerateAndSetAPDict(CPDF_Document* pDoc,
CPDF_Stream* pNormalStream = pDoc->NewIndirect<CPDF_Stream>();
pNormalStream->SetData(sAppStream.GetBuffer(), sAppStream.GetSize());
- auto pAPDict = pdfium::MakeUnique<CPDF_Dictionary>(pDoc->GetByteStringPool());
- pAPDict->SetReferenceFor("N", pDoc, pNormalStream);
- pAnnotDict->SetFor("AP", pAPDict.release());
+ CPDF_Dictionary* pAPDict = pAnnotDict->SetNewFor<CPDF_Dictionary>("AP");
+ pAPDict->SetNewFor<CPDF_Reference>("N", pDoc, pNormalStream->GetObjNum());
CPDF_Dictionary* pStreamDict = pNormalStream->GetDict();
- pStreamDict->SetIntegerFor("FormType", 1);
- pStreamDict->SetStringFor("Subtype", "Form");
+ pStreamDict->SetNewFor<CPDF_Number>("FormType", 1);
+ pStreamDict->SetNewFor<CPDF_String>("Subtype", "Form", false);
pStreamDict->SetMatrixFor("Matrix", CFX_Matrix());
CFX_FloatRect rect = bIsTextMarkupAnnotation
? CPDF_Annot::RectFromQuadPoints(pAnnotDict)
: pAnnotDict->GetRectFor("Rect");
pStreamDict->SetRectFor("BBox", rect);
- pStreamDict->SetFor("Resources", pResourceDict.release());
+ pStreamDict->SetFor("Resources", std::move(pResourceDict));
}
CFX_ByteString GetPaintOperatorString(bool bIsStrokeRect, bool bIsFillRect) {
@@ -693,7 +690,6 @@ bool FPDF_GenerateAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict) {
CPDF_Object* pFieldFlagsObj = FPDF_GetFieldAttr(pAnnotDict, "Ff");
uint32_t flags = pFieldFlagsObj ? pFieldFlagsObj->GetInteger() : 0;
-
if (field_type == "Ch") {
return (flags & (1 << 17))
? CPVT_GenerateAP::GenerateComboBoxAP(pDoc, pAnnotDict)
@@ -705,7 +701,8 @@ bool FPDF_GenerateAP(CPDF_Document* pDoc, CPDF_Dictionary* pAnnotDict) {
if (!pAnnotDict->KeyExist("AS")) {
if (CPDF_Dictionary* pParentDict = pAnnotDict->GetDictFor("Parent")) {
if (pParentDict->KeyExist("AS")) {
- pAnnotDict->SetStringFor("AS", pParentDict->GetStringFor("AS"));
+ pAnnotDict->SetNewFor<CPDF_String>(
+ "AS", pParentDict->GetStringFor("AS"), false);
}
}
}