summaryrefslogtreecommitdiff
path: root/core/fpdfdoc
diff options
context:
space:
mode:
authortsepez <tsepez@chromium.org>2016-09-21 19:10:19 -0700
committerCommit bot <commit-bot@chromium.org>2016-09-21 19:10:19 -0700
commitbb577af2f17467a55c04fbff21a8f0ec1016601a (patch)
tree5a5321b1aff1bcc6ee6dc19928aa729a4ddc9a3d /core/fpdfdoc
parent7149abce42b211ad3c0eaa39a340825acd41a1ec (diff)
downloadpdfium-bb577af2f17467a55c04fbff21a8f0ec1016601a.tar.xz
Remove some objnum locals with AddIndirectObject
Also, it's idempotent, so simplify some logic in callers to not care if objnum is zero. The alternate forms are rarely used, using the objnum form makes it clear that SetReferenceFor() can't possibly register the object as a side-effect. Review-Url: https://codereview.chromium.org/2361713002
Diffstat (limited to 'core/fpdfdoc')
-rw-r--r--core/fpdfdoc/cpdf_formfield_unittest.cpp10
-rw-r--r--core/fpdfdoc/cpdf_interform.cpp8
-rw-r--r--core/fpdfdoc/cpvt_fontmap.cpp7
-rw-r--r--core/fpdfdoc/cpvt_generateap.cpp20
4 files changed, 23 insertions, 22 deletions
diff --git a/core/fpdfdoc/cpdf_formfield_unittest.cpp b/core/fpdfdoc/cpdf_formfield_unittest.cpp
index d6feff9718..34c70caad2 100644
--- a/core/fpdfdoc/cpdf_formfield_unittest.cpp
+++ b/core/fpdfdoc/cpdf_formfield_unittest.cpp
@@ -19,9 +19,9 @@ TEST(cpdf_formfield, FPDF_GetFullName) {
EXPECT_STREQ("foo", name.UTF8Encode().c_str());
CPDF_Dictionary* dict1 = new CPDF_Dictionary;
- obj_holder.AddIndirectObject(dict1);
+ root->SetReferenceFor("Parent", &obj_holder,
+ obj_holder.AddIndirectObject(dict1));
dict1->SetNameFor("T", "bar");
- root->SetReferenceFor("Parent", &obj_holder, dict1);
name = FPDF_GetFullName(root);
EXPECT_STREQ("bar.foo", name.UTF8Encode().c_str());
@@ -31,13 +31,13 @@ TEST(cpdf_formfield, FPDF_GetFullName) {
EXPECT_STREQ("bar.foo", name.UTF8Encode().c_str());
CPDF_Dictionary* dict3 = new CPDF_Dictionary;
- obj_holder.AddIndirectObject(dict3);
+ dict2->SetReferenceFor("Parent", &obj_holder,
+ obj_holder.AddIndirectObject(dict3));
dict3->SetNameFor("T", "qux");
- dict2->SetReferenceFor("Parent", &obj_holder, dict3);
name = FPDF_GetFullName(root);
EXPECT_STREQ("qux.bar.foo", name.UTF8Encode().c_str());
- dict3->SetReferenceFor("Parent", &obj_holder, root);
+ dict3->SetReferenceFor("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 e06af867bb..924084d4e2 100644
--- a/core/fpdfdoc/cpdf_interform.cpp
+++ b/core/fpdfdoc/cpdf_interform.cpp
@@ -59,9 +59,8 @@ void InitDict(CPDF_Dictionary*& pFormDict, CPDF_Document* pDocument) {
if (!pFormDict) {
pFormDict = new CPDF_Dictionary;
- uint32_t dwObjNum = pDocument->AddIndirectObject(pFormDict);
- CPDF_Dictionary* pRoot = pDocument->GetRoot();
- pRoot->SetReferenceFor("AcroForm", pDocument, dwObjNum);
+ pDocument->GetRoot()->SetReferenceFor(
+ "AcroForm", pDocument, pDocument->AddIndirectObject(pFormDict));
}
CFX_ByteString csDA;
@@ -406,7 +405,8 @@ void AddFont(CPDF_Dictionary*& pFormDict,
csNameTag.Remove(' ');
csNameTag = CPDF_InterForm::GenerateNewResourceName(pDR, "Font", 4,
csNameTag.c_str());
- pFonts->SetReferenceFor(csNameTag, pDocument, pFont->GetFontDict());
+ pFonts->SetReferenceFor(csNameTag, pDocument,
+ pFont->GetFontDict()->GetObjNum());
}
CPDF_Font* AddNativeFont(CPDF_Dictionary*& pFormDict,
diff --git a/core/fpdfdoc/cpvt_fontmap.cpp b/core/fpdfdoc/cpvt_fontmap.cpp
index 7eff694d81..eb209664fd 100644
--- a/core/fpdfdoc/cpvt_fontmap.cpp
+++ b/core/fpdfdoc/cpvt_fontmap.cpp
@@ -37,9 +37,10 @@ void CPVT_FontMap::GetAnnotSysPDFFont(CPDF_Document* pDoc,
if (!pPDFFont)
return;
- if (CPDF_Dictionary* pFontList = pResDict->GetDictFor("Font")) {
- if (!pFontList->KeyExist(sSysFontAlias))
- pFontList->SetReferenceFor(sSysFontAlias, pDoc, pPDFFont->GetFontDict());
+ CPDF_Dictionary* pFontList = pResDict->GetDictFor("Font");
+ if (pFontList && !pFontList->KeyExist(sSysFontAlias)) {
+ pFontList->SetReferenceFor(sSysFontAlias, pDoc,
+ pPDFFont->GetFontDict()->GetObjNum());
}
pSysFont = pPDFFont;
}
diff --git a/core/fpdfdoc/cpvt_generateap.cpp b/core/fpdfdoc/cpvt_generateap.cpp
index d7c8bec3a1..f7ece9bc35 100644
--- a/core/fpdfdoc/cpvt_generateap.cpp
+++ b/core/fpdfdoc/cpvt_generateap.cpp
@@ -63,8 +63,8 @@ bool GenerateWidgetAP(CPDF_Document* pDoc,
pFontDict->SetNameFor("Subtype", "Type1");
pFontDict->SetNameFor("BaseFont", "Helvetica");
pFontDict->SetNameFor("Encoding", "WinAnsiEncoding");
- pDoc->AddIndirectObject(pFontDict);
- pDRFontDict->SetReferenceFor(sFontName.Mid(1), pDoc, pFontDict);
+ pDRFontDict->SetReferenceFor(sFontName.Mid(1), pDoc,
+ pDoc->AddIndirectObject(pFontDict));
}
CPDF_Font* pDefFont = pDoc->LoadFont(pFontDict);
if (!pDefFont)
@@ -169,8 +169,7 @@ bool GenerateWidgetAP(CPDF_Document* pDoc,
CPDF_Stream* pNormalStream = pAPDict->GetStreamFor("N");
if (!pNormalStream) {
pNormalStream = new CPDF_Stream;
- int32_t objnum = pDoc->AddIndirectObject(pNormalStream);
- pAnnotDict->GetDictFor("AP")->SetReferenceFor("N", pDoc, objnum);
+ pAPDict->SetReferenceFor("N", pDoc, pDoc->AddIndirectObject(pNormalStream));
}
CPDF_Dictionary* pStreamDict = pNormalStream->GetDict();
if (pStreamDict) {
@@ -184,7 +183,8 @@ bool GenerateWidgetAP(CPDF_Document* pDoc,
pStreamResList->SetFor("Font", pStreamResFontList);
}
if (!pStreamResFontList->KeyExist(sFontName))
- pStreamResFontList->SetReferenceFor(sFontName, pDoc, pFontDict);
+ pStreamResFontList->SetReferenceFor(sFontName, pDoc,
+ pFontDict->GetObjNum());
} else {
pStreamDict->SetFor("Resources", pFormDict->GetDictFor("DR")->Clone());
pStreamResList = pStreamDict->GetDictFor("Resources");
@@ -434,7 +434,8 @@ bool GenerateWidgetAP(CPDF_Document* pDoc,
pStreamResList->SetFor("Font", pStreamResFontList);
}
if (!pStreamResFontList->KeyExist(sFontName))
- pStreamResFontList->SetReferenceFor(sFontName, pDoc, pFontDict);
+ pStreamResFontList->SetReferenceFor(sFontName, pDoc,
+ pFontDict->GetObjNum());
} else {
pStreamDict->SetFor("Resources", pFormDict->GetDictFor("DR")->Clone());
pStreamResList = pStreamDict->GetDictFor("Resources");
@@ -562,10 +563,10 @@ CPDF_Dictionary* GenerateResourceFontDict(CPDF_Document* pDoc,
pFontDict->SetNameFor("Subtype", "Type1");
pFontDict->SetNameFor("BaseFont", "Helvetica");
pFontDict->SetNameFor("Encoding", "WinAnsiEncoding");
- pDoc->AddIndirectObject(pFontDict);
CPDF_Dictionary* pResourceFontDict = new CPDF_Dictionary;
- pResourceFontDict->SetReferenceFor(sFontDictName, pDoc, pFontDict);
+ pResourceFontDict->SetReferenceFor(sFontDictName, pDoc,
+ pDoc->AddIndirectObject(pFontDict));
return pResourceFontDict;
}
@@ -593,9 +594,8 @@ void GenerateAndSetAPDict(CPDF_Document* pDoc,
pAnnotDict->SetFor("AP", pAPDict);
CPDF_Stream* pNormalStream = new CPDF_Stream;
- int32_t objnum = pDoc->AddIndirectObject(pNormalStream);
- pAnnotDict->GetDictFor("AP")->SetReferenceFor("N", pDoc, objnum);
pNormalStream->SetData(sAppStream.GetBuffer(), sAppStream.GetSize());
+ pAPDict->SetReferenceFor("N", pDoc, pDoc->AddIndirectObject(pNormalStream));
CPDF_Dictionary* pStreamDict = pNormalStream->GetDict();
pStreamDict->SetIntegerFor("FormType", 1);