summaryrefslogtreecommitdiff
path: root/fpdfsdk
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2016-10-14 17:45:56 -0700
committerTom Sepez <tsepez@chromium.org>2016-10-14 17:45:56 -0700
commitc25a4219431c90a95233a08f25eecc921abbf3ed (patch)
treebd2ad923d527440785c19623fe2d19cc1a70a92d /fpdfsdk
parent62f367348ff8ff1e64c6f52c1ee5f77c3a89edc1 (diff)
downloadpdfium-c25a4219431c90a95233a08f25eecc921abbf3ed.tar.xz
Revert "Update CPDF_IndirectObjectHolder APIs for unique objects."
This reverts commit 3ba098595ae56b64eacc0c25ab76b89a4d78d920. TBR=thestig@chromium.org,weili@chromium.org Review URL: https://codereview.chromium.org/2424533003 .
Diffstat (limited to 'fpdfsdk')
-rw-r--r--fpdfsdk/cpdfsdk_baannot.cpp11
-rw-r--r--fpdfsdk/cpdfsdk_widget.cpp2
-rw-r--r--fpdfsdk/formfiller/cba_fontmap.cpp13
-rw-r--r--fpdfsdk/fpdf_flatten.cpp20
-rw-r--r--fpdfsdk/fpdf_transformpage.cpp29
-rw-r--r--fpdfsdk/fpdfdoc_unittest.cpp4
-rw-r--r--fpdfsdk/fpdfppo.cpp17
-rw-r--r--fpdfsdk/fpdfsave.cpp18
8 files changed, 62 insertions, 52 deletions
diff --git a/fpdfsdk/cpdfsdk_baannot.cpp b/fpdfsdk/cpdfsdk_baannot.cpp
index e704822e4d..72468e180f 100644
--- a/fpdfsdk/cpdfsdk_baannot.cpp
+++ b/fpdfsdk/cpdfsdk_baannot.cpp
@@ -316,9 +316,10 @@ void CPDFSDK_BAAnnot::WriteAppearance(const CFX_ByteString& sAPType,
}
if (!pStream) {
+ pStream = new CPDF_Stream;
CPDF_Document* pDoc = m_pPageView->GetPDFDocument();
- pStream = pDoc->AddIndirectStream();
- pParentDict->SetReferenceFor(sAPType, pDoc, pStream);
+ pParentDict->SetReferenceFor(sAPType, pDoc,
+ pDoc->AddIndirectObject(pStream));
}
CPDF_Dictionary* pStreamDict = pStream->GetDict();
@@ -353,10 +354,8 @@ void CPDFSDK_BAAnnot::SetAction(const CPDF_Action& action) {
CPDF_Dictionary* pDict = action.GetDict();
if (pDict != m_pAnnot->GetAnnotDict()->GetDictFor("A")) {
CPDF_Document* pDoc = m_pPageView->GetPDFDocument();
-
- // TODO(tsepez): check |pDict| ownership.
- m_pAnnot->GetAnnotDict()->SetReferenceFor(
- "A", pDoc, pDoc->AddIndirectObject(UniqueDictionary(pDict)));
+ m_pAnnot->GetAnnotDict()->SetReferenceFor("A", pDoc,
+ pDoc->AddIndirectObject(pDict));
}
}
diff --git a/fpdfsdk/cpdfsdk_widget.cpp b/fpdfsdk/cpdfsdk_widget.cpp
index 62bfcf7bd7..e1624a08b5 100644
--- a/fpdfsdk/cpdfsdk_widget.cpp
+++ b/fpdfsdk/cpdfsdk_widget.cpp
@@ -1811,7 +1811,7 @@ void CPDFSDK_Widget::AddImageToAppearance(const CFX_ByteString& sAPType,
}
CPDF_Dictionary* pXObject = new CPDF_Dictionary(pDoc->GetByteStringPool());
- pXObject->SetReferenceFor(sImageAlias, pDoc, pImage);
+ pXObject->SetReferenceFor(sImageAlias, pDoc, pImage->GetObjNum());
pStreamResList->SetFor("XObject", pXObject);
}
diff --git a/fpdfsdk/formfiller/cba_fontmap.cpp b/fpdfsdk/formfiller/cba_fontmap.cpp
index af518fe956..7178b902d0 100644
--- a/fpdfsdk/formfiller/cba_fontmap.cpp
+++ b/fpdfsdk/formfiller/cba_fontmap.cpp
@@ -166,8 +166,9 @@ void CBA_FontMap::AddFontToAnnotDict(CPDF_Font* pFont,
CPDF_Stream* pStream = pAPDict->GetStreamFor(m_sAPType);
if (!pStream) {
- pStream = m_pDocument->AddIndirectStream();
- pAPDict->SetReferenceFor(m_sAPType, m_pDocument, pStream);
+ pStream = new CPDF_Stream;
+ pAPDict->SetReferenceFor(m_sAPType, m_pDocument,
+ m_pDocument->AddIndirectObject(pStream));
}
CPDF_Dictionary* pStreamDict = pStream->GetDict();
@@ -185,12 +186,14 @@ void CBA_FontMap::AddFontToAnnotDict(CPDF_Font* pFont,
CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDictFor("Font");
if (!pStreamResFontList) {
pStreamResFontList =
- m_pDocument->AddIndirectDictionary(m_pDocument->GetByteStringPool());
- pStreamResList->SetReferenceFor("Font", m_pDocument, pStreamResFontList);
+ new CPDF_Dictionary(m_pDocument->GetByteStringPool());
+ pStreamResList->SetReferenceFor(
+ "Font", m_pDocument,
+ m_pDocument->AddIndirectObject(pStreamResFontList));
}
if (!pStreamResFontList->KeyExist(sAlias)) {
pStreamResFontList->SetReferenceFor(sAlias, m_pDocument,
- pFont->GetFontDict());
+ pFont->GetFontDict()->GetObjNum());
}
}
}
diff --git a/fpdfsdk/fpdf_flatten.cpp b/fpdfsdk/fpdf_flatten.cpp
index 3a1135130e..abfc69b092 100644
--- a/fpdfsdk/fpdf_flatten.cpp
+++ b/fpdfsdk/fpdf_flatten.cpp
@@ -186,12 +186,12 @@ CFX_FloatRect CalculateRect(CPDF_RectArray* pRectArray) {
uint32_t NewIndirectContentsStream(const CFX_ByteString& key,
CPDF_Document* pDocument) {
- CPDF_Stream* pNewContents = pDocument->AddIndirectStream(
+ CPDF_Stream* pNewContents = new CPDF_Stream(
nullptr, 0, new CPDF_Dictionary(pDocument->GetByteStringPool()));
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());
- return pNewContents->GetObjNum();
+ return pDocument->AddIndirectObject(pNewContents);
}
void SetPageContents(const CFX_ByteString& key,
@@ -211,15 +211,17 @@ void SetPageContents(const CFX_ByteString& key,
}
pPage->ConvertToIndirectObjectFor("Contents", pDocument);
if (!pContentsArray) {
- pContentsArray = pDocument->AddIndirectArray();
+ pContentsArray = new CPDF_Array;
CPDF_StreamAcc acc;
acc.LoadAllData(pContentsStream);
CFX_ByteString sStream = "q\n";
- CFX_ByteString sBody = CFX_ByteString(acc.GetData(), acc.GetSize());
+ CFX_ByteString sBody =
+ CFX_ByteString((const FX_CHAR*)acc.GetData(), acc.GetSize());
sStream = sStream + sBody + "\nQ";
pContentsStream->SetData(sStream.raw_str(), sStream.GetLength());
pContentsArray->AddReference(pDocument, pContentsStream->GetObjNum());
- pPage->SetReferenceFor("Contents", pDocument, pContentsArray);
+ pPage->SetReferenceFor("Contents", pDocument,
+ pDocument->AddIndirectObject(pContentsArray));
}
if (!key.IsEmpty()) {
pContentsArray->AddReference(pDocument,
@@ -316,10 +318,10 @@ DLLEXPORT int STDCALL FPDFPage_Flatten(FPDF_PAGE page, int nFlag) {
pPageDict->SetFor("Resources", pRes);
}
- CPDF_Stream* pNewXObject = pDocument->AddIndirectStream(
+ CPDF_Stream* pNewXObject = new CPDF_Stream(
nullptr, 0, new CPDF_Dictionary(pDocument->GetByteStringPool()));
- uint32_t dwObjNum = pNewXObject->GetObjNum();
+ uint32_t dwObjNum = pDocument->AddIndirectObject(pNewXObject);
CPDF_Dictionary* pPageXObject = pRes->GetDictFor("XObject");
if (!pPageXObject) {
pPageXObject = new CPDF_Dictionary(pDocument->GetByteStringPool());
@@ -424,10 +426,8 @@ DLLEXPORT int STDCALL FPDFPage_Flatten(FPDF_PAGE page, int nFlag) {
CFX_ByteString sFormName;
sFormName.Format("F%d", i);
-
- // TODO(tsepez): check |pObj| ownership.
pXObject->SetReferenceFor(sFormName, pDocument,
- pDocument->AddIndirectObject(UniqueObject(pObj)));
+ pDocument->AddIndirectObject(pObj));
CPDF_StreamAcc acc;
acc.LoadAllData(pNewXObject);
diff --git a/fpdfsdk/fpdf_transformpage.cpp b/fpdfsdk/fpdf_transformpage.cpp
index ce09da32a2..47b6cec9ea 100644
--- a/fpdfsdk/fpdf_transformpage.cpp
+++ b/fpdfsdk/fpdf_transformpage.cpp
@@ -129,13 +129,15 @@ DLLEXPORT FPDF_BOOL STDCALL FPDFPage_TransFormWithClip(FPDF_PAGE page,
if (!pDoc)
return FALSE;
- CPDF_Stream* pStream = pDoc->AddIndirectStream(
- nullptr, 0, new CPDF_Dictionary(pDoc->GetByteStringPool()));
+ CPDF_Dictionary* pDic = new CPDF_Dictionary(pDoc->GetByteStringPool());
+ CPDF_Stream* pStream = new CPDF_Stream(nullptr, 0, pDic);
pStream->SetData(textBuf.GetBuffer(), textBuf.GetSize());
+ pDoc->AddIndirectObject(pStream);
+ pDic = new CPDF_Dictionary(pDoc->GetByteStringPool());
- CPDF_Stream* pEndStream = pDoc->AddIndirectStream(
- nullptr, 0, new CPDF_Dictionary(pDoc->GetByteStringPool()));
+ CPDF_Stream* pEndStream = new CPDF_Stream(nullptr, 0, pDic);
pEndStream->SetData((const uint8_t*)" Q", 2);
+ pDoc->AddIndirectObject(pEndStream);
CPDF_Array* pContentArray = nullptr;
CPDF_Array* pArray = ToArray(pContentObj);
@@ -154,11 +156,12 @@ DLLEXPORT FPDF_BOOL STDCALL FPDFPage_TransFormWithClip(FPDF_PAGE page,
pContentArray->InsertAt(0, pRef);
pContentArray->AddReference(pDoc, pEndStream->GetObjNum());
} else if (pDirectObj->IsStream()) {
- pContentArray = pDoc->AddIndirectArray();
+ pContentArray = new CPDF_Array();
pContentArray->AddReference(pDoc, pStream->GetObjNum());
pContentArray->AddReference(pDoc, pDirectObj->GetObjNum());
pContentArray->AddReference(pDoc, pEndStream->GetObjNum());
- pPageDic->SetReferenceFor("Contents", pDoc, pContentArray);
+ pPageDic->SetReferenceFor("Contents", pDoc,
+ pDoc->AddIndirectObject(pContentArray));
}
}
}
@@ -302,9 +305,10 @@ DLLEXPORT void STDCALL FPDFPage_InsertClipPath(FPDF_PAGE page,
if (!pDoc)
return;
- CPDF_Stream* pStream = pDoc->AddIndirectStream(
- nullptr, 0, new CPDF_Dictionary(pDoc->GetByteStringPool()));
+ CPDF_Dictionary* pDic = new CPDF_Dictionary(pDoc->GetByteStringPool());
+ CPDF_Stream* pStream = new CPDF_Stream(nullptr, 0, pDic);
pStream->SetData(strClip.GetBuffer(), strClip.GetSize());
+ pDoc->AddIndirectObject(pStream);
CPDF_Array* pContentArray = nullptr;
CPDF_Array* pArray = ToArray(pContentObj);
@@ -321,10 +325,11 @@ DLLEXPORT void STDCALL FPDFPage_InsertClipPath(FPDF_PAGE page,
CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum());
pContentArray->InsertAt(0, pRef);
} else if (pDirectObj->IsStream()) {
- pContentArray = pDoc->AddIndirectArray();
- pContentArray->AddReference(pDoc, pStream);
- pContentArray->AddReference(pDoc, pDirectObj);
- pPageDic->SetReferenceFor("Contents", pDoc, pContentArray);
+ pContentArray = new CPDF_Array();
+ pContentArray->AddReference(pDoc, pStream->GetObjNum());
+ pContentArray->AddReference(pDoc, pDirectObj->GetObjNum());
+ pPageDic->SetReferenceFor("Contents", pDoc,
+ pDoc->AddIndirectObject(pContentArray));
}
}
}
diff --git a/fpdfsdk/fpdfdoc_unittest.cpp b/fpdfsdk/fpdfdoc_unittest.cpp
index 40457ee447..fc85404dba 100644
--- a/fpdfsdk/fpdfdoc_unittest.cpp
+++ b/fpdfsdk/fpdfdoc_unittest.cpp
@@ -80,8 +80,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 = m_pIndirectObjs->AddIndirectDictionary();
- 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 023c41a750..8a46ea4067 100644
--- a/fpdfsdk/fpdfppo.cpp
+++ b/fpdfsdk/fpdfppo.cpp
@@ -70,9 +70,9 @@ FX_BOOL CPDF_PageOrganizer::PDFDocInit(CPDF_Document* pDestPDFDoc,
CPDF_Dictionary* pNewPages =
pElement ? ToDictionary(pElement->GetDirect()) : nullptr;
if (!pNewPages) {
- pNewPages =
- pDestPDFDoc->AddIndirectDictionary(pDestPDFDoc->GetByteStringPool());
- pNewRoot->SetReferenceFor("Pages", pDestPDFDoc, pNewPages);
+ pNewPages = new CPDF_Dictionary(pDestPDFDoc->GetByteStringPool());
+ pNewRoot->SetReferenceFor("Pages", pDestPDFDoc,
+ pDestPDFDoc->AddIndirectObject(pNewPages));
}
CFX_ByteString cbPageType = pNewPages->GetStringFor("Type", "");
@@ -83,7 +83,7 @@ FX_BOOL CPDF_PageOrganizer::PDFDocInit(CPDF_Document* pDestPDFDoc,
if (!pNewPages->GetArrayFor("Kids")) {
pNewPages->SetIntegerFor("Count", 0);
pNewPages->SetReferenceFor("Kids", pDestPDFDoc,
- pDestPDFDoc->AddIndirectArray());
+ pDestPDFDoc->AddIndirectObject(new CPDF_Array));
}
return TRUE;
@@ -277,7 +277,7 @@ uint32_t CPDF_PageOrganizer::GetNewObjId(CPDF_Document* pDoc,
if (!pDirect)
return 0;
- UniqueObject pClone(pDirect->Clone());
+ CPDF_Object* pClone = pDirect->Clone();
if (!pClone)
return 0;
@@ -294,11 +294,10 @@ uint32_t CPDF_PageOrganizer::GetNewObjId(CPDF_Document* pDoc,
}
}
}
- CPDF_Object* pUnowned = pDoc->AddIndirectObject(std::move(pClone));
- dwNewObjNum = pUnowned->GetObjNum();
+ dwNewObjNum = pDoc->AddIndirectObject(pClone);
(*pObjNumberMap)[dwObjnum] = dwNewObjNum;
- if (!UpdateReference(pUnowned, pDoc, pObjNumberMap)) {
- pDoc->DeleteIndirectObject(dwNewObjNum);
+ if (!UpdateReference(pClone, pDoc, pObjNumberMap)) {
+ pClone->Release();
return 0;
}
return dwNewObjNum;
diff --git a/fpdfsdk/fpdfsave.cpp b/fpdfsdk/fpdfsave.cpp
index b594084218..364f4d2d6f 100644
--- a/fpdfsdk/fpdfsave.cpp
+++ b/fpdfsdk/fpdfsave.cpp
@@ -184,12 +184,14 @@ bool SaveXFADocumentData(CPDFXFA_Document* pDocument,
if (pDataSetsStream)
pDataSetsStream->InitStreamFromFile(pDsfileWrite.get(), pDataDict);
} else {
- CPDF_Stream* pData = pPDFDocument->AddIndirectStream();
+ CPDF_Stream* pData = new CPDF_Stream;
pData->InitStreamFromFile(pDsfileWrite.get(), pDataDict);
iLast = pArray->GetCount() - 2;
- pArray->InsertAt(iLast, new CPDF_String("datasets", false));
- pArray->InsertAt(iLast + 1,
- new CPDF_Reference(pPDFDocument, pData->GetObjNum()));
+ pArray->InsertAt(iLast, new CPDF_String("datasets", FALSE));
+ pArray->InsertAt(
+ iLast + 1,
+ new CPDF_Reference(pPDFDocument,
+ pPDFDocument->AddIndirectObject(pData)));
}
fileList->push_back(std::move(pDsfileWrite));
}
@@ -206,12 +208,14 @@ bool SaveXFADocumentData(CPDFXFA_Document* pDocument,
if (pFormStream)
pFormStream->InitStreamFromFile(pfileWrite.get(), pDataDict);
} else {
- CPDF_Stream* pData = pPDFDocument->AddIndirectStream();
+ CPDF_Stream* pData = new CPDF_Stream;
pData->InitStreamFromFile(pfileWrite.get(), pDataDict);
iLast = pArray->GetCount() - 2;
pArray->InsertAt(iLast, new CPDF_String("form", FALSE));
- pArray->InsertAt(iLast + 1,
- new CPDF_Reference(pPDFDocument, pData->GetObjNum()));
+ pArray->InsertAt(
+ iLast + 1,
+ new CPDF_Reference(pPDFDocument,
+ pPDFDocument->AddIndirectObject(pData)));
}
fileList->push_back(std::move(pfileWrite));
}