summaryrefslogtreecommitdiff
path: root/fpdfsdk
diff options
context:
space:
mode:
Diffstat (limited to 'fpdfsdk')
-rw-r--r--fpdfsdk/cpdfsdk_annothandlermgr.cpp7
-rw-r--r--fpdfsdk/cpdfsdk_baannot.cpp91
-rw-r--r--fpdfsdk/cpdfsdk_widget.cpp21
-rw-r--r--fpdfsdk/formfiller/cba_fontmap.cpp28
-rw-r--r--fpdfsdk/fpdf_flatten.cpp57
-rw-r--r--fpdfsdk/fpdf_transformpage.cpp11
-rw-r--r--fpdfsdk/fpdfdoc_unittest.cpp128
-rw-r--r--fpdfsdk/fpdfeditpage.cpp25
-rw-r--r--fpdfsdk/fpdfppo.cpp36
-rw-r--r--fpdfsdk/fpdfview.cpp2
-rw-r--r--fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp4
-rw-r--r--fpdfsdk/javascript/Document.cpp6
12 files changed, 205 insertions, 211 deletions
diff --git a/fpdfsdk/cpdfsdk_annothandlermgr.cpp b/fpdfsdk/cpdfsdk_annothandlermgr.cpp
index 51ce88e21f..898b9ccc0f 100644
--- a/fpdfsdk/cpdfsdk_annothandlermgr.cpp
+++ b/fpdfsdk/cpdfsdk_annothandlermgr.cpp
@@ -6,6 +6,8 @@
#include "fpdfsdk/cpdfsdk_annothandlermgr.h"
+#include "core/fpdfapi/parser/cpdf_number.h"
+#include "core/fpdfapi/parser/cpdf_string.h"
#include "core/fpdfdoc/cpdf_annot.h"
#include "fpdfsdk/cba_annotiterator.h"
#include "fpdfsdk/cpdfsdk_annot.h"
@@ -62,8 +64,9 @@ void CPDFSDK_AnnotHandlerMgr::Annot_OnCreate(CPDFSDK_Annot* pAnnot) {
CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot();
CPDFSDK_DateTime curTime;
- pPDFAnnot->GetAnnotDict()->SetStringFor("M", curTime.ToPDFDateTimeString());
- pPDFAnnot->GetAnnotDict()->SetNumberFor("F", 0);
+ pPDFAnnot->GetAnnotDict()->SetNewFor<CPDF_String>(
+ "M", curTime.ToPDFDateTimeString(), false);
+ pPDFAnnot->GetAnnotDict()->SetNewFor<CPDF_Number>("F", 0);
}
void CPDFSDK_AnnotHandlerMgr::Annot_OnLoad(CPDFSDK_Annot* pAnnot) {
diff --git a/fpdfsdk/cpdfsdk_baannot.cpp b/fpdfsdk/cpdfsdk_baannot.cpp
index ee4b55d290..9fb1e88a84 100644
--- a/fpdfsdk/cpdfsdk_baannot.cpp
+++ b/fpdfsdk/cpdfsdk_baannot.cpp
@@ -6,10 +6,15 @@
#include "fpdfsdk/cpdfsdk_baannot.h"
+#include <algorithm>
+
#include "core/fpdfapi/parser/cpdf_array.h"
#include "core/fpdfapi/parser/cpdf_document.h"
+#include "core/fpdfapi/parser/cpdf_name.h"
#include "core/fpdfapi/parser/cpdf_number.h"
+#include "core/fpdfapi/parser/cpdf_reference.h"
#include "core/fpdfapi/parser/cpdf_stream.h"
+#include "core/fpdfapi/parser/cpdf_string.h"
#include "core/fpdfapi/parser/fpdf_parser_decode.h"
#include "fpdfsdk/cpdfsdk_datetime.h"
#include "fpdfsdk/cpdfsdk_pageview.h"
@@ -89,11 +94,12 @@ void CPDFSDK_BAAnnot::ClearCachedAP() {
}
void CPDFSDK_BAAnnot::SetContents(const CFX_WideString& sContents) {
- if (sContents.IsEmpty())
+ if (sContents.IsEmpty()) {
m_pAnnot->GetAnnotDict()->RemoveFor("Contents");
- else
- m_pAnnot->GetAnnotDict()->SetStringFor("Contents",
- PDF_EncodeText(sContents));
+ } else {
+ m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_String>(
+ "Contents", PDF_EncodeText(sContents), false);
+ }
}
CFX_WideString CPDFSDK_BAAnnot::GetContents() const {
@@ -101,10 +107,12 @@ CFX_WideString CPDFSDK_BAAnnot::GetContents() const {
}
void CPDFSDK_BAAnnot::SetAnnotName(const CFX_WideString& sName) {
- if (sName.IsEmpty())
+ if (sName.IsEmpty()) {
m_pAnnot->GetAnnotDict()->RemoveFor("NM");
- else
- m_pAnnot->GetAnnotDict()->SetStringFor("NM", PDF_EncodeText(sName));
+ } else {
+ m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_String>(
+ "NM", PDF_EncodeText(sName), false);
+ }
}
CFX_WideString CPDFSDK_BAAnnot::GetAnnotName() const {
@@ -114,25 +122,23 @@ CFX_WideString CPDFSDK_BAAnnot::GetAnnotName() const {
void CPDFSDK_BAAnnot::SetModifiedDate(const FX_SYSTEMTIME& st) {
CPDFSDK_DateTime dt(st);
CFX_ByteString str = dt.ToPDFDateTimeString();
-
if (str.IsEmpty())
m_pAnnot->GetAnnotDict()->RemoveFor("M");
else
- m_pAnnot->GetAnnotDict()->SetStringFor("M", str);
+ m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_String>("M", str, false);
}
FX_SYSTEMTIME CPDFSDK_BAAnnot::GetModifiedDate() const {
FX_SYSTEMTIME systime;
CFX_ByteString str = m_pAnnot->GetAnnotDict()->GetStringFor("M");
-
CPDFSDK_DateTime dt(str);
dt.ToSystemTime(systime);
-
return systime;
}
void CPDFSDK_BAAnnot::SetFlags(uint32_t nFlags) {
- m_pAnnot->GetAnnotDict()->SetIntegerFor("F", nFlags);
+ m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_Number>("F",
+ static_cast<int>(nFlags));
}
uint32_t CPDFSDK_BAAnnot::GetFlags() const {
@@ -143,7 +149,7 @@ void CPDFSDK_BAAnnot::SetAppState(const CFX_ByteString& str) {
if (str.IsEmpty())
m_pAnnot->GetAnnotDict()->RemoveFor("AS");
else
- m_pAnnot->GetAnnotDict()->SetStringFor("AS", str);
+ m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_String>("AS", str, false);
}
CFX_ByteString CPDFSDK_BAAnnot::GetAppState() const {
@@ -151,7 +157,7 @@ CFX_ByteString CPDFSDK_BAAnnot::GetAppState() const {
}
void CPDFSDK_BAAnnot::SetStructParent(int key) {
- m_pAnnot->GetAnnotDict()->SetIntegerFor("StructParent", key);
+ m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_Number>("StructParent", key);
}
int CPDFSDK_BAAnnot::GetStructParent() const {
@@ -165,12 +171,10 @@ void CPDFSDK_BAAnnot::SetBorderWidth(int nWidth) {
pBorder->SetNewAt<CPDF_Number>(2, nWidth);
} else {
CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDictFor("BS");
- if (!pBSDict) {
- pBSDict =
- new CPDF_Dictionary(m_pAnnot->GetDocument()->GetByteStringPool());
- m_pAnnot->GetAnnotDict()->SetFor("BS", pBSDict);
- }
- pBSDict->SetIntegerFor("W", nWidth);
+ if (!pBSDict)
+ pBSDict = m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_Dictionary>("BS");
+
+ pBSDict->SetNewFor<CPDF_Number>("W", nWidth);
}
}
@@ -186,26 +190,24 @@ int CPDFSDK_BAAnnot::GetBorderWidth() const {
void CPDFSDK_BAAnnot::SetBorderStyle(BorderStyle nStyle) {
CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDictFor("BS");
- if (!pBSDict) {
- pBSDict = new CPDF_Dictionary(m_pAnnot->GetDocument()->GetByteStringPool());
- m_pAnnot->GetAnnotDict()->SetFor("BS", pBSDict);
- }
+ if (!pBSDict)
+ pBSDict = m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_Dictionary>("BS");
switch (nStyle) {
case BorderStyle::SOLID:
- pBSDict->SetNameFor("S", "S");
+ pBSDict->SetNewFor<CPDF_Name>("S", "S");
break;
case BorderStyle::DASH:
- pBSDict->SetNameFor("S", "D");
+ pBSDict->SetNewFor<CPDF_Name>("S", "D");
break;
case BorderStyle::BEVELED:
- pBSDict->SetNameFor("S", "B");
+ pBSDict->SetNewFor<CPDF_Name>("S", "B");
break;
case BorderStyle::INSET:
- pBSDict->SetNameFor("S", "I");
+ pBSDict->SetNewFor<CPDF_Name>("S", "I");
break;
case BorderStyle::UNDERLINE:
- pBSDict->SetNameFor("S", "U");
+ pBSDict->SetNewFor<CPDF_Name>("S", "U");
break;
default:
break;
@@ -241,14 +243,13 @@ BorderStyle CPDFSDK_BAAnnot::GetBorderStyle() const {
}
void CPDFSDK_BAAnnot::SetColor(FX_COLORREF color) {
- CPDF_Array* pArray = new CPDF_Array;
+ CPDF_Array* pArray = m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_Array>("C");
pArray->AddNew<CPDF_Number>(static_cast<FX_FLOAT>(FXSYS_GetRValue(color)) /
255.0f);
pArray->AddNew<CPDF_Number>(static_cast<FX_FLOAT>(FXSYS_GetGValue(color)) /
255.0f);
pArray->AddNew<CPDF_Number>(static_cast<FX_FLOAT>(FXSYS_GetBValue(color)) /
255.0f);
- m_pAnnot->GetAnnotDict()->SetFor("C", pArray);
}
void CPDFSDK_BAAnnot::RemoveColor() {
@@ -297,10 +298,8 @@ void CPDFSDK_BAAnnot::WriteAppearance(const CFX_ByteString& sAPType,
const CFX_ByteString& sContents,
const CFX_ByteString& sAPState) {
CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDictFor("AP");
- if (!pAPDict) {
- pAPDict = new CPDF_Dictionary(m_pAnnot->GetDocument()->GetByteStringPool());
- m_pAnnot->GetAnnotDict()->SetFor("AP", pAPDict);
- }
+ if (!pAPDict)
+ pAPDict = m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_Dictionary>("AP");
CPDF_Stream* pStream = nullptr;
CPDF_Dictionary* pParentDict = nullptr;
@@ -309,11 +308,9 @@ void CPDFSDK_BAAnnot::WriteAppearance(const CFX_ByteString& sAPType,
pStream = pAPDict->GetStreamFor(sAPType);
} else {
CPDF_Dictionary* pAPTypeDict = pAPDict->GetDictFor(sAPType);
- if (!pAPTypeDict) {
- pAPTypeDict =
- new CPDF_Dictionary(m_pAnnot->GetDocument()->GetByteStringPool());
- pAPDict->SetFor(sAPType, pAPTypeDict);
- }
+ if (!pAPTypeDict)
+ pAPTypeDict = pAPDict->SetNewFor<CPDF_Dictionary>(sAPType);
+
pParentDict = pAPTypeDict;
pStream = pAPTypeDict->GetStreamFor(sAPState);
}
@@ -321,16 +318,16 @@ void CPDFSDK_BAAnnot::WriteAppearance(const CFX_ByteString& sAPType,
if (!pStream) {
CPDF_Document* pDoc = m_pPageView->GetPDFDocument();
pStream = pDoc->NewIndirect<CPDF_Stream>();
- pParentDict->SetReferenceFor(sAPType, pDoc, pStream);
+ pParentDict->SetNewFor<CPDF_Reference>(sAPType, pDoc, pStream->GetObjNum());
}
CPDF_Dictionary* pStreamDict = pStream->GetDict();
if (!pStreamDict) {
pStreamDict =
new CPDF_Dictionary(m_pAnnot->GetDocument()->GetByteStringPool());
- pStreamDict->SetNameFor("Type", "XObject");
- pStreamDict->SetNameFor("Subtype", "Form");
- pStreamDict->SetIntegerFor("FormType", 1);
+ pStreamDict->SetNewFor<CPDF_Name>("Type", "XObject");
+ pStreamDict->SetNewFor<CPDF_Name>("Subtype", "Form");
+ pStreamDict->SetNewFor<CPDF_Number>("FormType", 1);
pStream->InitStream(nullptr, 0, pStreamDict);
}
@@ -358,7 +355,8 @@ void CPDFSDK_BAAnnot::SetAction(const CPDF_Action& action) {
CPDF_Document* pDoc = m_pPageView->GetPDFDocument();
if (pDict->IsInline())
pDict = pDoc->AddIndirectObject(pDict->Clone())->AsDictionary();
- m_pAnnot->GetAnnotDict()->SetReferenceFor("A", pDoc, pDict);
+ m_pAnnot->GetAnnotDict()->SetNewFor<CPDF_Reference>("A", pDoc,
+ pDict->GetObjNum());
}
}
@@ -372,7 +370,7 @@ CPDF_AAction CPDFSDK_BAAnnot::GetAAction() const {
void CPDFSDK_BAAnnot::SetAAction(const CPDF_AAction& aa) {
if (aa.GetDict() != m_pAnnot->GetAnnotDict()->GetDictFor("AA"))
- m_pAnnot->GetAnnotDict()->SetFor("AA", aa.GetDict());
+ m_pAnnot->GetAnnotDict()->SetFor("AA", pdfium::WrapUnique(aa.GetDict()));
}
void CPDFSDK_BAAnnot::RemoveAAction() {
@@ -381,7 +379,6 @@ void CPDFSDK_BAAnnot::RemoveAAction() {
CPDF_Action CPDFSDK_BAAnnot::GetAAction(CPDF_AAction::AActionType eAAT) {
CPDF_AAction AAction = GetAAction();
-
if (AAction.ActionExist(eAAT))
return AAction.GetAction(eAAT);
diff --git a/fpdfsdk/cpdfsdk_widget.cpp b/fpdfsdk/cpdfsdk_widget.cpp
index b1c3379ac9..108690665c 100644
--- a/fpdfsdk/cpdfsdk_widget.cpp
+++ b/fpdfsdk/cpdfsdk_widget.cpp
@@ -8,9 +8,12 @@
#include <memory>
+#include "core/fpdfapi/parser/cpdf_array.h"
#include "core/fpdfapi/parser/cpdf_dictionary.h"
#include "core/fpdfapi/parser/cpdf_document.h"
+#include "core/fpdfapi/parser/cpdf_reference.h"
#include "core/fpdfapi/parser/cpdf_stream.h"
+#include "core/fpdfapi/parser/cpdf_string.h"
#include "core/fpdfdoc/cpdf_defaultappearance.h"
#include "core/fpdfdoc/cpdf_formcontrol.h"
#include "core/fpdfdoc/cpdf_formfield.h"
@@ -966,21 +969,21 @@ void CPDFSDK_Widget::ResetAppearance_PushButton() {
if (pNormalIcon) {
if (CPDF_Dictionary* pImageDict = pNormalIcon->GetDict()) {
if (pImageDict->GetStringFor("Name").IsEmpty())
- pImageDict->SetStringFor("Name", "ImgA");
+ pImageDict->SetNewFor<CPDF_String>("Name", "ImgA", false);
}
}
if (pRolloverIcon) {
if (CPDF_Dictionary* pImageDict = pRolloverIcon->GetDict()) {
if (pImageDict->GetStringFor("Name").IsEmpty())
- pImageDict->SetStringFor("Name", "ImgB");
+ pImageDict->SetNewFor<CPDF_String>("Name", "ImgB", false);
}
}
if (pDownIcon) {
if (CPDF_Dictionary* pImageDict = pDownIcon->GetDict()) {
if (pImageDict->GetStringFor("Name").IsEmpty())
- pImageDict->SetStringFor("Name", "ImgC");
+ pImageDict->SetNewFor<CPDF_String>("Name", "ImgC", false);
}
}
@@ -1804,14 +1807,12 @@ void CPDFSDK_Widget::AddImageToAppearance(const CFX_ByteString& sAPType,
CPDF_Document* pDoc = m_pPageView->GetPDFDocument();
CPDF_Dictionary* pStreamResList = pStreamDict->GetDictFor("Resources");
- if (!pStreamResList) {
- pStreamResList = new CPDF_Dictionary(pDoc->GetByteStringPool());
- pStreamDict->SetFor("Resources", pStreamResList);
- }
+ if (!pStreamResList)
+ pStreamResList = pStreamDict->SetNewFor<CPDF_Dictionary>("Resources");
- CPDF_Dictionary* pXObject = new CPDF_Dictionary(pDoc->GetByteStringPool());
- pXObject->SetReferenceFor(sImageAlias, pDoc, pImage->GetObjNum());
- pStreamResList->SetFor("XObject", pXObject);
+ CPDF_Dictionary* pXObject =
+ pStreamResList->SetNewFor<CPDF_Dictionary>("XObject");
+ pXObject->SetNewFor<CPDF_Reference>(sImageAlias, pDoc, pImage->GetObjNum());
}
void CPDFSDK_Widget::RemoveAppearance(const CFX_ByteString& sAPType) {
diff --git a/fpdfsdk/formfiller/cba_fontmap.cpp b/fpdfsdk/formfiller/cba_fontmap.cpp
index fd9304befc..83e45791e2 100644
--- a/fpdfsdk/formfiller/cba_fontmap.cpp
+++ b/fpdfsdk/formfiller/cba_fontmap.cpp
@@ -9,6 +9,7 @@
#include "core/fpdfapi/font/cpdf_font.h"
#include "core/fpdfapi/page/cpdf_page.h"
#include "core/fpdfapi/parser/cpdf_document.h"
+#include "core/fpdfapi/parser/cpdf_reference.h"
#include "core/fpdfapi/parser/cpdf_simple_parser.h"
#include "core/fpdfapi/parser/cpdf_stream.h"
#include "core/fpdfapi/parser/fpdf_parser_decode.h"
@@ -119,11 +120,10 @@ CPDF_Font* CBA_FontMap::FindResFontSameCharset(CPDF_Dictionary* pResDict,
CPDF_Font* pFind = nullptr;
for (const auto& it : *pFonts) {
const CFX_ByteString& csKey = it.first;
- CPDF_Object* pObj = it.second;
- if (!pObj)
+ if (!it.second)
continue;
- CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect());
+ CPDF_Dictionary* pElement = ToDictionary(it.second->GetDirect());
if (!pElement)
continue;
if (pElement->GetStringFor("Type") != "Font")
@@ -154,10 +154,8 @@ void CBA_FontMap::AddFontToAnnotDict(CPDF_Font* pFont,
return;
CPDF_Dictionary* pAPDict = m_pAnnotDict->GetDictFor("AP");
- if (!pAPDict) {
- pAPDict = new CPDF_Dictionary(m_pDocument->GetByteStringPool());
- m_pAnnotDict->SetFor("AP", pAPDict);
- }
+ if (!pAPDict)
+ pAPDict = m_pAnnotDict->SetNewFor<CPDF_Dictionary>("AP");
// to avoid checkbox and radiobutton
CPDF_Object* pObject = pAPDict->GetObjectFor(m_sAPType);
@@ -167,7 +165,8 @@ void CBA_FontMap::AddFontToAnnotDict(CPDF_Font* pFont,
CPDF_Stream* pStream = pAPDict->GetStreamFor(m_sAPType);
if (!pStream) {
pStream = m_pDocument->NewIndirect<CPDF_Stream>();
- pAPDict->SetReferenceFor(m_sAPType, m_pDocument, pStream);
+ pAPDict->SetNewFor<CPDF_Reference>(m_sAPType, m_pDocument,
+ pStream->GetObjNum());
}
CPDF_Dictionary* pStreamDict = pStream->GetDict();
@@ -178,18 +177,17 @@ void CBA_FontMap::AddFontToAnnotDict(CPDF_Font* pFont,
if (pStreamDict) {
CPDF_Dictionary* pStreamResList = pStreamDict->GetDictFor("Resources");
- if (!pStreamResList) {
- pStreamResList = new CPDF_Dictionary(m_pDocument->GetByteStringPool());
- pStreamDict->SetFor("Resources", pStreamResList);
- }
+ if (!pStreamResList)
+ pStreamResList = pStreamDict->SetNewFor<CPDF_Dictionary>("Resources");
CPDF_Dictionary* pStreamResFontList = pStreamResList->GetDictFor("Font");
if (!pStreamResFontList) {
pStreamResFontList = m_pDocument->NewIndirect<CPDF_Dictionary>();
- pStreamResList->SetReferenceFor("Font", m_pDocument, pStreamResFontList);
+ pStreamResList->SetNewFor<CPDF_Reference>(
+ "Font", m_pDocument, pStreamResFontList->GetObjNum());
}
if (!pStreamResFontList->KeyExist(sAlias)) {
- pStreamResFontList->SetReferenceFor(sAlias, m_pDocument,
- pFont->GetFontDict()->GetObjNum());
+ pStreamResFontList->SetNewFor<CPDF_Reference>(
+ sAlias, m_pDocument, pFont->GetFontDict()->GetObjNum());
}
}
}
diff --git a/fpdfsdk/fpdf_flatten.cpp b/fpdfsdk/fpdf_flatten.cpp
index cb0a625e23..ccbb7b8765 100644
--- a/fpdfsdk/fpdf_flatten.cpp
+++ b/fpdfsdk/fpdf_flatten.cpp
@@ -7,11 +7,15 @@
#include "public/fpdf_flatten.h"
#include <algorithm>
+#include <memory>
+#include <utility>
+#include <vector>
#include "core/fpdfapi/page/cpdf_page.h"
#include "core/fpdfapi/page/cpdf_pageobject.h"
#include "core/fpdfapi/parser/cpdf_array.h"
#include "core/fpdfapi/parser/cpdf_document.h"
+#include "core/fpdfapi/parser/cpdf_name.h"
#include "core/fpdfapi/parser/cpdf_number.h"
#include "core/fpdfapi/parser/cpdf_reference.h"
#include "core/fpdfapi/parser/cpdf_stream.h"
@@ -190,8 +194,8 @@ void SetPageContents(const CFX_ByteString& key,
pContentsArray = pPage->GetArrayFor("Contents");
if (!pContentsArray) {
if (!key.IsEmpty()) {
- pPage->SetReferenceFor("Contents", pDocument,
- NewIndirectContentsStream(key, pDocument));
+ pPage->SetNewFor<CPDF_Reference>(
+ "Contents", pDocument, NewIndirectContentsStream(key, pDocument));
}
return;
}
@@ -208,7 +212,8 @@ void SetPageContents(const CFX_ByteString& key,
pContentsStream->SetData(sStream.raw_str(), sStream.GetLength());
pContentsArray->AddNew<CPDF_Reference>(pDocument,
pContentsStream->GetObjNum());
- pPage->SetReferenceFor("Contents", pDocument, pContentsArray);
+ pPage->SetNewFor<CPDF_Reference>("Contents", pDocument,
+ pContentsArray->GetObjNum());
}
if (!key.IsEmpty()) {
pContentsArray->AddNew<CPDF_Reference>(
@@ -271,38 +276,32 @@ DLLEXPORT int STDCALL FPDFPage_Flatten(FPDF_PAGE page, int nFlag) {
rcOriginalCB = rcOriginalMB;
if (!rcOriginalMB.IsEmpty()) {
- CPDF_Array* pMediaBox = new CPDF_Array();
+ CPDF_Array* pMediaBox = pPageDict->SetNewFor<CPDF_Array>("MediaBox");
pMediaBox->AddNew<CPDF_Number>(rcOriginalMB.left);
pMediaBox->AddNew<CPDF_Number>(rcOriginalMB.bottom);
pMediaBox->AddNew<CPDF_Number>(rcOriginalMB.right);
pMediaBox->AddNew<CPDF_Number>(rcOriginalMB.top);
- pPageDict->SetFor("MediaBox", pMediaBox);
}
if (!rcOriginalCB.IsEmpty()) {
- CPDF_Array* pCropBox = new CPDF_Array();
+ CPDF_Array* pCropBox = pPageDict->SetNewFor<CPDF_Array>("ArtBox");
pCropBox->AddNew<CPDF_Number>(rcOriginalCB.left);
pCropBox->AddNew<CPDF_Number>(rcOriginalCB.bottom);
pCropBox->AddNew<CPDF_Number>(rcOriginalCB.right);
pCropBox->AddNew<CPDF_Number>(rcOriginalCB.top);
- pPageDict->SetFor("ArtBox", pCropBox);
}
CPDF_Dictionary* pRes = pPageDict->GetDictFor("Resources");
- if (!pRes) {
- pRes = new CPDF_Dictionary(pDocument->GetByteStringPool());
- pPageDict->SetFor("Resources", pRes);
- }
+ if (!pRes)
+ pRes = pPageDict->SetNewFor<CPDF_Dictionary>("Resources");
CPDF_Stream* pNewXObject = pDocument->NewIndirect<CPDF_Stream>(
nullptr, 0, new CPDF_Dictionary(pDocument->GetByteStringPool()));
uint32_t dwObjNum = pNewXObject->GetObjNum();
CPDF_Dictionary* pPageXObject = pRes->GetDictFor("XObject");
- if (!pPageXObject) {
- pPageXObject = new CPDF_Dictionary(pDocument->GetByteStringPool());
- pRes->SetFor("XObject", pPageXObject);
- }
+ if (!pPageXObject)
+ pPageXObject = pRes->SetNewFor<CPDF_Dictionary>("XObject");
CFX_ByteString key = "";
int nStreams = pdfium::CollectionSize<int>(ObjectArray);
@@ -320,14 +319,13 @@ DLLEXPORT int STDCALL FPDFPage_Flatten(FPDF_PAGE page, int nFlag) {
CPDF_Dictionary* pNewXORes = nullptr;
if (!key.IsEmpty()) {
- pPageXObject->SetReferenceFor(key, pDocument, dwObjNum);
+ pPageXObject->SetNewFor<CPDF_Reference>(key, pDocument, dwObjNum);
CPDF_Dictionary* pNewOXbjectDic = pNewXObject->GetDict();
- pNewXORes = new CPDF_Dictionary(pDocument->GetByteStringPool());
- pNewOXbjectDic->SetFor("Resources", pNewXORes);
- pNewOXbjectDic->SetNameFor("Type", "XObject");
- pNewOXbjectDic->SetNameFor("Subtype", "Form");
- pNewOXbjectDic->SetIntegerFor("FormType", 1);
- pNewOXbjectDic->SetNameFor("Name", "FRM");
+ pNewXORes = pNewOXbjectDic->SetNewFor<CPDF_Dictionary>("Resources");
+ pNewOXbjectDic->SetNewFor<CPDF_Name>("Type", "XObject");
+ pNewOXbjectDic->SetNewFor<CPDF_Name>("Subtype", "Form");
+ pNewOXbjectDic->SetNewFor<CPDF_Number>("FormType", 1);
+ pNewOXbjectDic->SetNewFor<CPDF_Name>("Name", "FRM");
CFX_FloatRect rcBBox = pPageDict->GetRectFor("ArtBox");
pNewOXbjectDic->SetRectFor("BBox", rcBBox);
}
@@ -356,7 +354,7 @@ DLLEXPORT int STDCALL FPDFPage_Flatten(FPDF_PAGE page, int nFlag) {
} else {
auto it = pAPDic->begin();
if (it != pAPDic->end()) {
- CPDF_Object* pFirstObj = it->second;
+ CPDF_Object* pFirstObj = it->second.get();
if (pFirstObj) {
if (pFirstObj->IsReference())
pFirstObj = pFirstObj->GetDirect();
@@ -389,19 +387,18 @@ DLLEXPORT int STDCALL FPDFPage_Flatten(FPDF_PAGE page, int nFlag) {
CPDF_Dictionary* pObjDic = pObj->GetDict();
if (pObjDic) {
- pObjDic->SetNameFor("Type", "XObject");
- pObjDic->SetNameFor("Subtype", "Form");
+ pObjDic->SetNewFor<CPDF_Name>("Type", "XObject");
+ pObjDic->SetNewFor<CPDF_Name>("Subtype", "Form");
}
CPDF_Dictionary* pXObject = pNewXORes->GetDictFor("XObject");
- if (!pXObject) {
- pXObject = new CPDF_Dictionary(pDocument->GetByteStringPool());
- pNewXORes->SetFor("XObject", pXObject);
- }
+ if (!pXObject)
+ pXObject = pNewXORes->SetNewFor<CPDF_Dictionary>("XObject");
CFX_ByteString sFormName;
sFormName.Format("F%d", i);
- pXObject->SetReferenceFor(sFormName, pDocument, pObj->GetObjNum());
+ pXObject->SetNewFor<CPDF_Reference>(sFormName, pDocument,
+ pObj->GetObjNum());
CPDF_StreamAcc acc;
acc.LoadAllData(pNewXObject);
diff --git a/fpdfsdk/fpdf_transformpage.cpp b/fpdfsdk/fpdf_transformpage.cpp
index beaa6c4d98..b1e8da06b9 100644
--- a/fpdfsdk/fpdf_transformpage.cpp
+++ b/fpdfsdk/fpdf_transformpage.cpp
@@ -26,12 +26,11 @@ void SetBoundingBox(CPDF_Page* page,
float bottom,
float right,
float top) {
- CPDF_Array* pBoundingBoxArray = new CPDF_Array;
+ CPDF_Array* pBoundingBoxArray = page->m_pFormDict->SetNewFor<CPDF_Array>(key);
pBoundingBoxArray->AddNew<CPDF_Number>(left);
pBoundingBoxArray->AddNew<CPDF_Number>(bottom);
pBoundingBoxArray->AddNew<CPDF_Number>(right);
pBoundingBoxArray->AddNew<CPDF_Number>(top);
- page->m_pFormDict->SetFor(key, pBoundingBoxArray);
}
bool GetBoundingBox(CPDF_Page* page,
@@ -158,7 +157,8 @@ DLLEXPORT FPDF_BOOL STDCALL FPDFPage_TransFormWithClip(FPDF_PAGE page,
pContentArray->AddNew<CPDF_Reference>(pDoc, pStream->GetObjNum());
pContentArray->AddNew<CPDF_Reference>(pDoc, pDirectObj->GetObjNum());
pContentArray->AddNew<CPDF_Reference>(pDoc, pEndStream->GetObjNum());
- pPageDic->SetReferenceFor("Contents", pDoc, pContentArray);
+ pPageDic->SetNewFor<CPDF_Reference>("Contents", pDoc,
+ pContentArray->GetObjNum());
}
}
}
@@ -169,7 +169,7 @@ DLLEXPORT FPDF_BOOL STDCALL FPDFPage_TransFormWithClip(FPDF_PAGE page,
CPDF_Dictionary* pPattenDict = pRes->GetDictFor("Pattern");
if (pPattenDict) {
for (const auto& it : *pPattenDict) {
- CPDF_Object* pObj = it.second;
+ CPDF_Object* pObj = it.second.get();
if (pObj->IsReference())
pObj = pObj->GetDirect();
@@ -328,6 +328,7 @@ DLLEXPORT void STDCALL FPDFPage_InsertClipPath(FPDF_PAGE page,
CPDF_Array* pContentArray = pDoc->NewIndirect<CPDF_Array>();
pContentArray->AddNew<CPDF_Reference>(pDoc, pStream->GetObjNum());
pContentArray->AddNew<CPDF_Reference>(pDoc, pDirectObj->GetObjNum());
- pPageDic->SetReferenceFor("Contents", pDoc, pContentArray);
+ pPageDic->SetNewFor<CPDF_Reference>("Contents", pDoc,
+ pContentArray->GetObjNum());
}
}
diff --git a/fpdfsdk/fpdfdoc_unittest.cpp b/fpdfsdk/fpdfdoc_unittest.cpp
index d049b4e757..664ce39381 100644
--- a/fpdfsdk/fpdfdoc_unittest.cpp
+++ b/fpdfsdk/fpdfdoc_unittest.cpp
@@ -105,7 +105,7 @@ TEST_F(PDFDocTest, FindBookmark) {
}
{
// Empty bookmark tree.
- m_pRootObj->SetFor("Outlines", new CPDF_Dictionary());
+ m_pRootObj->SetNewFor<CPDF_Dictionary>("Outlines");
std::unique_ptr<unsigned short, pdfium::FreeDeleter> title =
GetFPDFWideString(L"");
EXPECT_EQ(nullptr, FPDFBookmark_Find(m_pDoc.get(), title.get()));
@@ -117,27 +117,27 @@ TEST_F(PDFDocTest, FindBookmark) {
// Check on a regular bookmark tree.
auto bookmarks = CreateDictObjs(3);
- bookmarks[1].obj->SetFor("Title", new CPDF_String(L"Chapter 1"));
- bookmarks[1].obj->SetFor(
- "Parent", new CPDF_Reference(m_pIndirectObjs, bookmarks[0].num));
- bookmarks[1].obj->SetFor(
- "Next", new CPDF_Reference(m_pIndirectObjs, bookmarks[2].num));
+ bookmarks[1].obj->SetNewFor<CPDF_String>("Title", L"Chapter 1");
+ bookmarks[1].obj->SetNewFor<CPDF_Reference>("Parent", m_pIndirectObjs,
+ bookmarks[0].num);
+ bookmarks[1].obj->SetNewFor<CPDF_Reference>("Next", m_pIndirectObjs,
+ bookmarks[2].num);
- bookmarks[2].obj->SetFor("Title", new CPDF_String(L"Chapter 2"));
- bookmarks[2].obj->SetFor(
- "Parent", new CPDF_Reference(m_pIndirectObjs, bookmarks[0].num));
- bookmarks[2].obj->SetFor(
- "Prev", new CPDF_Reference(m_pIndirectObjs, bookmarks[1].num));
+ bookmarks[2].obj->SetNewFor<CPDF_String>("Title", L"Chapter 2");
+ bookmarks[2].obj->SetNewFor<CPDF_Reference>("Parent", m_pIndirectObjs,
+ bookmarks[0].num);
+ bookmarks[2].obj->SetNewFor<CPDF_Reference>("Prev", m_pIndirectObjs,
+ bookmarks[1].num);
- bookmarks[0].obj->SetFor("Type", new CPDF_Name(nullptr, "Outlines"));
- bookmarks[0].obj->SetFor("Count", new CPDF_Number(2));
- bookmarks[0].obj->SetFor(
- "First", new CPDF_Reference(m_pIndirectObjs, bookmarks[1].num));
- bookmarks[0].obj->SetFor(
- "Last", new CPDF_Reference(m_pIndirectObjs, bookmarks[2].num));
+ bookmarks[0].obj->SetNewFor<CPDF_Name>("Type", "Outlines");
+ bookmarks[0].obj->SetNewFor<CPDF_Number>("Count", 2);
+ bookmarks[0].obj->SetNewFor<CPDF_Reference>("First", m_pIndirectObjs,
+ bookmarks[1].num);
+ bookmarks[0].obj->SetNewFor<CPDF_Reference>("Last", m_pIndirectObjs,
+ bookmarks[2].num);
- m_pRootObj->SetFor("Outlines",
- new CPDF_Reference(m_pIndirectObjs, bookmarks[0].num));
+ m_pRootObj->SetNewFor<CPDF_Reference>("Outlines", m_pIndirectObjs,
+ bookmarks[0].num);
// Title with no match.
std::unique_ptr<unsigned short, pdfium::FreeDeleter> title =
@@ -160,27 +160,27 @@ TEST_F(PDFDocTest, FindBookmark) {
// Circular bookmarks in depth.
auto bookmarks = CreateDictObjs(3);
- bookmarks[1].obj->SetFor("Title", new CPDF_String(L"Chapter 1"));
- bookmarks[1].obj->SetFor(
- "Parent", new CPDF_Reference(m_pIndirectObjs, bookmarks[0].num));
- bookmarks[1].obj->SetFor(
- "First", new CPDF_Reference(m_pIndirectObjs, bookmarks[2].num));
+ bookmarks[1].obj->SetNewFor<CPDF_String>("Title", L"Chapter 1");
+ bookmarks[1].obj->SetNewFor<CPDF_Reference>("Parent", m_pIndirectObjs,
+ bookmarks[0].num);
+ bookmarks[1].obj->SetNewFor<CPDF_Reference>("First", m_pIndirectObjs,
+ bookmarks[2].num);
- bookmarks[2].obj->SetFor("Title", new CPDF_String(L"Chapter 2"));
- bookmarks[2].obj->SetFor(
- "Parent", new CPDF_Reference(m_pIndirectObjs, bookmarks[1].num));
- bookmarks[2].obj->SetFor(
- "First", new CPDF_Reference(m_pIndirectObjs, bookmarks[1].num));
+ bookmarks[2].obj->SetNewFor<CPDF_String>("Title", L"Chapter 2");
+ bookmarks[2].obj->SetNewFor<CPDF_Reference>("Parent", m_pIndirectObjs,
+ bookmarks[1].num);
+ bookmarks[2].obj->SetNewFor<CPDF_Reference>("First", m_pIndirectObjs,
+ bookmarks[1].num);
- bookmarks[0].obj->SetFor("Type", new CPDF_Name(nullptr, "Outlines"));
- bookmarks[0].obj->SetFor("Count", new CPDF_Number(2));
- bookmarks[0].obj->SetFor(
- "First", new CPDF_Reference(m_pIndirectObjs, bookmarks[1].num));
- bookmarks[0].obj->SetFor(
- "Last", new CPDF_Reference(m_pIndirectObjs, bookmarks[2].num));
+ bookmarks[0].obj->SetNewFor<CPDF_Name>("Type", "Outlines");
+ bookmarks[0].obj->SetNewFor<CPDF_Number>("Count", 2);
+ bookmarks[0].obj->SetNewFor<CPDF_Reference>("First", m_pIndirectObjs,
+ bookmarks[1].num);
+ bookmarks[0].obj->SetNewFor<CPDF_Reference>("Last", m_pIndirectObjs,
+ bookmarks[2].num);
- m_pRootObj->SetFor("Outlines",
- new CPDF_Reference(m_pIndirectObjs, bookmarks[0].num));
+ m_pRootObj->SetNewFor<CPDF_Reference>("Outlines", m_pIndirectObjs,
+ bookmarks[0].num);
// Title with no match.
std::unique_ptr<unsigned short, pdfium::FreeDeleter> title =
@@ -195,33 +195,33 @@ TEST_F(PDFDocTest, FindBookmark) {
// Circular bookmarks in breadth.
auto bookmarks = CreateDictObjs(4);
- bookmarks[1].obj->SetFor("Title", new CPDF_String(L"Chapter 1"));
- bookmarks[1].obj->SetFor(
- "Parent", new CPDF_Reference(m_pIndirectObjs, bookmarks[0].num));
- bookmarks[1].obj->SetFor(
- "Next", new CPDF_Reference(m_pIndirectObjs, bookmarks[2].num));
-
- bookmarks[2].obj->SetFor("Title", new CPDF_String(L"Chapter 2"));
- bookmarks[2].obj->SetFor(
- "Parent", new CPDF_Reference(m_pIndirectObjs, bookmarks[0].num));
- bookmarks[2].obj->SetFor(
- "Next", new CPDF_Reference(m_pIndirectObjs, bookmarks[3].num));
-
- bookmarks[3].obj->SetFor("Title", new CPDF_String(L"Chapter 3"));
- bookmarks[3].obj->SetFor(
- "Parent", new CPDF_Reference(m_pIndirectObjs, bookmarks[0].num));
- bookmarks[3].obj->SetFor(
- "Next", new CPDF_Reference(m_pIndirectObjs, bookmarks[1].num));
-
- bookmarks[0].obj->SetFor("Type", new CPDF_Name(nullptr, "Outlines"));
- bookmarks[0].obj->SetFor("Count", new CPDF_Number(2));
- bookmarks[0].obj->SetFor(
- "First", new CPDF_Reference(m_pIndirectObjs, bookmarks[1].num));
- bookmarks[0].obj->SetFor(
- "Last", new CPDF_Reference(m_pIndirectObjs, bookmarks[2].num));
-
- m_pRootObj->SetFor("Outlines",
- new CPDF_Reference(m_pIndirectObjs, bookmarks[0].num));
+ bookmarks[1].obj->SetNewFor<CPDF_String>("Title", L"Chapter 1");
+ bookmarks[1].obj->SetNewFor<CPDF_Reference>("Parent", m_pIndirectObjs,
+ bookmarks[0].num);
+ bookmarks[1].obj->SetNewFor<CPDF_Reference>("Next", m_pIndirectObjs,
+ bookmarks[2].num);
+
+ bookmarks[2].obj->SetNewFor<CPDF_String>("Title", L"Chapter 2");
+ bookmarks[2].obj->SetNewFor<CPDF_Reference>("Parent", m_pIndirectObjs,
+ bookmarks[0].num);
+ bookmarks[2].obj->SetNewFor<CPDF_Reference>("Next", m_pIndirectObjs,
+ bookmarks[3].num);
+
+ bookmarks[3].obj->SetNewFor<CPDF_String>("Title", L"Chapter 3");
+ bookmarks[3].obj->SetNewFor<CPDF_Reference>("Parent", m_pIndirectObjs,
+ bookmarks[0].num);
+ bookmarks[3].obj->SetNewFor<CPDF_Reference>("Next", m_pIndirectObjs,
+ bookmarks[1].num);
+
+ bookmarks[0].obj->SetNewFor<CPDF_Name>("Type", "Outlines");
+ bookmarks[0].obj->SetNewFor<CPDF_Number>("Count", 2);
+ bookmarks[0].obj->SetNewFor<CPDF_Reference>("First", m_pIndirectObjs,
+ bookmarks[1].num);
+ bookmarks[0].obj->SetNewFor<CPDF_Reference>("Last", m_pIndirectObjs,
+ bookmarks[2].num);
+
+ m_pRootObj->SetNewFor<CPDF_Reference>("Outlines", m_pIndirectObjs,
+ bookmarks[0].num);
// Title with no match.
std::unique_ptr<unsigned short, pdfium::FreeDeleter> title =
diff --git a/fpdfsdk/fpdfeditpage.cpp b/fpdfsdk/fpdfeditpage.cpp
index 847adac7ec..c864b82145 100644
--- a/fpdfsdk/fpdfeditpage.cpp
+++ b/fpdfsdk/fpdfeditpage.cpp
@@ -83,11 +83,9 @@ DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_CreateNewDocument() {
CPDF_Dictionary* pInfoDict = nullptr;
pInfoDict = pDoc->GetInfo();
if (pInfoDict) {
- if (FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS)) {
- pInfoDict->SetFor("CreationDate",
- new CPDF_String(nullptr, DateStr, false));
- }
- pInfoDict->SetFor("Creator", new CPDF_String(L"PDFium"));
+ if (FSDK_IsSandBoxPolicyEnabled(FPDF_POLICY_MACHINETIME_ACCESS))
+ pInfoDict->SetNewFor<CPDF_String>("CreationDate", DateStr, false);
+ pInfoDict->SetNewFor<CPDF_String>("Creator", L"PDFium");
}
return FPDFDocumentFromCPDFDocument(pDoc);
@@ -111,15 +109,13 @@ DLLEXPORT FPDF_PAGE STDCALL FPDFPage_New(FPDF_DOCUMENT document,
if (!pPageDict)
return nullptr;
- CPDF_Array* pMediaBoxArray = new CPDF_Array;
+ CPDF_Array* pMediaBoxArray = pPageDict->SetNewFor<CPDF_Array>("MediaBox");
pMediaBoxArray->AddNew<CPDF_Number>(0);
pMediaBoxArray->AddNew<CPDF_Number>(0);
pMediaBoxArray->AddNew<CPDF_Number>(static_cast<FX_FLOAT>(width));
pMediaBoxArray->AddNew<CPDF_Number>(static_cast<FX_FLOAT>(height));
- pPageDict->SetFor("MediaBox", pMediaBoxArray);
- pPageDict->SetFor("Rotate", new CPDF_Number(0));
- pPageDict->SetFor("Resources",
- new CPDF_Dictionary(pDoc->GetByteStringPool()));
+ pPageDict->SetNewFor<CPDF_Number>("Rotate", 0);
+ pPageDict->SetNewFor<CPDF_Dictionary>("Resources");
#ifdef PDF_ENABLE_XFA
CPDFXFA_Page* pPage =
@@ -296,10 +292,9 @@ DLLEXPORT void STDCALL FPDFPage_TransformAnnots(FPDF_PAGE page,
rect.Transform(&matrix);
CPDF_Array* pRectArray = pAnnot->GetAnnotDict()->GetArrayFor("Rect");
- if (!pRectArray) {
- pRectArray = new CPDF_Array;
- pAnnot->GetAnnotDict()->SetFor("Rect", pRectArray);
- }
+ if (!pRectArray)
+ pRectArray = pAnnot->GetAnnotDict()->SetNewFor<CPDF_Array>("Rect");
+
pRectArray->SetNewAt<CPDF_Number>(0, rect.left);
pRectArray->SetNewAt<CPDF_Number>(1, rect.bottom);
pRectArray->SetNewAt<CPDF_Number>(2, rect.right);
@@ -316,5 +311,5 @@ DLLEXPORT void STDCALL FPDFPage_SetRotation(FPDF_PAGE page, int rotate) {
CPDF_Dictionary* pDict = pPage->m_pFormDict;
rotate %= 4;
- pDict->SetFor("Rotate", new CPDF_Number(rotate * 90));
+ pDict->SetNewFor<CPDF_Number>("Rotate", rotate * 90);
}
diff --git a/fpdfsdk/fpdfppo.cpp b/fpdfsdk/fpdfppo.cpp
index 915de1ad07..4e06856455 100644
--- a/fpdfsdk/fpdfppo.cpp
+++ b/fpdfsdk/fpdfppo.cpp
@@ -8,6 +8,7 @@
#include <map>
#include <memory>
+#include <utility>
#include <vector>
#include "core/fpdfapi/parser/cpdf_array.h"
@@ -64,7 +65,7 @@ bool CopyInheritable(CPDF_Dictionary* pCurPageDict,
if (!pInheritable)
return false;
- pCurPageDict->SetFor(key, pInheritable->Clone().release());
+ pCurPageDict->SetFor(key, pInheritable->Clone());
return true;
}
@@ -158,31 +159,30 @@ bool CPDF_PageOrganizer::PDFDocInit() {
if (!pDocInfoDict)
return false;
- CFX_ByteString producerstr;
- producerstr.Format("PDFium");
- pDocInfoDict->SetFor("Producer",
- new CPDF_String(nullptr, producerstr, false));
+ pDocInfoDict->SetNewFor<CPDF_String>("Producer", "PDFium", false);
CFX_ByteString cbRootType = pNewRoot->GetStringFor("Type", "");
if (cbRootType.IsEmpty())
- pNewRoot->SetFor("Type", new CPDF_Name(nullptr, "Catalog"));
+ pNewRoot->SetNewFor<CPDF_Name>("Type", "Catalog");
CPDF_Object* pElement = pNewRoot->GetObjectFor("Pages");
CPDF_Dictionary* pNewPages =
pElement ? ToDictionary(pElement->GetDirect()) : nullptr;
if (!pNewPages) {
pNewPages = m_pDestPDFDoc->NewIndirect<CPDF_Dictionary>();
- pNewRoot->SetReferenceFor("Pages", m_pDestPDFDoc, pNewPages);
+ pNewRoot->SetNewFor<CPDF_Reference>("Pages", m_pDestPDFDoc,
+ pNewPages->GetObjNum());
}
CFX_ByteString cbPageType = pNewPages->GetStringFor("Type", "");
if (cbPageType.IsEmpty())
- pNewPages->SetFor("Type", new CPDF_Name(nullptr, "Pages"));
+ pNewPages->SetNewFor<CPDF_Name>("Type", "Pages");
if (!pNewPages->GetArrayFor("Kids")) {
- pNewPages->SetIntegerFor("Count", 0);
- pNewPages->SetReferenceFor("Kids", m_pDestPDFDoc,
- m_pDestPDFDoc->NewIndirect<CPDF_Array>());
+ pNewPages->SetNewFor<CPDF_Number>("Count", 0);
+ pNewPages->SetNewFor<CPDF_Reference>(
+ "Kids", m_pDestPDFDoc,
+ m_pDestPDFDoc->NewIndirect<CPDF_Array>()->GetObjNum());
}
return true;
@@ -202,11 +202,11 @@ bool CPDF_PageOrganizer::ExportPage(const std::vector<uint16_t>& pageNums,
// Clone the page dictionary
for (const auto& it : *pSrcPageDict) {
const CFX_ByteString& cbSrcKeyStr = it.first;
- CPDF_Object* pObj = it.second;
if (cbSrcKeyStr == "Type" || cbSrcKeyStr == "Parent")
continue;
- pCurPageDict->SetFor(cbSrcKeyStr, pObj->Clone().release());
+ CPDF_Object* pObj = it.second.get();
+ pCurPageDict->SetFor(cbSrcKeyStr, pObj->Clone());
}
// inheritable item
@@ -217,15 +217,14 @@ bool CPDF_PageOrganizer::ExportPage(const std::vector<uint16_t>& pageNums,
CPDF_Object* pInheritable =
PageDictGetInheritableTag(pSrcPageDict, "CropBox");
if (pInheritable) {
- pCurPageDict->SetFor("MediaBox", pInheritable->Clone().release());
+ pCurPageDict->SetFor("MediaBox", pInheritable->Clone());
} else {
// Make the default size to be letter size (8.5'x11')
- CPDF_Array* pArray = new CPDF_Array;
+ CPDF_Array* pArray = pCurPageDict->SetNewFor<CPDF_Array>("MediaBox");
pArray->AddNew<CPDF_Number>(0);
pArray->AddNew<CPDF_Number>(0);
pArray->AddNew<CPDF_Number>(612);
pArray->AddNew<CPDF_Number>(792);
- pCurPageDict->SetFor("MediaBox", pArray);
}
}
@@ -265,7 +264,7 @@ bool CPDF_PageOrganizer::UpdateReference(CPDF_Object* pObj,
auto it = pDict->begin();
while (it != pDict->end()) {
const CFX_ByteString& key = it->first;
- CPDF_Object* pNextObj = it->second;
+ CPDF_Object* pNextObj = it->second.get();
++it;
if (key == "Parent" || key == "Prev" || key == "First")
continue;
@@ -386,7 +385,6 @@ DLLEXPORT FPDF_BOOL STDCALL FPDF_CopyViewerPreferences(FPDF_DOCUMENT dest_doc,
if (!pDstDict)
return false;
- pDstDict->SetFor("ViewerPreferences",
- pSrcDict->CloneDirectObject().release());
+ pDstDict->SetFor("ViewerPreferences", pSrcDict->CloneDirectObject());
return true;
}
diff --git a/fpdfsdk/fpdfview.cpp b/fpdfsdk/fpdfview.cpp
index 334c14cd45..d5f9a0e810 100644
--- a/fpdfsdk/fpdfview.cpp
+++ b/fpdfsdk/fpdfview.cpp
@@ -1082,7 +1082,7 @@ DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDest(FPDF_DOCUMENT document,
int i = 0;
for (const auto& it : *pDest) {
bsName = it.first;
- pDestObj = it.second;
+ pDestObj = it.second.get();
if (!pDestObj)
continue;
if (i == index)
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
index 26227c068e..9bb1418379 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
@@ -6,6 +6,8 @@
#include "fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.h"
+#include <memory>
+
#include "core/fpdfapi/parser/cpdf_array.h"
#include "core/fpdfapi/parser/cpdf_stream_acc.h"
#include "core/fpdfapi/parser/cpdf_string.h"
@@ -398,7 +400,7 @@ void CPDFXFA_DocEnvironment::SetTitle(CXFA_FFDoc* hDoc,
return;
if (CPDF_Dictionary* pInfoDict = m_pContext->GetPDFDoc()->GetInfo())
- pInfoDict->SetFor("Title", new CPDF_String(wsTitle));
+ pInfoDict->SetNewFor<CPDF_String>("Title", wsTitle);
}
void CPDFXFA_DocEnvironment::ExportData(CXFA_FFDoc* hDoc,
diff --git a/fpdfsdk/javascript/Document.cpp b/fpdfsdk/javascript/Document.cpp
index 54761a2647..29f9764806 100644
--- a/fpdfsdk/javascript/Document.cpp
+++ b/fpdfsdk/javascript/Document.cpp
@@ -13,6 +13,7 @@
#include "core/fpdfapi/page/cpdf_page.h"
#include "core/fpdfapi/parser/cpdf_array.h"
#include "core/fpdfapi/parser/cpdf_document.h"
+#include "core/fpdfapi/parser/cpdf_string.h"
#include "core/fpdfapi/parser/fpdf_parser_decode.h"
#include "core/fpdfdoc/cpdf_interform.h"
#include "core/fpdfdoc/cpdf_nametree.h"
@@ -809,7 +810,7 @@ bool Document::info(IJS_Context* cc,
// It's to be compatible to non-standard info dictionary.
for (const auto& it : *pDictionary) {
const CFX_ByteString& bsKey = it.first;
- CPDF_Object* pValueObj = it.second;
+ CPDF_Object* pValueObj = it.second.get();
CFX_WideString wsKey = CFX_WideString::FromUTF8(bsKey.AsStringC());
if (pValueObj->IsString() || pValueObj->IsName()) {
pRuntime->PutObjectString(pObj, wsKey, pValueObj->GetUnicodeText());
@@ -844,7 +845,8 @@ bool Document::getPropertyInternal(IJS_Context* cc,
}
CFX_WideString csProperty;
vp >> csProperty;
- pDictionary->SetStringFor(propName, PDF_EncodeText(csProperty));
+ pDictionary->SetNewFor<CPDF_String>(propName, PDF_EncodeText(csProperty),
+ false);
m_pFormFillEnv->SetChangeMark();
}
return true;