summaryrefslogtreecommitdiff
path: root/fpdfsdk
diff options
context:
space:
mode:
authortsepez <tsepez@chromium.org>2016-11-21 13:19:10 -0800
committerCommit bot <commit-bot@chromium.org>2016-11-21 13:19:10 -0800
commit9e05ee1e7bfb74d56d69620ad1e72b03e29b9237 (patch)
tree12b47b617d99edc7bd2715292402b74e864e1fa4 /fpdfsdk
parentaa3922dd713d480229408f3a0813b7dab9e8fd78 (diff)
downloadpdfium-9e05ee1e7bfb74d56d69620ad1e72b03e29b9237.tar.xz
Make CPDF_Stream() take unique_ptr's to its dictionary.
Review-Url: https://codereview.chromium.org/2520493002
Diffstat (limited to 'fpdfsdk')
-rw-r--r--fpdfsdk/cpdfsdk_baannot.cpp16
-rw-r--r--fpdfsdk/formfiller/cba_fontmap.cpp34
-rw-r--r--fpdfsdk/fpdf_flatten.cpp6
-rw-r--r--fpdfsdk/fpdf_transformpage.cpp16
-rw-r--r--fpdfsdk/fpdfsave.cpp24
5 files changed, 52 insertions, 44 deletions
diff --git a/fpdfsdk/cpdfsdk_baannot.cpp b/fpdfsdk/cpdfsdk_baannot.cpp
index 9fb1e88a84..3eedf1502c 100644
--- a/fpdfsdk/cpdfsdk_baannot.cpp
+++ b/fpdfsdk/cpdfsdk_baannot.cpp
@@ -7,6 +7,7 @@
#include "fpdfsdk/cpdfsdk_baannot.h"
#include <algorithm>
+#include <utility>
#include "core/fpdfapi/parser/cpdf_array.h"
#include "core/fpdfapi/parser/cpdf_document.h"
@@ -323,19 +324,16 @@ void CPDFSDK_BAAnnot::WriteAppearance(const CFX_ByteString& sAPType,
CPDF_Dictionary* pStreamDict = pStream->GetDict();
if (!pStreamDict) {
- pStreamDict =
- new CPDF_Dictionary(m_pAnnot->GetDocument()->GetByteStringPool());
+ auto pNewDict = pdfium::MakeUnique<CPDF_Dictionary>(
+ m_pAnnot->GetDocument()->GetByteStringPool());
+ pStreamDict = pNewDict.get();
pStreamDict->SetNewFor<CPDF_Name>("Type", "XObject");
pStreamDict->SetNewFor<CPDF_Name>("Subtype", "Form");
pStreamDict->SetNewFor<CPDF_Number>("FormType", 1);
- pStream->InitStream(nullptr, 0, pStreamDict);
+ pStream->InitStream(nullptr, 0, std::move(pNewDict));
}
-
- if (pStreamDict) {
- pStreamDict->SetMatrixFor("Matrix", matrix);
- pStreamDict->SetRectFor("BBox", rcBBox);
- }
-
+ pStreamDict->SetMatrixFor("Matrix", matrix);
+ pStreamDict->SetRectFor("BBox", rcBBox);
pStream->SetData((uint8_t*)sContents.c_str(), sContents.GetLength());
}
diff --git a/fpdfsdk/formfiller/cba_fontmap.cpp b/fpdfsdk/formfiller/cba_fontmap.cpp
index 83e45791e2..750b41627e 100644
--- a/fpdfsdk/formfiller/cba_fontmap.cpp
+++ b/fpdfsdk/formfiller/cba_fontmap.cpp
@@ -6,6 +6,8 @@
#include "fpdfsdk/formfiller/cba_fontmap.h"
+#include <utility>
+
#include "core/fpdfapi/font/cpdf_font.h"
#include "core/fpdfapi/page/cpdf_page.h"
#include "core/fpdfapi/parser/cpdf_document.h"
@@ -171,24 +173,24 @@ void CBA_FontMap::AddFontToAnnotDict(CPDF_Font* pFont,
CPDF_Dictionary* pStreamDict = pStream->GetDict();
if (!pStreamDict) {
- pStreamDict = new CPDF_Dictionary(m_pDocument->GetByteStringPool());
- pStream->InitStream(nullptr, 0, pStreamDict);
+ auto pOwnedDict =
+ pdfium::MakeUnique<CPDF_Dictionary>(m_pDocument->GetByteStringPool());
+ pStreamDict = pOwnedDict.get();
+ pStream->InitStream(nullptr, 0, std::move(pOwnedDict));
}
- if (pStreamDict) {
- CPDF_Dictionary* pStreamResList = pStreamDict->GetDictFor("Resources");
- if (!pStreamResList)
- pStreamResList = pStreamDict->SetNewFor<CPDF_Dictionary>("Resources");
- CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDictFor("Font");
- if (!pStreamResFontList) {
- pStreamResFontList = m_pDocument->NewIndirect<CPDF_Dictionary>();
- pStreamResList->SetNewFor<CPDF_Reference>(
- "Font", m_pDocument, pStreamResFontList->GetObjNum());
- }
- if (!pStreamResFontList->KeyExist(sAlias)) {
- pStreamResFontList->SetNewFor<CPDF_Reference>(
- sAlias, m_pDocument, pFont->GetFontDict()->GetObjNum());
- }
+ CPDF_Dictionary* pStreamResList = pStreamDict->GetDictFor("Resources");
+ if (!pStreamResList)
+ pStreamResList = pStreamDict->SetNewFor<CPDF_Dictionary>("Resources");
+ CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDictFor("Font");
+ if (!pStreamResFontList) {
+ pStreamResFontList = m_pDocument->NewIndirect<CPDF_Dictionary>();
+ pStreamResList->SetNewFor<CPDF_Reference>("Font", m_pDocument,
+ pStreamResFontList->GetObjNum());
+ }
+ if (!pStreamResFontList->KeyExist(sAlias)) {
+ pStreamResFontList->SetNewFor<CPDF_Reference>(
+ sAlias, m_pDocument, pFont->GetFontDict()->GetObjNum());
}
}
diff --git a/fpdfsdk/fpdf_flatten.cpp b/fpdfsdk/fpdf_flatten.cpp
index ccbb7b8765..e649bacf49 100644
--- a/fpdfsdk/fpdf_flatten.cpp
+++ b/fpdfsdk/fpdf_flatten.cpp
@@ -178,7 +178,8 @@ CFX_FloatRect CalculateRect(std::vector<CFX_FloatRect>* pRectArray) {
uint32_t NewIndirectContentsStream(const CFX_ByteString& key,
CPDF_Document* pDocument) {
CPDF_Stream* pNewContents = pDocument->NewIndirect<CPDF_Stream>(
- nullptr, 0, new CPDF_Dictionary(pDocument->GetByteStringPool()));
+ nullptr, 0,
+ pdfium::MakeUnique<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());
@@ -296,7 +297,8 @@ DLLEXPORT int STDCALL FPDFPage_Flatten(FPDF_PAGE page, int nFlag) {
pRes = pPageDict->SetNewFor<CPDF_Dictionary>("Resources");
CPDF_Stream* pNewXObject = pDocument->NewIndirect<CPDF_Stream>(
- nullptr, 0, new CPDF_Dictionary(pDocument->GetByteStringPool()));
+ nullptr, 0,
+ pdfium::MakeUnique<CPDF_Dictionary>(pDocument->GetByteStringPool()));
uint32_t dwObjNum = pNewXObject->GetObjNum();
CPDF_Dictionary* pPageXObject = pRes->GetDictFor("XObject");
diff --git a/fpdfsdk/fpdf_transformpage.cpp b/fpdfsdk/fpdf_transformpage.cpp
index b1e8da06b9..13d9756bd8 100644
--- a/fpdfsdk/fpdf_transformpage.cpp
+++ b/fpdfsdk/fpdf_transformpage.cpp
@@ -128,13 +128,14 @@ DLLEXPORT FPDF_BOOL STDCALL FPDFPage_TransFormWithClip(FPDF_PAGE page,
if (!pDoc)
return false;
- CPDF_Dictionary* pDic = new CPDF_Dictionary(pDoc->GetByteStringPool());
- CPDF_Stream* pStream = pDoc->NewIndirect<CPDF_Stream>(nullptr, 0, pDic);
+ CPDF_Stream* pStream = pDoc->NewIndirect<CPDF_Stream>(
+ nullptr, 0,
+ pdfium::MakeUnique<CPDF_Dictionary>(pDoc->GetByteStringPool()));
pStream->SetData(textBuf.GetBuffer(), textBuf.GetSize());
- pDic = new CPDF_Dictionary(pDoc->GetByteStringPool());
-
- CPDF_Stream* pEndStream = pDoc->NewIndirect<CPDF_Stream>(nullptr, 0, pDic);
+ CPDF_Stream* pEndStream = pDoc->NewIndirect<CPDF_Stream>(
+ nullptr, 0,
+ pdfium::MakeUnique<CPDF_Dictionary>(pDoc->GetByteStringPool()));
pEndStream->SetData((const uint8_t*)" Q", 2);
CPDF_Array* pContentArray = nullptr;
@@ -302,8 +303,9 @@ DLLEXPORT void STDCALL FPDFPage_InsertClipPath(FPDF_PAGE page,
if (!pDoc)
return;
- CPDF_Dictionary* pDic = new CPDF_Dictionary(pDoc->GetByteStringPool());
- CPDF_Stream* pStream = pDoc->NewIndirect<CPDF_Stream>(nullptr, 0, pDic);
+ CPDF_Stream* pStream = pDoc->NewIndirect<CPDF_Stream>(
+ nullptr, 0,
+ pdfium::MakeUnique<CPDF_Dictionary>(pDoc->GetByteStringPool()));
pStream->SetData(strClip.GetBuffer(), strClip.GetSize());
CPDF_Array* pArray = ToArray(pContentObj);
diff --git a/fpdfsdk/fpdfsave.cpp b/fpdfsdk/fpdfsave.cpp
index 89b8b5839e..cb01ab697b 100644
--- a/fpdfsdk/fpdfsave.cpp
+++ b/fpdfsdk/fpdfsave.cpp
@@ -176,14 +176,16 @@ bool SaveXFADocumentData(CPDFXFA_Context* pContext,
// Datasets
pChecksum->UpdateChecksum(pDsfileWrite.get());
pChecksum->FinishChecksum();
- CPDF_Dictionary* pDataDict =
- new CPDF_Dictionary(pPDFDocument->GetByteStringPool());
+ auto pDataDict = pdfium::MakeUnique<CPDF_Dictionary>(
+ pPDFDocument->GetByteStringPool());
if (iDataSetsIndex != -1) {
- if (pDataSetsStream)
- pDataSetsStream->InitStreamFromFile(pDsfileWrite.get(), pDataDict);
+ if (pDataSetsStream) {
+ pDataSetsStream->InitStreamFromFile(pDsfileWrite.get(),
+ std::move(pDataDict));
+ }
} else {
CPDF_Stream* pData = pPDFDocument->NewIndirect<CPDF_Stream>();
- pData->InitStreamFromFile(pDsfileWrite.get(), pDataDict);
+ pData->InitStreamFromFile(pDsfileWrite.get(), std::move(pDataDict));
iLast = pArray->GetCount() - 2;
pArray->InsertNewAt<CPDF_String>(iLast, "datasets", false);
pArray->InsertNewAt<CPDF_Reference>(iLast + 1, pPDFDocument,
@@ -198,14 +200,16 @@ bool SaveXFADocumentData(CPDFXFA_Context* pContext,
if (pXFADocView->GetDoc()->SavePackage(XFA_HASHCODE_Form, pfileWrite.get(),
pChecksum.get()) &&
pfileWrite->GetSize() > 0) {
- CPDF_Dictionary* pDataDict =
- new CPDF_Dictionary(pPDFDocument->GetByteStringPool());
+ auto pDataDict = pdfium::MakeUnique<CPDF_Dictionary>(
+ pPDFDocument->GetByteStringPool());
if (iFormIndex != -1) {
- if (pFormStream)
- pFormStream->InitStreamFromFile(pfileWrite.get(), pDataDict);
+ if (pFormStream) {
+ pFormStream->InitStreamFromFile(pfileWrite.get(),
+ std::move(pDataDict));
+ }
} else {
CPDF_Stream* pData = pPDFDocument->NewIndirect<CPDF_Stream>();
- pData->InitStreamFromFile(pfileWrite.get(), pDataDict);
+ pData->InitStreamFromFile(pfileWrite.get(), std::move(pDataDict));
iLast = pArray->GetCount() - 2;
pArray->InsertNewAt<CPDF_String>(iLast, "form", false);
pArray->InsertNewAt<CPDF_Reference>(iLast + 1, pPDFDocument,