summaryrefslogtreecommitdiff
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
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
-rw-r--r--core/fpdfapi/fpdf_edit/cpdf_pagecontentgenerator.cpp22
-rw-r--r--core/fpdfapi/fpdf_page/cpdf_image.cpp17
-rw-r--r--core/fpdfapi/fpdf_parser/cfdf_document.cpp3
-rw-r--r--core/fpdfapi/fpdf_parser/cpdf_document.cpp21
-rw-r--r--core/fpdfapi/fpdf_parser/cpdf_object_unittest.cpp2
-rw-r--r--core/fpdfapi/fpdf_parser/include/cpdf_array.h3
-rw-r--r--core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h5
-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
-rw-r--r--fpdfsdk/cpdfsdk_baannot.cpp15
-rw-r--r--fpdfsdk/cpdfsdk_widget.cpp8
-rw-r--r--fpdfsdk/formfiller/cba_fontmap.cpp27
-rw-r--r--fpdfsdk/fpdf_flatten.cpp20
-rw-r--r--fpdfsdk/fpdf_transformpage.cpp7
-rw-r--r--fpdfsdk/fpdfdoc_unittest.cpp5
-rw-r--r--fpdfsdk/fpdfppo.cpp15
-rw-r--r--fpdfsdk/fpdfsave.cpp12
19 files changed, 103 insertions, 124 deletions
diff --git a/core/fpdfapi/fpdf_edit/cpdf_pagecontentgenerator.cpp b/core/fpdfapi/fpdf_edit/cpdf_pagecontentgenerator.cpp
index 7acd368683..29c5940f5e 100644
--- a/core/fpdfapi/fpdf_edit/cpdf_pagecontentgenerator.cpp
+++ b/core/fpdfapi/fpdf_edit/cpdf_pagecontentgenerator.cpp
@@ -50,13 +50,13 @@ void CPDF_PageContentGenerator::GenerateContent() {
}
CPDF_Object* pContent =
pPageDict ? pPageDict->GetDirectObjectFor("Contents") : nullptr;
- if (pContent) {
+ if (pContent)
pPageDict->RemoveFor("Contents");
- }
+
CPDF_Stream* pStream = new CPDF_Stream;
pStream->SetData(buf.GetBuffer(), buf.GetLength());
- m_pDocument->AddIndirectObject(pStream);
- pPageDict->SetReferenceFor("Contents", m_pDocument, pStream->GetObjNum());
+ pPageDict->SetReferenceFor("Contents", m_pDocument,
+ m_pDocument->AddIndirectObject(pStream));
}
CFX_ByteString CPDF_PageContentGenerator::RealizeResource(
@@ -64,15 +64,15 @@ CFX_ByteString CPDF_PageContentGenerator::RealizeResource(
const CFX_ByteString& bsType) {
if (!m_pPage->m_pResources) {
m_pPage->m_pResources = new CPDF_Dictionary;
- int objnum = m_pDocument->AddIndirectObject(m_pPage->m_pResources);
- m_pPage->m_pFormDict->SetReferenceFor("Resources", m_pDocument, objnum);
+ m_pPage->m_pFormDict->SetReferenceFor(
+ "Resources", m_pDocument,
+ m_pDocument->AddIndirectObject(m_pPage->m_pResources));
}
CPDF_Dictionary* pResList = m_pPage->m_pResources->GetDictFor(bsType);
if (!pResList) {
pResList = new CPDF_Dictionary;
m_pPage->m_pResources->SetFor(bsType, pResList);
}
- m_pDocument->AddIndirectObject(pResourceObj);
CFX_ByteString name;
int idnum = 1;
while (1) {
@@ -82,7 +82,8 @@ CFX_ByteString CPDF_PageContentGenerator::RealizeResource(
}
idnum++;
}
- pResList->SetReferenceFor(name, m_pDocument, pResourceObj->GetObjNum());
+ pResList->SetReferenceFor(name, m_pDocument,
+ m_pDocument->AddIndirectObject(pResourceObj));
return name;
}
@@ -170,7 +171,6 @@ void CPDF_PageContentGenerator::TransformContent(CFX_Matrix& matrix) {
}
CPDF_Stream* pStream = new CPDF_Stream;
pStream->SetData(buf.GetBuffer(), buf.GetLength());
- m_pDocument->AddIndirectObject(pStream);
- m_pPage->m_pFormDict->SetReferenceFor("Contents", m_pDocument,
- pStream->GetObjNum());
+ m_pPage->m_pFormDict->SetReferenceFor(
+ "Contents", m_pDocument, m_pDocument->AddIndirectObject(pStream));
}
diff --git a/core/fpdfapi/fpdf_page/cpdf_image.cpp b/core/fpdfapi/fpdf_page/cpdf_image.cpp
index 32b69bf9cb..4112ad86ee 100644
--- a/core/fpdfapi/fpdf_page/cpdf_image.cpp
+++ b/core/fpdfapi/fpdf_page/cpdf_image.cpp
@@ -201,7 +201,6 @@ void CPDF_Image::SetImage(const CFX_DIBitmap* pBitmap, int32_t iCompress) {
int32_t iPalette = pBitmap->GetPaletteSize();
if (iPalette > 0) {
CPDF_Array* pCS = new CPDF_Array;
- m_pDocument->AddIndirectObject(pCS);
pCS->AddName("Indexed");
pCS->AddName("DeviceRGB");
pCS->AddInteger(iPalette - 1);
@@ -216,9 +215,9 @@ void CPDF_Image::SetImage(const CFX_DIBitmap* pBitmap, int32_t iCompress) {
}
CPDF_Stream* pCTS =
new CPDF_Stream(pColorTable, iPalette * 3, new CPDF_Dictionary);
- m_pDocument->AddIndirectObject(pCTS);
- pCS->AddReference(m_pDocument, pCTS);
- pDict->SetReferenceFor("ColorSpace", m_pDocument, pCS);
+ pCS->AddReference(m_pDocument, m_pDocument->AddIndirectObject(pCTS));
+ pDict->SetReferenceFor("ColorSpace", m_pDocument,
+ m_pDocument->AddIndirectObject(pCS));
} else {
pDict->SetNameFor("ColorSpace", "DeviceGray");
}
@@ -269,13 +268,11 @@ void CPDF_Image::SetImage(const CFX_DIBitmap* pBitmap, int32_t iCompress) {
}
}
pMaskDict->SetIntegerFor("Length", mask_size);
-
- CPDF_Stream* pMaskStream = new CPDF_Stream(mask_buf, mask_size, pMaskDict);
- m_pDocument->AddIndirectObject(pMaskStream);
- pDict->SetReferenceFor("SMask", m_pDocument, pMaskStream);
- if (bDeleteMask) {
+ pDict->SetReferenceFor("SMask", m_pDocument,
+ m_pDocument->AddIndirectObject(new CPDF_Stream(
+ mask_buf, mask_size, pMaskDict)));
+ if (bDeleteMask)
delete pMaskBitmap;
- }
}
if (opType == 0) {
if (iCompress & PDF_IMAGE_LOSSLESS_COMPRESS) {
diff --git a/core/fpdfapi/fpdf_parser/cfdf_document.cpp b/core/fpdfapi/fpdf_parser/cfdf_document.cpp
index 92b20cafd8..c602f634ad 100644
--- a/core/fpdfapi/fpdf_parser/cfdf_document.cpp
+++ b/core/fpdfapi/fpdf_parser/cfdf_document.cpp
@@ -25,8 +25,7 @@ CFDF_Document* CFDF_Document::CreateNewDoc() {
CFDF_Document* pDoc = new CFDF_Document;
pDoc->m_pRootDict = new CPDF_Dictionary;
pDoc->AddIndirectObject(pDoc->m_pRootDict);
- CPDF_Dictionary* pFDFDict = new CPDF_Dictionary;
- pDoc->m_pRootDict->SetFor("FDF", pFDFDict);
+ pDoc->m_pRootDict->SetFor("FDF", new CPDF_Dictionary);
return pDoc;
}
diff --git a/core/fpdfapi/fpdf_parser/cpdf_document.cpp b/core/fpdfapi/fpdf_parser/cpdf_document.cpp
index bd11ed26e6..1694566f1b 100644
--- a/core/fpdfapi/fpdf_parser/cpdf_document.cpp
+++ b/core/fpdfapi/fpdf_parser/cpdf_document.cpp
@@ -689,13 +689,12 @@ void CPDF_Document::CreateNewDoc() {
ASSERT(!m_pRootDict && !m_pInfoDict);
m_pRootDict = new CPDF_Dictionary;
m_pRootDict->SetNameFor("Type", "Catalog");
- int objnum = AddIndirectObject(m_pRootDict);
+ AddIndirectObject(m_pRootDict);
CPDF_Dictionary* pPages = new CPDF_Dictionary;
pPages->SetNameFor("Type", "Pages");
pPages->SetNumberFor("Count", 0);
pPages->SetFor("Kids", new CPDF_Array);
- objnum = AddIndirectObject(pPages);
- m_pRootDict->SetReferenceFor("Pages", this, objnum);
+ m_pRootDict->SetReferenceFor("Pages", this, AddIndirectObject(pPages));
m_pInfoDict = new CPDF_Dictionary;
AddIndirectObject(m_pInfoDict);
}
@@ -754,8 +753,9 @@ size_t CPDF_Document::CalculateEncodingDict(int charset,
pArray->AddName(name.IsEmpty() ? ".notdef" : name);
}
pEncodingDict->SetFor("Differences", pArray);
- AddIndirectObject(pEncodingDict);
- pBaseDict->SetReferenceFor("Encoding", this, pEncodingDict);
+ pBaseDict->SetReferenceFor("Encoding", this,
+ AddIndirectObject(pEncodingDict));
+
return i;
}
@@ -822,8 +822,7 @@ CPDF_Dictionary* CPDF_Document::ProcessbCJK(
pFontDict->SetFor("CIDSystemInfo", pCIDSysInfo);
CPDF_Array* pArray = new CPDF_Array;
pBaseDict->SetFor("DescendantFonts", pArray);
- AddIndirectObject(pFontDict);
- pArray->AddReference(this, pFontDict);
+ pArray->AddReference(this, AddIndirectObject(pFontDict));
return pFontDict;
}
@@ -910,8 +909,8 @@ CPDF_Font* CPDF_Document::AddFont(CFX_Font* pFont, int charset, FX_BOOL bVert) {
CPDF_Dictionary* pFontDesc =
CalculateFontDesc(basefont, flags, italicangle, pFont->GetAscent(),
pFont->GetDescent(), pBBox, nStemV);
- AddIndirectObject(pFontDesc);
- pFontDict->SetReferenceFor("FontDescriptor", this, pFontDesc);
+ pFontDict->SetReferenceFor("FontDescriptor", this,
+ AddIndirectObject(pFontDesc));
return LoadFont(pBaseDict);
}
@@ -1006,8 +1005,8 @@ CPDF_Font* CPDF_Document::AddWindowsFont(LOGFONTA* pLogFont,
CalculateFontDesc(basefont, flags, italicangle, ascend, descend, pBBox,
pLogFont->lfWeight / 5);
pFontDesc->SetIntegerFor("CapHeight", capheight);
- AddIndirectObject(pFontDesc);
- pFontDict->SetReferenceFor("FontDescriptor", this, pFontDesc);
+ pFontDict->SetReferenceFor("FontDescriptor", this,
+ AddIndirectObject(pFontDesc));
hFont = SelectObject(hDC, hFont);
DeleteObject(hFont);
DeleteDC(hDC);
diff --git a/core/fpdfapi/fpdf_parser/cpdf_object_unittest.cpp b/core/fpdfapi/fpdf_parser/cpdf_object_unittest.cpp
index cbfdf2b9ac..dad98cd28e 100644
--- a/core/fpdfapi/fpdf_parser/cpdf_object_unittest.cpp
+++ b/core/fpdfapi/fpdf_parser/cpdf_object_unittest.cpp
@@ -730,7 +730,7 @@ TEST(PDFArrayTest, AddReferenceAndGetObjectAt) {
holder->ReplaceIndirectObjectIfHigherGeneration(obj_nums[i],
indirect_objs[i]);
arr->AddReference(holder.get(), obj_nums[i]);
- arr1->AddReference(holder.get(), indirect_objs[i]);
+ arr1->AddReference(holder.get(), indirect_objs[i]->GetObjNum());
}
// Check indirect objects.
for (size_t i = 0; i < FX_ArraySize(obj_nums); ++i)
diff --git a/core/fpdfapi/fpdf_parser/include/cpdf_array.h b/core/fpdfapi/fpdf_parser/include/cpdf_array.h
index 1e8c612710..a63c40cddb 100644
--- a/core/fpdfapi/fpdf_parser/include/cpdf_array.h
+++ b/core/fpdfapi/fpdf_parser/include/cpdf_array.h
@@ -53,9 +53,6 @@ class CPDF_Array : public CPDF_Object {
void AddString(const CFX_ByteString& str);
void AddName(const CFX_ByteString& str);
void AddReference(CPDF_IndirectObjectHolder* pDoc, uint32_t objnum);
- void AddReference(CPDF_IndirectObjectHolder* pDoc, CPDF_Object* obj) {
- AddReference(pDoc, obj->GetObjNum());
- }
iterator begin() { return m_Objects.begin(); }
iterator end() { return m_Objects.end(); }
diff --git a/core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h b/core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h
index 784d49714f..fc69ce2f4b 100644
--- a/core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h
+++ b/core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h
@@ -63,11 +63,6 @@ class CPDF_Dictionary : public CPDF_Object {
void SetReferenceFor(const CFX_ByteString& key,
CPDF_IndirectObjectHolder* pDoc,
uint32_t objnum);
- void SetReferenceFor(const CFX_ByteString& key,
- CPDF_IndirectObjectHolder* pDoc,
- CPDF_Object* obj) {
- SetReferenceFor(key, pDoc, obj->GetObjNum());
- }
void SetRectFor(const CFX_ByteString& key, const CFX_FloatRect& rect);
void SetMatrixFor(const CFX_ByteString& key, const CFX_Matrix& matrix);
void SetBooleanFor(const CFX_ByteString& key, bool bValue);
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);
diff --git a/fpdfsdk/cpdfsdk_baannot.cpp b/fpdfsdk/cpdfsdk_baannot.cpp
index 2c63780772..836298f50d 100644
--- a/fpdfsdk/cpdfsdk_baannot.cpp
+++ b/fpdfsdk/cpdfsdk_baannot.cpp
@@ -322,8 +322,8 @@ void CPDFSDK_BAAnnot::WriteAppearance(const CFX_ByteString& sAPType,
if (!pStream) {
pStream = new CPDF_Stream;
CPDF_Document* pDoc = m_pPageView->GetPDFDocument();
- int32_t objnum = pDoc->AddIndirectObject(pStream);
- pParentDict->SetReferenceFor(sAPType, pDoc, objnum);
+ pParentDict->SetReferenceFor(sAPType, pDoc,
+ pDoc->AddIndirectObject(pStream));
}
CPDF_Dictionary* pStreamDict = pStream->GetDict();
@@ -354,14 +354,11 @@ CPDF_Action CPDFSDK_BAAnnot::GetAction() const {
}
void CPDFSDK_BAAnnot::SetAction(const CPDF_Action& action) {
- ASSERT(action.GetDict());
- if (action.GetDict() != m_pAnnot->GetAnnotDict()->GetDictFor("A")) {
+ CPDF_Dictionary* pDict = action.GetDict();
+ if (pDict != m_pAnnot->GetAnnotDict()->GetDictFor("A")) {
CPDF_Document* pDoc = m_pPageView->GetPDFDocument();
- CPDF_Dictionary* pDict = action.GetDict();
- if (pDict && pDict->GetObjNum() == 0) {
- pDoc->AddIndirectObject(pDict);
- }
- m_pAnnot->GetAnnotDict()->SetReferenceFor("A", pDoc, pDict->GetObjNum());
+ m_pAnnot->GetAnnotDict()->SetReferenceFor("A", pDoc,
+ pDoc->AddIndirectObject(pDict));
}
}
diff --git a/fpdfsdk/cpdfsdk_widget.cpp b/fpdfsdk/cpdfsdk_widget.cpp
index d4fc5c7900..cc2a767039 100644
--- a/fpdfsdk/cpdfsdk_widget.cpp
+++ b/fpdfsdk/cpdfsdk_widget.cpp
@@ -1835,11 +1835,9 @@ void CPDFSDK_Widget::AddImageToAppearance(const CFX_ByteString& sAPType,
pStreamDict->SetFor("Resources", pStreamResList);
}
- if (pStreamResList) {
- CPDF_Dictionary* pXObject = new CPDF_Dictionary;
- pXObject->SetReferenceFor(sImageAlias, pDoc, pImage);
- pStreamResList->SetFor("XObject", pXObject);
- }
+ CPDF_Dictionary* pXObject = new CPDF_Dictionary;
+ pXObject->SetReferenceFor(sImageAlias, pDoc, pImage->GetObjNum());
+ pStreamResList->SetFor("XObject", pXObject);
}
void CPDFSDK_Widget::RemoveAppearance(const CFX_ByteString& sAPType) {
diff --git a/fpdfsdk/formfiller/cba_fontmap.cpp b/fpdfsdk/formfiller/cba_fontmap.cpp
index fe690f23d5..04d6a72ec5 100644
--- a/fpdfsdk/formfiller/cba_fontmap.cpp
+++ b/fpdfsdk/formfiller/cba_fontmap.cpp
@@ -154,7 +154,6 @@ void CBA_FontMap::AddFontToAnnotDict(CPDF_Font* pFont,
return;
CPDF_Dictionary* pAPDict = m_pAnnotDict->GetDictFor("AP");
-
if (!pAPDict) {
pAPDict = new CPDF_Dictionary;
m_pAnnotDict->SetFor("AP", pAPDict);
@@ -168,12 +167,11 @@ void CBA_FontMap::AddFontToAnnotDict(CPDF_Font* pFont,
CPDF_Stream* pStream = pAPDict->GetStreamFor(m_sAPType);
if (!pStream) {
pStream = new CPDF_Stream;
- int32_t objnum = m_pDocument->AddIndirectObject(pStream);
- pAPDict->SetReferenceFor(m_sAPType, m_pDocument, objnum);
+ pAPDict->SetReferenceFor(m_sAPType, m_pDocument,
+ m_pDocument->AddIndirectObject(pStream));
}
CPDF_Dictionary* pStreamDict = pStream->GetDict();
-
if (!pStreamDict) {
pStreamDict = new CPDF_Dictionary;
pStream->InitStream(nullptr, 0, pStreamDict);
@@ -185,17 +183,16 @@ void CBA_FontMap::AddFontToAnnotDict(CPDF_Font* pFont,
pStreamResList = new CPDF_Dictionary();
pStreamDict->SetFor("Resources", pStreamResList);
}
-
- if (pStreamResList) {
- CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDictFor("Font");
- if (!pStreamResFontList) {
- pStreamResFontList = new CPDF_Dictionary;
- int32_t objnum = m_pDocument->AddIndirectObject(pStreamResFontList);
- pStreamResList->SetReferenceFor("Font", m_pDocument, objnum);
- }
- if (!pStreamResFontList->KeyExist(sAlias))
- pStreamResFontList->SetReferenceFor(sAlias, m_pDocument,
- pFont->GetFontDict());
+ CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDictFor("Font");
+ if (!pStreamResFontList) {
+ pStreamResFontList = new CPDF_Dictionary;
+ pStreamResList->SetReferenceFor(
+ "Font", m_pDocument,
+ m_pDocument->AddIndirectObject(pStreamResFontList));
+ }
+ if (!pStreamResFontList->KeyExist(sAlias)) {
+ pStreamResFontList->SetReferenceFor(sAlias, m_pDocument,
+ pFont->GetFontDict()->GetObjNum());
}
}
}
diff --git a/fpdfsdk/fpdf_flatten.cpp b/fpdfsdk/fpdf_flatten.cpp
index aa21b280ed..5ee485855b 100644
--- a/fpdfsdk/fpdf_flatten.cpp
+++ b/fpdfsdk/fpdf_flatten.cpp
@@ -195,12 +195,11 @@ void SetPageContents(CFX_ByteString key,
if (!key.IsEmpty()) {
CPDF_Stream* pNewContents =
new CPDF_Stream(nullptr, 0, new CPDF_Dictionary);
- pPage->SetReferenceFor("Contents", pDocument,
- pDocument->AddIndirectObject(pNewContents));
-
CFX_ByteString sStream;
sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str());
pNewContents->SetData(sStream.raw_str(), sStream.GetLength());
+ pPage->SetReferenceFor("Contents", pDocument,
+ pDocument->AddIndirectObject(pNewContents));
}
return;
}
@@ -234,18 +233,17 @@ void SetPageContents(CFX_ByteString key,
if (!pContentsArray)
return;
- uint32_t dwObjNum = pDocument->AddIndirectObject(pContentsArray);
- pPage->SetReferenceFor("Contents", pDocument, dwObjNum);
+ pPage->SetReferenceFor("Contents", pDocument,
+ pDocument->AddIndirectObject(pContentsArray));
if (!key.IsEmpty()) {
CPDF_Stream* pNewContents =
new CPDF_Stream(nullptr, 0, new CPDF_Dictionary);
- dwObjNum = pDocument->AddIndirectObject(pNewContents);
- pContentsArray->AddReference(pDocument, dwObjNum);
-
CFX_ByteString sStream;
sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str());
pNewContents->SetData(sStream.raw_str(), sStream.GetLength());
+ pContentsArray->AddReference(pDocument,
+ pDocument->AddIndirectObject(pNewContents));
}
}
@@ -482,15 +480,14 @@ DLLEXPORT int STDCALL FPDFPage_Flatten(FPDF_PAGE page, int nFlag) {
CFX_ByteString sFormName;
sFormName.Format("F%d", i);
- uint32_t dwStreamObjNum = pDocument->AddIndirectObject(pObj);
- pXObject->SetReferenceFor(sFormName, pDocument, dwStreamObjNum);
+ pXObject->SetReferenceFor(sFormName, pDocument,
+ pDocument->AddIndirectObject(pObj));
CPDF_StreamAcc acc;
acc.LoadAllData(pNewXObject);
const uint8_t* pData = acc.GetData();
CFX_ByteString sStream(pData, acc.GetSize());
- CFX_ByteString sTemp;
if (matrix.IsIdentity()) {
matrix.a = 1.0f;
@@ -501,6 +498,7 @@ DLLEXPORT int STDCALL FPDFPage_Flatten(FPDF_PAGE page, int nFlag) {
matrix.f = 0.0f;
}
+ CFX_ByteString sTemp;
CFX_Matrix m = GetMatrix(rcAnnot, rcStream, matrix);
sTemp.Format("q %f 0 0 %f %f %f cm /%s Do Q\n", m.a, m.d, m.e, m.f,
sFormName.c_str());
diff --git a/fpdfsdk/fpdf_transformpage.cpp b/fpdfsdk/fpdf_transformpage.cpp
index 204e49b695..68007d3ca5 100644
--- a/fpdfsdk/fpdf_transformpage.cpp
+++ b/fpdfsdk/fpdf_transformpage.cpp
@@ -144,7 +144,7 @@ DLLEXPORT FPDF_BOOL STDCALL FPDFPage_TransFormWithClip(FPDF_PAGE page,
pContentArray = pArray;
CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum());
pContentArray->InsertAt(0, pRef);
- pContentArray->AddReference(pDoc, pEndStream);
+ pContentArray->AddReference(pDoc, pEndStream->GetObjNum());
} else if (CPDF_Reference* pReference = ToReference(pContentObj)) {
CPDF_Object* pDirectObj = pReference->GetDirect();
if (pDirectObj) {
@@ -153,12 +153,12 @@ DLLEXPORT FPDF_BOOL STDCALL FPDFPage_TransFormWithClip(FPDF_PAGE page,
pContentArray = pObjArray;
CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum());
pContentArray->InsertAt(0, pRef);
- pContentArray->AddReference(pDoc, pEndStream);
+ pContentArray->AddReference(pDoc, pEndStream->GetObjNum());
} else if (pDirectObj->IsStream()) {
pContentArray = new CPDF_Array();
pContentArray->AddReference(pDoc, pStream->GetObjNum());
pContentArray->AddReference(pDoc, pDirectObj->GetObjNum());
- pContentArray->AddReference(pDoc, pEndStream);
+ pContentArray->AddReference(pDoc, pEndStream->GetObjNum());
pPageDic->SetReferenceFor("Contents", pDoc,
pDoc->AddIndirectObject(pContentArray));
}
@@ -306,6 +306,7 @@ DLLEXPORT void STDCALL FPDFPage_InsertClipPath(FPDF_PAGE page,
CPDF_Document* pDoc = pPage->m_pDocument;
if (!pDoc)
return;
+
pDoc->AddIndirectObject(pStream);
CPDF_Array* pContentArray = nullptr;
diff --git a/fpdfsdk/fpdfdoc_unittest.cpp b/fpdfsdk/fpdfdoc_unittest.cpp
index 5bda8da928..59f9e31e25 100644
--- a/fpdfsdk/fpdfdoc_unittest.cpp
+++ b/fpdfsdk/fpdfdoc_unittest.cpp
@@ -79,9 +79,8 @@ class PDFDocTest : public testing::Test {
std::vector<DictObjInfo> info;
for (int i = 0; i < num; ++i) {
// Objects created will be released by the document.
- CPDF_Dictionary* obj(new CPDF_Dictionary());
- m_pIndirectObjs->AddIndirectObject(obj);
- info.push_back({obj->GetObjNum(), obj});
+ CPDF_Dictionary* obj = new CPDF_Dictionary;
+ info.push_back({m_pIndirectObjs->AddIndirectObject(obj), obj});
}
return info;
}
diff --git a/fpdfsdk/fpdfppo.cpp b/fpdfsdk/fpdfppo.cpp
index 8ed8384c24..d901a61143 100644
--- a/fpdfsdk/fpdfppo.cpp
+++ b/fpdfsdk/fpdfppo.cpp
@@ -71,8 +71,8 @@ FX_BOOL CPDF_PageOrganizer::PDFDocInit(CPDF_Document* pDestPDFDoc,
pElement ? ToDictionary(pElement->GetDirect()) : nullptr;
if (!pNewPages) {
pNewPages = new CPDF_Dictionary;
- uint32_t NewPagesON = pDestPDFDoc->AddIndirectObject(pNewPages);
- pNewRoot->SetFor("Pages", new CPDF_Reference(pDestPDFDoc, NewPagesON));
+ pNewRoot->SetReferenceFor("Pages", pDestPDFDoc,
+ pDestPDFDoc->AddIndirectObject(pNewPages));
}
CFX_ByteString cbPageType = pNewPages->GetStringFor("Type", "");
@@ -80,13 +80,10 @@ FX_BOOL CPDF_PageOrganizer::PDFDocInit(CPDF_Document* pDestPDFDoc,
pNewPages->SetFor("Type", new CPDF_Name("Pages"));
}
- CPDF_Array* pKeysArray = pNewPages->GetArrayFor("Kids");
- if (!pKeysArray) {
- CPDF_Array* pNewKids = new CPDF_Array;
- uint32_t Kidsobjnum = pDestPDFDoc->AddIndirectObject(pNewKids);
-
- pNewPages->SetFor("Kids", new CPDF_Reference(pDestPDFDoc, Kidsobjnum));
- pNewPages->SetFor("Count", new CPDF_Number(0));
+ if (!pNewPages->GetArrayFor("Kids")) {
+ pNewPages->SetIntegerFor("Count", 0);
+ pNewPages->SetReferenceFor("Kids", pDestPDFDoc,
+ pDestPDFDoc->AddIndirectObject(new CPDF_Array));
}
return TRUE;
diff --git a/fpdfsdk/fpdfsave.cpp b/fpdfsdk/fpdfsave.cpp
index e5938b2542..8293c371dc 100644
--- a/fpdfsdk/fpdfsave.cpp
+++ b/fpdfsdk/fpdfsave.cpp
@@ -185,10 +185,12 @@ bool SaveXFADocumentData(CPDFXFA_Document* pDocument,
} else {
CPDF_Stream* pData = new CPDF_Stream;
pData->InitStreamFromFile(pDsfileWrite.get(), pDataDict);
- uint32_t objnum = pPDFDocument->AddIndirectObject(pData);
iLast = pArray->GetCount() - 2;
pArray->InsertAt(iLast, new CPDF_String("datasets", FALSE));
- pArray->InsertAt(iLast + 1, new CPDF_Reference(pPDFDocument, objnum));
+ pArray->InsertAt(
+ iLast + 1,
+ new CPDF_Reference(pPDFDocument,
+ pPDFDocument->AddIndirectObject(pData)));
}
fileList->push_back(std::move(pDsfileWrite));
}
@@ -206,10 +208,12 @@ bool SaveXFADocumentData(CPDFXFA_Document* pDocument,
} else {
CPDF_Stream* pData = new CPDF_Stream;
pData->InitStreamFromFile(pfileWrite.get(), pDataDict);
- uint32_t objnum = pPDFDocument->AddIndirectObject(pData);
iLast = pArray->GetCount() - 2;
pArray->InsertAt(iLast, new CPDF_String("form", FALSE));
- pArray->InsertAt(iLast + 1, new CPDF_Reference(pPDFDocument, objnum));
+ pArray->InsertAt(
+ iLast + 1,
+ new CPDF_Reference(pPDFDocument,
+ pPDFDocument->AddIndirectObject(pData)));
}
fileList->push_back(std::move(pfileWrite));
}