summaryrefslogtreecommitdiff
path: root/core/fpdfdoc
diff options
context:
space:
mode:
authortsepez <tsepez@chromium.org>2016-11-15 11:33:44 -0800
committerCommit bot <commit-bot@chromium.org>2016-11-15 11:33:44 -0800
commit70c4afd5c3c5c44cd24f814423a23a6ef05bba02 (patch)
treecbe593d0b6c0bfc6fd5038bf60a77a94e49c69c9 /core/fpdfdoc
parentf16f6b8b52277348f5d571b7641bb0bbd5239589 (diff)
downloadpdfium-70c4afd5c3c5c44cd24f814423a23a6ef05bba02.tar.xz
Make AddIndirectObject() take a unique_ptr.
Add convenience routines to create and add object in one step. Review-Url: https://codereview.chromium.org/2489283003
Diffstat (limited to 'core/fpdfdoc')
-rw-r--r--core/fpdfdoc/cpdf_formfield_unittest.cpp14
-rw-r--r--core/fpdfdoc/cpdf_interform.cpp7
-rw-r--r--core/fpdfdoc/cpvt_generateap.cpp42
3 files changed, 26 insertions, 37 deletions
diff --git a/core/fpdfdoc/cpdf_formfield_unittest.cpp b/core/fpdfdoc/cpdf_formfield_unittest.cpp
index 11cccf19b8..f69df1d064 100644
--- a/core/fpdfdoc/cpdf_formfield_unittest.cpp
+++ b/core/fpdfdoc/cpdf_formfield_unittest.cpp
@@ -12,15 +12,13 @@ TEST(cpdf_formfield, FPDF_GetFullName) {
EXPECT_TRUE(name.IsEmpty());
CPDF_IndirectObjectHolder obj_holder;
- CPDF_Dictionary* root = new CPDF_Dictionary();
- obj_holder.AddIndirectObject(root);
+ CPDF_Dictionary* root = obj_holder.NewIndirect<CPDF_Dictionary>();
root->SetNameFor("T", "foo");
name = FPDF_GetFullName(root);
EXPECT_STREQ("foo", name.UTF8Encode().c_str());
- CPDF_Dictionary* dict1 = new CPDF_Dictionary();
- root->SetReferenceFor("Parent", &obj_holder,
- obj_holder.AddIndirectObject(dict1));
+ CPDF_Dictionary* dict1 = obj_holder.NewIndirect<CPDF_Dictionary>();
+ root->SetReferenceFor("Parent", &obj_holder, dict1);
dict1->SetNameFor("T", "bar");
name = FPDF_GetFullName(root);
EXPECT_STREQ("bar.foo", name.UTF8Encode().c_str());
@@ -30,9 +28,9 @@ TEST(cpdf_formfield, FPDF_GetFullName) {
name = FPDF_GetFullName(root);
EXPECT_STREQ("bar.foo", name.UTF8Encode().c_str());
- CPDF_Dictionary* dict3 = new CPDF_Dictionary();
- dict2->SetReferenceFor("Parent", &obj_holder,
- obj_holder.AddIndirectObject(dict3));
+ CPDF_Dictionary* dict3 = obj_holder.NewIndirect<CPDF_Dictionary>();
+ dict2->SetReferenceFor("Parent", &obj_holder, dict3);
+
dict3->SetNameFor("T", "qux");
name = FPDF_GetFullName(root);
EXPECT_STREQ("qux.bar.foo", name.UTF8Encode().c_str());
diff --git a/core/fpdfdoc/cpdf_interform.cpp b/core/fpdfdoc/cpdf_interform.cpp
index 2a02e890c3..64d15a0d88 100644
--- a/core/fpdfdoc/cpdf_interform.cpp
+++ b/core/fpdfdoc/cpdf_interform.cpp
@@ -59,9 +59,10 @@ void InitDict(CPDF_Dictionary*& pFormDict, CPDF_Document* pDocument) {
return;
if (!pFormDict) {
- pFormDict = new CPDF_Dictionary(pDocument->GetByteStringPool());
- pDocument->GetRoot()->SetReferenceFor(
- "AcroForm", pDocument, pDocument->AddIndirectObject(pFormDict));
+ pFormDict =
+ pDocument->NewIndirect<CPDF_Dictionary>(pDocument->GetByteStringPool());
+ pDocument->GetRoot()->SetReferenceFor("AcroForm", pDocument,
+ pFormDict->GetObjNum());
}
CFX_ByteString csDA;
diff --git a/core/fpdfdoc/cpvt_generateap.cpp b/core/fpdfdoc/cpvt_generateap.cpp
index 0802e907fd..c8bba64b1e 100644
--- a/core/fpdfdoc/cpvt_generateap.cpp
+++ b/core/fpdfdoc/cpvt_generateap.cpp
@@ -61,16 +61,12 @@ bool GenerateWidgetAP(CPDF_Document* pDoc,
CPDF_Dictionary* pFontDict = pDRFontDict->GetDictFor(sFontName.Mid(1));
if (!pFontDict) {
- auto pNewFontDict =
- pdfium::MakeUnique<CPDF_Dictionary>(pDoc->GetByteStringPool());
- pNewFontDict->SetNameFor("Type", "Font");
- pNewFontDict->SetNameFor("Subtype", "Type1");
- pNewFontDict->SetNameFor("BaseFont", "Helvetica");
- pNewFontDict->SetNameFor("Encoding", "WinAnsiEncoding");
- // Ownership passes to AddIndirectObject().
- pFontDict = pNewFontDict.release();
- pDRFontDict->SetReferenceFor(sFontName.Mid(1), pDoc,
- pDoc->AddIndirectObject(pFontDict));
+ pFontDict = pDoc->NewIndirect<CPDF_Dictionary>(pDoc->GetByteStringPool());
+ pFontDict->SetNameFor("Type", "Font");
+ pFontDict->SetNameFor("Subtype", "Type1");
+ pFontDict->SetNameFor("BaseFont", "Helvetica");
+ pFontDict->SetNameFor("Encoding", "WinAnsiEncoding");
+ pDRFontDict->SetReferenceFor(sFontName.Mid(1), pDoc, pFontDict);
}
CPDF_Font* pDefFont = pDoc->LoadFont(pFontDict);
if (!pDefFont)
@@ -177,10 +173,8 @@ bool GenerateWidgetAP(CPDF_Document* pDoc,
}
CPDF_Stream* pNormalStream = pAPDict->GetStreamFor("N");
if (!pNormalStream) {
- auto pNewNormalStream = pdfium::MakeUnique<CPDF_Stream>();
- // Ownership passes to AddIndirectObject().
- pNormalStream = pNewNormalStream.release();
- pAPDict->SetReferenceFor("N", pDoc, pDoc->AddIndirectObject(pNormalStream));
+ pNormalStream = pDoc->NewIndirect<CPDF_Stream>();
+ pAPDict->SetReferenceFor("N", pDoc, pNormalStream);
}
CPDF_Dictionary* pStreamDict = pNormalStream->GetDict();
if (pStreamDict) {
@@ -197,8 +191,7 @@ bool GenerateWidgetAP(CPDF_Document* pDoc,
pStreamResList->SetFor("Font", pStreamResFontList);
}
if (!pStreamResFontList->KeyExist(sFontName))
- pStreamResFontList->SetReferenceFor(sFontName, pDoc,
- pFontDict->GetObjNum());
+ pStreamResFontList->SetReferenceFor(sFontName, pDoc, pFontDict);
} else {
pStreamDict->SetFor("Resources",
pFormDict->GetDictFor("DR")->Clone().release());
@@ -452,8 +445,7 @@ bool GenerateWidgetAP(CPDF_Document* pDoc,
pStreamResList->SetFor("Font", pStreamResFontList);
}
if (!pStreamResFontList->KeyExist(sFontName))
- pStreamResFontList->SetReferenceFor(sFontName, pDoc,
- pFontDict->GetObjNum());
+ pStreamResFontList->SetReferenceFor(sFontName, pDoc, pFontDict);
} else {
pStreamDict->SetFor("Resources",
pFormDict->GetDictFor("DR")->Clone().release());
@@ -580,8 +572,8 @@ std::unique_ptr<CPDF_Dictionary> GenerateExtGStateDict(
std::unique_ptr<CPDF_Dictionary> GenerateResourceFontDict(
CPDF_Document* pDoc,
const CFX_ByteString& sFontDictName) {
- auto pFontDict =
- pdfium::MakeUnique<CPDF_Dictionary>(pDoc->GetByteStringPool());
+ CPDF_Dictionary* pFontDict =
+ pDoc->NewIndirect<CPDF_Dictionary>(pDoc->GetByteStringPool());
pFontDict->SetNameFor("Type", "Font");
pFontDict->SetNameFor("Subtype", "Type1");
pFontDict->SetNameFor("BaseFont", "Helvetica");
@@ -589,8 +581,7 @@ std::unique_ptr<CPDF_Dictionary> GenerateResourceFontDict(
auto pResourceFontDict =
pdfium::MakeUnique<CPDF_Dictionary>(pDoc->GetByteStringPool());
- pResourceFontDict->SetReferenceFor(
- sFontDictName, pDoc, pDoc->AddIndirectObject(pFontDict.release()));
+ pResourceFontDict->SetReferenceFor(sFontDictName, pDoc, pFontDict);
return pResourceFontDict;
}
@@ -612,15 +603,14 @@ void GenerateAndSetAPDict(CPDF_Document* pDoc,
const CFX_ByteTextBuf& sAppStream,
std::unique_ptr<CPDF_Dictionary> pResourceDict,
bool bIsTextMarkupAnnotation) {
- auto pNormalStream = pdfium::MakeUnique<CPDF_Stream>();
+ CPDF_Stream* pNormalStream = pDoc->NewIndirect<CPDF_Stream>();
pNormalStream->SetData(sAppStream.GetBuffer(), sAppStream.GetSize());
- CPDF_Dictionary* pStreamDict = pNormalStream->GetDict();
auto pAPDict = pdfium::MakeUnique<CPDF_Dictionary>(pDoc->GetByteStringPool());
- pAPDict->SetReferenceFor("N", pDoc,
- pDoc->AddIndirectObject(pNormalStream.release()));
+ pAPDict->SetReferenceFor("N", pDoc, pNormalStream);
pAnnotDict->SetFor("AP", pAPDict.release());
+ CPDF_Dictionary* pStreamDict = pNormalStream->GetDict();
pStreamDict->SetIntegerFor("FormType", 1);
pStreamDict->SetStringFor("Subtype", "Form");
pStreamDict->SetMatrixFor("Matrix", CFX_Matrix());