diff options
author | tsepez <tsepez@chromium.org> | 2016-09-21 19:10:19 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-09-21 19:10:19 -0700 |
commit | bb577af2f17467a55c04fbff21a8f0ec1016601a (patch) | |
tree | 5a5321b1aff1bcc6ee6dc19928aa729a4ddc9a3d /fpdfsdk | |
parent | 7149abce42b211ad3c0eaa39a340825acd41a1ec (diff) | |
download | pdfium-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 'fpdfsdk')
-rw-r--r-- | fpdfsdk/cpdfsdk_baannot.cpp | 15 | ||||
-rw-r--r-- | fpdfsdk/cpdfsdk_widget.cpp | 8 | ||||
-rw-r--r-- | fpdfsdk/formfiller/cba_fontmap.cpp | 27 | ||||
-rw-r--r-- | fpdfsdk/fpdf_flatten.cpp | 20 | ||||
-rw-r--r-- | fpdfsdk/fpdf_transformpage.cpp | 7 | ||||
-rw-r--r-- | fpdfsdk/fpdfdoc_unittest.cpp | 5 | ||||
-rw-r--r-- | fpdfsdk/fpdfppo.cpp | 15 | ||||
-rw-r--r-- | fpdfsdk/fpdfsave.cpp | 12 |
8 files changed, 50 insertions, 59 deletions
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)); } |