diff options
Diffstat (limited to 'fpdfsdk')
-rw-r--r-- | fpdfsdk/cpdfsdk_baannot.cpp | 11 | ||||
-rw-r--r-- | fpdfsdk/cpdfsdk_widget.cpp | 2 | ||||
-rw-r--r-- | fpdfsdk/formfiller/cba_fontmap.cpp | 13 | ||||
-rw-r--r-- | fpdfsdk/fpdf_flatten.cpp | 20 | ||||
-rw-r--r-- | fpdfsdk/fpdf_transformpage.cpp | 29 | ||||
-rw-r--r-- | fpdfsdk/fpdfdoc_unittest.cpp | 4 | ||||
-rw-r--r-- | fpdfsdk/fpdfppo.cpp | 17 | ||||
-rw-r--r-- | fpdfsdk/fpdfsave.cpp | 18 |
8 files changed, 52 insertions, 62 deletions
diff --git a/fpdfsdk/cpdfsdk_baannot.cpp b/fpdfsdk/cpdfsdk_baannot.cpp index 72468e180f..e704822e4d 100644 --- a/fpdfsdk/cpdfsdk_baannot.cpp +++ b/fpdfsdk/cpdfsdk_baannot.cpp @@ -316,10 +316,9 @@ void CPDFSDK_BAAnnot::WriteAppearance(const CFX_ByteString& sAPType, } if (!pStream) { - pStream = new CPDF_Stream; CPDF_Document* pDoc = m_pPageView->GetPDFDocument(); - pParentDict->SetReferenceFor(sAPType, pDoc, - pDoc->AddIndirectObject(pStream)); + pStream = pDoc->AddIndirectStream(); + pParentDict->SetReferenceFor(sAPType, pDoc, pStream); } CPDF_Dictionary* pStreamDict = pStream->GetDict(); @@ -354,8 +353,10 @@ 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(); - m_pAnnot->GetAnnotDict()->SetReferenceFor("A", pDoc, - pDoc->AddIndirectObject(pDict)); + + // TODO(tsepez): check |pDict| ownership. + m_pAnnot->GetAnnotDict()->SetReferenceFor( + "A", pDoc, pDoc->AddIndirectObject(UniqueDictionary(pDict))); } } diff --git a/fpdfsdk/cpdfsdk_widget.cpp b/fpdfsdk/cpdfsdk_widget.cpp index e1624a08b5..62bfcf7bd7 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->GetObjNum()); + pXObject->SetReferenceFor(sImageAlias, pDoc, pImage); pStreamResList->SetFor("XObject", pXObject); } diff --git a/fpdfsdk/formfiller/cba_fontmap.cpp b/fpdfsdk/formfiller/cba_fontmap.cpp index 7178b902d0..af518fe956 100644 --- a/fpdfsdk/formfiller/cba_fontmap.cpp +++ b/fpdfsdk/formfiller/cba_fontmap.cpp @@ -166,9 +166,8 @@ void CBA_FontMap::AddFontToAnnotDict(CPDF_Font* pFont, CPDF_Stream* pStream = pAPDict->GetStreamFor(m_sAPType); if (!pStream) { - pStream = new CPDF_Stream; - pAPDict->SetReferenceFor(m_sAPType, m_pDocument, - m_pDocument->AddIndirectObject(pStream)); + pStream = m_pDocument->AddIndirectStream(); + pAPDict->SetReferenceFor(m_sAPType, m_pDocument, pStream); } CPDF_Dictionary* pStreamDict = pStream->GetDict(); @@ -186,14 +185,12 @@ void CBA_FontMap::AddFontToAnnotDict(CPDF_Font* pFont, CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDictFor("Font"); if (!pStreamResFontList) { pStreamResFontList = - new CPDF_Dictionary(m_pDocument->GetByteStringPool()); - pStreamResList->SetReferenceFor( - "Font", m_pDocument, - m_pDocument->AddIndirectObject(pStreamResFontList)); + m_pDocument->AddIndirectDictionary(m_pDocument->GetByteStringPool()); + pStreamResList->SetReferenceFor("Font", m_pDocument, pStreamResFontList); } if (!pStreamResFontList->KeyExist(sAlias)) { pStreamResFontList->SetReferenceFor(sAlias, m_pDocument, - pFont->GetFontDict()->GetObjNum()); + pFont->GetFontDict()); } } } diff --git a/fpdfsdk/fpdf_flatten.cpp b/fpdfsdk/fpdf_flatten.cpp index abfc69b092..3a1135130e 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 = new CPDF_Stream( + CPDF_Stream* pNewContents = pDocument->AddIndirectStream( 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 pDocument->AddIndirectObject(pNewContents); + return pNewContents->GetObjNum(); } void SetPageContents(const CFX_ByteString& key, @@ -211,17 +211,15 @@ void SetPageContents(const CFX_ByteString& key, } pPage->ConvertToIndirectObjectFor("Contents", pDocument); if (!pContentsArray) { - pContentsArray = new CPDF_Array; + pContentsArray = pDocument->AddIndirectArray(); CPDF_StreamAcc acc; acc.LoadAllData(pContentsStream); CFX_ByteString sStream = "q\n"; - CFX_ByteString sBody = - CFX_ByteString((const FX_CHAR*)acc.GetData(), acc.GetSize()); + CFX_ByteString sBody = CFX_ByteString(acc.GetData(), acc.GetSize()); sStream = sStream + sBody + "\nQ"; pContentsStream->SetData(sStream.raw_str(), sStream.GetLength()); pContentsArray->AddReference(pDocument, pContentsStream->GetObjNum()); - pPage->SetReferenceFor("Contents", pDocument, - pDocument->AddIndirectObject(pContentsArray)); + pPage->SetReferenceFor("Contents", pDocument, pContentsArray); } if (!key.IsEmpty()) { pContentsArray->AddReference(pDocument, @@ -318,10 +316,10 @@ DLLEXPORT int STDCALL FPDFPage_Flatten(FPDF_PAGE page, int nFlag) { pPageDict->SetFor("Resources", pRes); } - CPDF_Stream* pNewXObject = new CPDF_Stream( + CPDF_Stream* pNewXObject = pDocument->AddIndirectStream( nullptr, 0, new CPDF_Dictionary(pDocument->GetByteStringPool())); - uint32_t dwObjNum = pDocument->AddIndirectObject(pNewXObject); + uint32_t dwObjNum = pNewXObject->GetObjNum(); CPDF_Dictionary* pPageXObject = pRes->GetDictFor("XObject"); if (!pPageXObject) { pPageXObject = new CPDF_Dictionary(pDocument->GetByteStringPool()); @@ -426,8 +424,10 @@ 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(pObj)); + pDocument->AddIndirectObject(UniqueObject(pObj))); CPDF_StreamAcc acc; acc.LoadAllData(pNewXObject); diff --git a/fpdfsdk/fpdf_transformpage.cpp b/fpdfsdk/fpdf_transformpage.cpp index 47b6cec9ea..ce09da32a2 100644 --- a/fpdfsdk/fpdf_transformpage.cpp +++ b/fpdfsdk/fpdf_transformpage.cpp @@ -129,15 +129,13 @@ DLLEXPORT FPDF_BOOL STDCALL FPDFPage_TransFormWithClip(FPDF_PAGE page, if (!pDoc) return FALSE; - CPDF_Dictionary* pDic = new CPDF_Dictionary(pDoc->GetByteStringPool()); - CPDF_Stream* pStream = new CPDF_Stream(nullptr, 0, pDic); + CPDF_Stream* pStream = pDoc->AddIndirectStream( + nullptr, 0, new CPDF_Dictionary(pDoc->GetByteStringPool())); pStream->SetData(textBuf.GetBuffer(), textBuf.GetSize()); - pDoc->AddIndirectObject(pStream); - pDic = new CPDF_Dictionary(pDoc->GetByteStringPool()); - CPDF_Stream* pEndStream = new CPDF_Stream(nullptr, 0, pDic); + CPDF_Stream* pEndStream = pDoc->AddIndirectStream( + nullptr, 0, new CPDF_Dictionary(pDoc->GetByteStringPool())); pEndStream->SetData((const uint8_t*)" Q", 2); - pDoc->AddIndirectObject(pEndStream); CPDF_Array* pContentArray = nullptr; CPDF_Array* pArray = ToArray(pContentObj); @@ -156,12 +154,11 @@ DLLEXPORT FPDF_BOOL STDCALL FPDFPage_TransFormWithClip(FPDF_PAGE page, pContentArray->InsertAt(0, pRef); pContentArray->AddReference(pDoc, pEndStream->GetObjNum()); } else if (pDirectObj->IsStream()) { - pContentArray = new CPDF_Array(); + pContentArray = pDoc->AddIndirectArray(); pContentArray->AddReference(pDoc, pStream->GetObjNum()); pContentArray->AddReference(pDoc, pDirectObj->GetObjNum()); pContentArray->AddReference(pDoc, pEndStream->GetObjNum()); - pPageDic->SetReferenceFor("Contents", pDoc, - pDoc->AddIndirectObject(pContentArray)); + pPageDic->SetReferenceFor("Contents", pDoc, pContentArray); } } } @@ -305,10 +302,9 @@ DLLEXPORT void STDCALL FPDFPage_InsertClipPath(FPDF_PAGE page, if (!pDoc) return; - CPDF_Dictionary* pDic = new CPDF_Dictionary(pDoc->GetByteStringPool()); - CPDF_Stream* pStream = new CPDF_Stream(nullptr, 0, pDic); + CPDF_Stream* pStream = pDoc->AddIndirectStream( + nullptr, 0, new CPDF_Dictionary(pDoc->GetByteStringPool())); pStream->SetData(strClip.GetBuffer(), strClip.GetSize()); - pDoc->AddIndirectObject(pStream); CPDF_Array* pContentArray = nullptr; CPDF_Array* pArray = ToArray(pContentObj); @@ -325,11 +321,10 @@ 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 = new CPDF_Array(); - pContentArray->AddReference(pDoc, pStream->GetObjNum()); - pContentArray->AddReference(pDoc, pDirectObj->GetObjNum()); - pPageDic->SetReferenceFor("Contents", pDoc, - pDoc->AddIndirectObject(pContentArray)); + pContentArray = pDoc->AddIndirectArray(); + pContentArray->AddReference(pDoc, pStream); + pContentArray->AddReference(pDoc, pDirectObj); + pPageDic->SetReferenceFor("Contents", pDoc, pContentArray); } } } diff --git a/fpdfsdk/fpdfdoc_unittest.cpp b/fpdfsdk/fpdfdoc_unittest.cpp index fc85404dba..40457ee447 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 = new CPDF_Dictionary(); - info.push_back({m_pIndirectObjs->AddIndirectObject(obj), obj}); + CPDF_Dictionary* obj = m_pIndirectObjs->AddIndirectDictionary(); + info.push_back({obj->GetObjNum(), obj}); } return info; } diff --git a/fpdfsdk/fpdfppo.cpp b/fpdfsdk/fpdfppo.cpp index 8a46ea4067..023c41a750 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 = new CPDF_Dictionary(pDestPDFDoc->GetByteStringPool()); - pNewRoot->SetReferenceFor("Pages", pDestPDFDoc, - pDestPDFDoc->AddIndirectObject(pNewPages)); + pNewPages = + pDestPDFDoc->AddIndirectDictionary(pDestPDFDoc->GetByteStringPool()); + pNewRoot->SetReferenceFor("Pages", pDestPDFDoc, 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->AddIndirectObject(new CPDF_Array)); + pDestPDFDoc->AddIndirectArray()); } return TRUE; @@ -277,7 +277,7 @@ uint32_t CPDF_PageOrganizer::GetNewObjId(CPDF_Document* pDoc, if (!pDirect) return 0; - CPDF_Object* pClone = pDirect->Clone(); + UniqueObject pClone(pDirect->Clone()); if (!pClone) return 0; @@ -294,10 +294,11 @@ uint32_t CPDF_PageOrganizer::GetNewObjId(CPDF_Document* pDoc, } } } - dwNewObjNum = pDoc->AddIndirectObject(pClone); + CPDF_Object* pUnowned = pDoc->AddIndirectObject(std::move(pClone)); + dwNewObjNum = pUnowned->GetObjNum(); (*pObjNumberMap)[dwObjnum] = dwNewObjNum; - if (!UpdateReference(pClone, pDoc, pObjNumberMap)) { - pClone->Release(); + if (!UpdateReference(pUnowned, pDoc, pObjNumberMap)) { + pDoc->DeleteIndirectObject(dwNewObjNum); return 0; } return dwNewObjNum; diff --git a/fpdfsdk/fpdfsave.cpp b/fpdfsdk/fpdfsave.cpp index 364f4d2d6f..b594084218 100644 --- a/fpdfsdk/fpdfsave.cpp +++ b/fpdfsdk/fpdfsave.cpp @@ -184,14 +184,12 @@ bool SaveXFADocumentData(CPDFXFA_Document* pDocument, if (pDataSetsStream) pDataSetsStream->InitStreamFromFile(pDsfileWrite.get(), pDataDict); } else { - CPDF_Stream* pData = new CPDF_Stream; + CPDF_Stream* pData = pPDFDocument->AddIndirectStream(); 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, - pPDFDocument->AddIndirectObject(pData))); + pArray->InsertAt(iLast, new CPDF_String("datasets", false)); + pArray->InsertAt(iLast + 1, + new CPDF_Reference(pPDFDocument, pData->GetObjNum())); } fileList->push_back(std::move(pDsfileWrite)); } @@ -208,14 +206,12 @@ bool SaveXFADocumentData(CPDFXFA_Document* pDocument, if (pFormStream) pFormStream->InitStreamFromFile(pfileWrite.get(), pDataDict); } else { - CPDF_Stream* pData = new CPDF_Stream; + CPDF_Stream* pData = pPDFDocument->AddIndirectStream(); 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, - pPDFDocument->AddIndirectObject(pData))); + pArray->InsertAt(iLast + 1, + new CPDF_Reference(pPDFDocument, pData->GetObjNum())); } fileList->push_back(std::move(pfileWrite)); } |