summaryrefslogtreecommitdiff
path: root/core/fpdfapi
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/fpdfapi
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/fpdfapi')
-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
7 files changed, 30 insertions, 43 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);