summaryrefslogtreecommitdiff
path: root/fpdfsdk
diff options
context:
space:
mode:
Diffstat (limited to 'fpdfsdk')
-rw-r--r--fpdfsdk/cpdfsdk_baannot.cpp11
-rw-r--r--fpdfsdk/fpdf_flatten.cpp24
-rw-r--r--fpdfsdk/fpdf_transformpage.cpp65
-rw-r--r--fpdfsdk/fpdfdoc_unittest.cpp16
-rw-r--r--fpdfsdk/fpdfeditpage.cpp16
-rw-r--r--fpdfsdk/fpdfppo.cpp8
-rw-r--r--fpdfsdk/fpdfsave.cpp12
7 files changed, 79 insertions, 73 deletions
diff --git a/fpdfsdk/cpdfsdk_baannot.cpp b/fpdfsdk/cpdfsdk_baannot.cpp
index 9436b3ba62..ee4b55d290 100644
--- a/fpdfsdk/cpdfsdk_baannot.cpp
+++ b/fpdfsdk/cpdfsdk_baannot.cpp
@@ -162,7 +162,7 @@ int CPDFSDK_BAAnnot::GetStructParent() const {
void CPDFSDK_BAAnnot::SetBorderWidth(int nWidth) {
CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArrayFor("Border");
if (pBorder) {
- pBorder->SetAt(2, new CPDF_Number(nWidth));
+ pBorder->SetNewAt<CPDF_Number>(2, nWidth);
} else {
CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDictFor("BS");
if (!pBSDict) {
@@ -242,9 +242,12 @@ BorderStyle CPDFSDK_BAAnnot::GetBorderStyle() const {
void CPDFSDK_BAAnnot::SetColor(FX_COLORREF color) {
CPDF_Array* pArray = new CPDF_Array;
- pArray->AddNumber((FX_FLOAT)FXSYS_GetRValue(color) / 255.0f);
- pArray->AddNumber((FX_FLOAT)FXSYS_GetGValue(color) / 255.0f);
- pArray->AddNumber((FX_FLOAT)FXSYS_GetBValue(color) / 255.0f);
+ 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);
}
diff --git a/fpdfsdk/fpdf_flatten.cpp b/fpdfsdk/fpdf_flatten.cpp
index b11e4a621d..cb0a625e23 100644
--- a/fpdfsdk/fpdf_flatten.cpp
+++ b/fpdfsdk/fpdf_flatten.cpp
@@ -13,6 +13,7 @@
#include "core/fpdfapi/parser/cpdf_array.h"
#include "core/fpdfapi/parser/cpdf_document.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_stream_acc.h"
#include "core/fpdfdoc/cpdf_annot.h"
@@ -205,12 +206,13 @@ void SetPageContents(const CFX_ByteString& key,
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());
+ pContentsArray->AddNew<CPDF_Reference>(pDocument,
+ pContentsStream->GetObjNum());
pPage->SetReferenceFor("Contents", pDocument, pContentsArray);
}
if (!key.IsEmpty()) {
- pContentsArray->AddReference(pDocument,
- NewIndirectContentsStream(key, pDocument));
+ pContentsArray->AddNew<CPDF_Reference>(
+ pDocument, NewIndirectContentsStream(key, pDocument));
}
}
@@ -270,19 +272,19 @@ DLLEXPORT int STDCALL FPDFPage_Flatten(FPDF_PAGE page, int nFlag) {
if (!rcOriginalMB.IsEmpty()) {
CPDF_Array* pMediaBox = new CPDF_Array();
- pMediaBox->Add(new CPDF_Number(rcOriginalMB.left));
- pMediaBox->Add(new CPDF_Number(rcOriginalMB.bottom));
- pMediaBox->Add(new CPDF_Number(rcOriginalMB.right));
- pMediaBox->Add(new CPDF_Number(rcOriginalMB.top));
+ 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();
- pCropBox->Add(new CPDF_Number(rcOriginalCB.left));
- pCropBox->Add(new CPDF_Number(rcOriginalCB.bottom));
- pCropBox->Add(new CPDF_Number(rcOriginalCB.right));
- pCropBox->Add(new CPDF_Number(rcOriginalCB.top));
+ 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);
}
diff --git a/fpdfsdk/fpdf_transformpage.cpp b/fpdfsdk/fpdf_transformpage.cpp
index 76be4de092..beaa6c4d98 100644
--- a/fpdfsdk/fpdf_transformpage.cpp
+++ b/fpdfsdk/fpdf_transformpage.cpp
@@ -27,10 +27,10 @@ void SetBoundingBox(CPDF_Page* page,
float right,
float top) {
CPDF_Array* pBoundingBoxArray = new CPDF_Array;
- pBoundingBoxArray->Add(new CPDF_Number(left));
- pBoundingBoxArray->Add(new CPDF_Number(bottom));
- pBoundingBoxArray->Add(new CPDF_Number(right));
- pBoundingBoxArray->Add(new CPDF_Number(top));
+ 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);
}
@@ -142,23 +142,22 @@ DLLEXPORT FPDF_BOOL STDCALL FPDFPage_TransFormWithClip(FPDF_PAGE page,
CPDF_Array* pArray = ToArray(pContentObj);
if (pArray) {
pContentArray = pArray;
- CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum());
- pContentArray->InsertAt(0, pRef);
- pContentArray->AddReference(pDoc, pEndStream->GetObjNum());
+ pContentArray->InsertNewAt<CPDF_Reference>(0, pDoc, pStream->GetObjNum());
+ pContentArray->AddNew<CPDF_Reference>(pDoc, pEndStream->GetObjNum());
} else if (CPDF_Reference* pReference = ToReference(pContentObj)) {
CPDF_Object* pDirectObj = pReference->GetDirect();
if (pDirectObj) {
CPDF_Array* pObjArray = pDirectObj->AsArray();
if (pObjArray) {
pContentArray = pObjArray;
- CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum());
- pContentArray->InsertAt(0, pRef);
- pContentArray->AddReference(pDoc, pEndStream->GetObjNum());
+ pContentArray->InsertNewAt<CPDF_Reference>(0, pDoc,
+ pStream->GetObjNum());
+ pContentArray->AddNew<CPDF_Reference>(pDoc, pEndStream->GetObjNum());
} else if (pDirectObj->IsStream()) {
pContentArray = pDoc->NewIndirect<CPDF_Array>();
- pContentArray->AddReference(pDoc, pStream->GetObjNum());
- pContentArray->AddReference(pDoc, pDirectObj->GetObjNum());
- pContentArray->AddReference(pDoc, pEndStream->GetObjNum());
+ 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);
}
}
@@ -307,26 +306,28 @@ DLLEXPORT void STDCALL FPDFPage_InsertClipPath(FPDF_PAGE page,
CPDF_Stream* pStream = pDoc->NewIndirect<CPDF_Stream>(nullptr, 0, pDic);
pStream->SetData(strClip.GetBuffer(), strClip.GetSize());
- CPDF_Array* pContentArray = nullptr;
CPDF_Array* pArray = ToArray(pContentObj);
if (pArray) {
- pContentArray = pArray;
- CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum());
- pContentArray->InsertAt(0, pRef);
- } else if (CPDF_Reference* pReference = ToReference(pContentObj)) {
- CPDF_Object* pDirectObj = pReference->GetDirect();
- if (pDirectObj) {
- CPDF_Array* pObjArray = pDirectObj->AsArray();
- if (pObjArray) {
- pContentArray = pObjArray;
- CPDF_Reference* pRef = new CPDF_Reference(pDoc, pStream->GetObjNum());
- pContentArray->InsertAt(0, pRef);
- } else if (pDirectObj->IsStream()) {
- pContentArray = pDoc->NewIndirect<CPDF_Array>();
- pContentArray->AddReference(pDoc, pStream->GetObjNum());
- pContentArray->AddReference(pDoc, pDirectObj->GetObjNum());
- pPageDic->SetReferenceFor("Contents", pDoc, pContentArray);
- }
- }
+ pArray->InsertNewAt<CPDF_Reference>(0, pDoc, pStream->GetObjNum());
+ return;
+ }
+ CPDF_Reference* pReference = ToReference(pContentObj);
+ if (!pReference)
+ return;
+
+ CPDF_Object* pDirectObj = pReference->GetDirect();
+ if (!pDirectObj)
+ return;
+
+ CPDF_Array* pObjArray = pDirectObj->AsArray();
+ if (pObjArray) {
+ pObjArray->InsertNewAt<CPDF_Reference>(0, pDoc, pStream->GetObjNum());
+ return;
+ }
+ if (pDirectObj->IsStream()) {
+ 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);
}
}
diff --git a/fpdfsdk/fpdfdoc_unittest.cpp b/fpdfsdk/fpdfdoc_unittest.cpp
index 7d1d6b4ba8..50837d52e3 100644
--- a/fpdfsdk/fpdfdoc_unittest.cpp
+++ b/fpdfsdk/fpdfdoc_unittest.cpp
@@ -236,11 +236,11 @@ TEST_F(PDFDocTest, FindBookmark) {
TEST_F(PDFDocTest, GetLocationInPage) {
auto array = pdfium::MakeUnique<CPDF_Array>();
- array->AddInteger(0); // Page Index.
- array->AddName("XYZ");
- array->AddNumber(4); // X
- array->AddNumber(5); // Y
- array->AddNumber(6); // Zoom.
+ array->AddNew<CPDF_Number>(0); // Page Index.
+ array->AddNew<CPDF_Name>("XYZ");
+ array->AddNew<CPDF_Number>(4); // X
+ array->AddNew<CPDF_Number>(5); // Y
+ array->AddNew<CPDF_Number>(6); // Zoom.
FPDF_BOOL hasX;
FPDF_BOOL hasY;
@@ -258,9 +258,9 @@ TEST_F(PDFDocTest, GetLocationInPage) {
EXPECT_EQ(5, y);
EXPECT_EQ(6, zoom);
- array->SetAt(2, new CPDF_Null);
- array->SetAt(3, new CPDF_Null);
- array->SetAt(4, new CPDF_Null);
+ array->SetNewAt<CPDF_Null>(2);
+ array->SetNewAt<CPDF_Null>(3);
+ array->SetNewAt<CPDF_Null>(4);
EXPECT_TRUE(FPDFDest_GetLocationInPage(array.get(), &hasX, &hasY, &hasZoom,
&x, &y, &zoom));
EXPECT_FALSE(hasX);
diff --git a/fpdfsdk/fpdfeditpage.cpp b/fpdfsdk/fpdfeditpage.cpp
index 92fd39e78b..9dc8ae9099 100644
--- a/fpdfsdk/fpdfeditpage.cpp
+++ b/fpdfsdk/fpdfeditpage.cpp
@@ -110,10 +110,10 @@ DLLEXPORT FPDF_PAGE STDCALL FPDFPage_New(FPDF_DOCUMENT document,
return nullptr;
CPDF_Array* pMediaBoxArray = new CPDF_Array;
- pMediaBoxArray->Add(new CPDF_Number(0));
- pMediaBoxArray->Add(new CPDF_Number(0));
- pMediaBoxArray->Add(new CPDF_Number(FX_FLOAT(width)));
- pMediaBoxArray->Add(new CPDF_Number(FX_FLOAT(height)));
+ 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",
@@ -298,10 +298,10 @@ DLLEXPORT void STDCALL FPDFPage_TransformAnnots(FPDF_PAGE page,
pRectArray = new CPDF_Array;
pAnnot->GetAnnotDict()->SetFor("Rect", pRectArray);
}
- pRectArray->SetAt(0, new CPDF_Number(rect.left));
- pRectArray->SetAt(1, new CPDF_Number(rect.bottom));
- pRectArray->SetAt(2, new CPDF_Number(rect.right));
- pRectArray->SetAt(3, new CPDF_Number(rect.top));
+ pRectArray->SetNewAt<CPDF_Number>(0, rect.left);
+ pRectArray->SetNewAt<CPDF_Number>(1, rect.bottom);
+ pRectArray->SetNewAt<CPDF_Number>(2, rect.right);
+ pRectArray->SetNewAt<CPDF_Number>(3, rect.top);
// TODO: Transform AP's rectangle
}
diff --git a/fpdfsdk/fpdfppo.cpp b/fpdfsdk/fpdfppo.cpp
index 610aae7abd..ec3312b121 100644
--- a/fpdfsdk/fpdfppo.cpp
+++ b/fpdfsdk/fpdfppo.cpp
@@ -221,10 +221,10 @@ bool CPDF_PageOrganizer::ExportPage(const std::vector<uint16_t>& pageNums,
} else {
// Make the default size to be letter size (8.5'x11')
CPDF_Array* pArray = new CPDF_Array;
- pArray->AddNumber(0);
- pArray->AddNumber(0);
- pArray->AddNumber(612);
- pArray->AddNumber(792);
+ pArray->AddNew<CPDF_Number>(0);
+ pArray->AddNew<CPDF_Number>(0);
+ pArray->AddNew<CPDF_Number>(612);
+ pArray->AddNew<CPDF_Number>(792);
pCurPageDict->SetFor("MediaBox", pArray);
}
}
diff --git a/fpdfsdk/fpdfsave.cpp b/fpdfsdk/fpdfsave.cpp
index e5d7a409ae..c9043249e1 100644
--- a/fpdfsdk/fpdfsave.cpp
+++ b/fpdfsdk/fpdfsave.cpp
@@ -183,9 +183,9 @@ bool SaveXFADocumentData(CPDFXFA_Context* pContext,
CPDF_Stream* pData = pPDFDocument->NewIndirect<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->InsertNewAt<CPDF_String>(iLast, "datasets", false);
+ pArray->InsertNewAt<CPDF_Reference>(iLast + 1, pPDFDocument,
+ pData->GetObjNum());
}
fileList->push_back(std::move(pDsfileWrite));
}
@@ -205,9 +205,9 @@ bool SaveXFADocumentData(CPDFXFA_Context* pContext,
CPDF_Stream* pData = pPDFDocument->NewIndirect<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->InsertNewAt<CPDF_String>(iLast, "form", false);
+ pArray->InsertNewAt<CPDF_Reference>(iLast + 1, pPDFDocument,
+ pData->GetObjNum());
}
fileList->push_back(std::move(pfileWrite));
}