summaryrefslogtreecommitdiff
path: root/core/fpdfapi/page
diff options
context:
space:
mode:
authortsepez <tsepez@chromium.org>2016-11-18 16:22:41 -0800
committerCommit bot <commit-bot@chromium.org>2016-11-18 16:22:41 -0800
commit0e606b5ecd6e45f74391f110cc1fe0cce0e80c64 (patch)
tree07c55fac710b191cf5d1d6595c63b90ca52e3cbb /core/fpdfapi/page
parent430ab8363e77c48b2c2435af4d289f85e2be1b96 (diff)
downloadpdfium-0e606b5ecd6e45f74391f110cc1fe0cce0e80c64.tar.xz
Make CPDF_Dictionary use unique pointers.chromium/2926
Some changes were required to match underlying ctors as invoked by the templated methods. Many release() calls go away, a few WrapUniques() are introduced to avoid going deeper into other code. Review-Url: https://codereview.chromium.org/2510223002
Diffstat (limited to 'core/fpdfapi/page')
-rw-r--r--core/fpdfapi/page/cpdf_allstates.cpp4
-rw-r--r--core/fpdfapi/page/cpdf_colorspace.cpp2
-rw-r--r--core/fpdfapi/page/cpdf_docpagedata.cpp13
-rw-r--r--core/fpdfapi/page/cpdf_image.cpp72
-rw-r--r--core/fpdfapi/page/cpdf_streamcontentparser.cpp19
-rw-r--r--core/fpdfapi/page/cpdf_streamparser.cpp13
6 files changed, 62 insertions, 61 deletions
diff --git a/core/fpdfapi/page/cpdf_allstates.cpp b/core/fpdfapi/page/cpdf_allstates.cpp
index 012c1349c0..f88342d7d7 100644
--- a/core/fpdfapi/page/cpdf_allstates.cpp
+++ b/core/fpdfapi/page/cpdf_allstates.cpp
@@ -6,6 +6,8 @@
#include "core/fpdfapi/page/cpdf_allstates.h"
+#include <algorithm>
+
#include "core/fpdfapi/page/pageint.h"
#include "core/fpdfapi/parser/cpdf_array.h"
#include "core/fpdfapi/parser/cpdf_dictionary.h"
@@ -52,7 +54,7 @@ void CPDF_AllStates::ProcessExtGS(CPDF_Dictionary* pGS,
CPDF_StreamContentParser* pParser) {
for (const auto& it : *pGS) {
const CFX_ByteString& key_str = it.first;
- CPDF_Object* pElement = it.second;
+ CPDF_Object* pElement = it.second.get();
CPDF_Object* pObject = pElement ? pElement->GetDirect() : nullptr;
if (!pObject)
continue;
diff --git a/core/fpdfapi/page/cpdf_colorspace.cpp b/core/fpdfapi/page/cpdf_colorspace.cpp
index 0c023d19ff..b1675d87a7 100644
--- a/core/fpdfapi/page/cpdf_colorspace.cpp
+++ b/core/fpdfapi/page/cpdf_colorspace.cpp
@@ -345,7 +345,7 @@ std::unique_ptr<CPDF_ColorSpace> CPDF_ColorSpace::Load(CPDF_Document* pDoc,
for (const auto& it : *pDict) {
std::unique_ptr<CPDF_ColorSpace> pRet;
- CPDF_Object* pValue = it.second;
+ CPDF_Object* pValue = it.second.get();
if (ToName(pValue))
pRet.reset(ColorspaceFromName(pValue->GetString()));
if (pRet)
diff --git a/core/fpdfapi/page/cpdf_docpagedata.cpp b/core/fpdfapi/page/cpdf_docpagedata.cpp
index b849bc4107..3df771070e 100644
--- a/core/fpdfapi/page/cpdf_docpagedata.cpp
+++ b/core/fpdfapi/page/cpdf_docpagedata.cpp
@@ -7,6 +7,7 @@
#include "core/fpdfapi/page/cpdf_docpagedata.h"
#include <algorithm>
+#include <memory>
#include <set>
#include "core/fdrm/crypto/fx_crypt.h"
@@ -21,6 +22,7 @@
#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_name.h"
#include "core/fpdfapi/parser/cpdf_stream_acc.h"
#include "third_party/base/stl_util.h"
@@ -176,12 +178,13 @@ CPDF_Font* CPDF_DocPageData::GetStandardFont(const CFX_ByteString& fontName,
}
CPDF_Dictionary* pDict = m_pPDFDoc->NewIndirect<CPDF_Dictionary>();
- pDict->SetNameFor("Type", "Font");
- pDict->SetNameFor("Subtype", "Type1");
- pDict->SetNameFor("BaseFont", fontName);
+ pDict->SetNewFor<CPDF_Name>("Type", "Font");
+ pDict->SetNewFor<CPDF_Name>("Subtype", "Type1");
+ pDict->SetNewFor<CPDF_Name>("BaseFont", fontName);
if (pEncoding) {
- pDict->SetFor("Encoding",
- pEncoding->Realize(m_pPDFDoc->GetByteStringPool()));
+ pDict->SetFor(
+ "Encoding",
+ pdfium::WrapUnique(pEncoding->Realize(m_pPDFDoc->GetByteStringPool())));
}
std::unique_ptr<CPDF_Font> pFont = CPDF_Font::Create(m_pPDFDoc, pDict);
diff --git a/core/fpdfapi/page/cpdf_image.cpp b/core/fpdfapi/page/cpdf_image.cpp
index 1c3aa89ff2..8ded34e630 100644
--- a/core/fpdfapi/page/cpdf_image.cpp
+++ b/core/fpdfapi/page/cpdf_image.cpp
@@ -8,6 +8,7 @@
#include <algorithm>
#include <memory>
+#include <utility>
#include <vector>
#include "core/fpdfapi/cpdf_modulemgr.h"
@@ -97,10 +98,10 @@ CPDF_Dictionary* CPDF_Image::InitJPEG(uint8_t* pData, uint32_t size) {
CPDF_Dictionary* pDict =
new CPDF_Dictionary(m_pDocument->GetByteStringPool());
- pDict->SetNameFor("Type", "XObject");
- pDict->SetNameFor("Subtype", "Image");
- pDict->SetIntegerFor("Width", width);
- pDict->SetIntegerFor("Height", height);
+ pDict->SetNewFor<CPDF_Name>("Type", "XObject");
+ pDict->SetNewFor<CPDF_Name>("Subtype", "Image");
+ pDict->SetNewFor<CPDF_Number>("Width", width);
+ pDict->SetNewFor<CPDF_Number>("Height", height);
const FX_CHAR* csname = nullptr;
if (num_comps == 1) {
csname = "DeviceGray";
@@ -108,21 +109,18 @@ CPDF_Dictionary* CPDF_Image::InitJPEG(uint8_t* pData, uint32_t size) {
csname = "DeviceRGB";
} else if (num_comps == 4) {
csname = "DeviceCMYK";
- CPDF_Array* pDecode = new CPDF_Array;
+ CPDF_Array* pDecode = pDict->SetNewFor<CPDF_Array>("Decode");
for (int n = 0; n < 4; n++) {
pDecode->AddNew<CPDF_Number>(1);
pDecode->AddNew<CPDF_Number>(0);
}
- pDict->SetFor("Decode", pDecode);
}
- pDict->SetNameFor("ColorSpace", csname);
- pDict->SetIntegerFor("BitsPerComponent", bits);
- pDict->SetNameFor("Filter", "DCTDecode");
+ pDict->SetNewFor<CPDF_Name>("ColorSpace", csname);
+ pDict->SetNewFor<CPDF_Number>("BitsPerComponent", bits);
+ pDict->SetNewFor<CPDF_Name>("Filter", "DCTDecode");
if (!color_trans) {
- CPDF_Dictionary* pParms =
- new CPDF_Dictionary(m_pDocument->GetByteStringPool());
- pDict->SetFor("DecodeParms", pParms);
- pParms->SetIntegerFor("ColorTransform", 0);
+ CPDF_Dictionary* pParms = pDict->SetNewFor<CPDF_Dictionary>("DecodeParms");
+ pParms->SetNewFor<CPDF_Number>("ColorTransform", 0);
}
m_bIsMask = false;
m_Width = width;
@@ -166,10 +164,10 @@ void CPDF_Image::SetImage(const CFX_DIBitmap* pBitmap, int32_t iCompress) {
CPDF_Dictionary* pDict =
new CPDF_Dictionary(m_pDocument->GetByteStringPool());
- pDict->SetNameFor("Type", "XObject");
- pDict->SetNameFor("Subtype", "Image");
- pDict->SetIntegerFor("Width", BitmapWidth);
- pDict->SetIntegerFor("Height", BitmapHeight);
+ pDict->SetNewFor<CPDF_Name>("Type", "XObject");
+ pDict->SetNewFor<CPDF_Name>("Subtype", "Image");
+ pDict->SetNewFor<CPDF_Number>("Width", BitmapWidth);
+ pDict->SetNewFor<CPDF_Number>("Height", BitmapHeight);
uint8_t* dest_buf = nullptr;
FX_STRSIZE dest_pitch = 0, dest_size = 0, opType = -1;
if (bpp == 1) {
@@ -181,15 +179,14 @@ void CPDF_Image::SetImage(const CFX_DIBitmap* pBitmap, int32_t iCompress) {
ArgbDecode(pBitmap->GetPaletteArgb(1), set_a, set_r, set_g, set_b);
}
if (set_a == 0 || reset_a == 0) {
- pDict->SetFor("ImageMask", new CPDF_Boolean(true));
+ pDict->SetNewFor<CPDF_Boolean>("ImageMask", true);
if (reset_a == 0) {
- CPDF_Array* pArray = new CPDF_Array;
+ CPDF_Array* pArray = pDict->SetNewFor<CPDF_Array>("Decode");
pArray->AddNew<CPDF_Number>(1);
pArray->AddNew<CPDF_Number>(0);
- pDict->SetFor("Decode", pArray);
}
} else {
- CPDF_Array* pCS = new CPDF_Array;
+ CPDF_Array* pCS = pDict->SetNewFor<CPDF_Array>("ColorSpace");
pCS->AddNew<CPDF_Name>("Indexed");
pCS->AddNew<CPDF_Name>("DeviceRGB");
pCS->AddNew<CPDF_Number>(1);
@@ -203,9 +200,8 @@ void CPDF_Image::SetImage(const CFX_DIBitmap* pBitmap, int32_t iCompress) {
pBuf[5] = (FX_CHAR)set_b;
ct.ReleaseBuffer(6);
pCS->AddNew<CPDF_String>(ct, true);
- pDict->SetFor("ColorSpace", pCS);
}
- pDict->SetIntegerFor("BitsPerComponent", 1);
+ pDict->SetNewFor<CPDF_Number>("BitsPerComponent", 1);
dest_pitch = (BitmapWidth + 7) / 8;
if ((iCompress & 0x03) == PDF_IMAGE_NO_COMPRESS) {
opType = 1;
@@ -232,11 +228,12 @@ void CPDF_Image::SetImage(const CFX_DIBitmap* pBitmap, int32_t iCompress) {
pColorTable, iPalette * 3,
new CPDF_Dictionary(m_pDocument->GetByteStringPool()));
pCS->AddNew<CPDF_Reference>(m_pDocument, pCTS->GetObjNum());
- pDict->SetReferenceFor("ColorSpace", m_pDocument, pCS);
+ pDict->SetNewFor<CPDF_Reference>("ColorSpace", m_pDocument,
+ pCS->GetObjNum());
} else {
- pDict->SetNameFor("ColorSpace", "DeviceGray");
+ pDict->SetNewFor<CPDF_Name>("ColorSpace", "DeviceGray");
}
- pDict->SetIntegerFor("BitsPerComponent", 8);
+ pDict->SetNewFor<CPDF_Number>("BitsPerComponent", 8);
if ((iCompress & 0x03) == PDF_IMAGE_NO_COMPRESS) {
dest_pitch = BitmapWidth;
opType = 1;
@@ -244,8 +241,8 @@ void CPDF_Image::SetImage(const CFX_DIBitmap* pBitmap, int32_t iCompress) {
opType = 0;
}
} else {
- pDict->SetNameFor("ColorSpace", "DeviceRGB");
- pDict->SetIntegerFor("BitsPerComponent", 8);
+ pDict->SetNewFor<CPDF_Name>("ColorSpace", "DeviceRGB");
+ pDict->SetNewFor<CPDF_Number>("BitsPerComponent", 8);
if ((iCompress & 0x03) == PDF_IMAGE_NO_COMPRESS) {
dest_pitch = BitmapWidth * 3;
opType = 2;
@@ -266,12 +263,12 @@ void CPDF_Image::SetImage(const CFX_DIBitmap* pBitmap, int32_t iCompress) {
FX_STRSIZE mask_size = 0;
CPDF_Dictionary* pMaskDict =
new CPDF_Dictionary(m_pDocument->GetByteStringPool());
- pMaskDict->SetNameFor("Type", "XObject");
- pMaskDict->SetNameFor("Subtype", "Image");
- pMaskDict->SetIntegerFor("Width", maskWidth);
- pMaskDict->SetIntegerFor("Height", maskHeight);
- pMaskDict->SetNameFor("ColorSpace", "DeviceGray");
- pMaskDict->SetIntegerFor("BitsPerComponent", 8);
+ pMaskDict->SetNewFor<CPDF_Name>("Type", "XObject");
+ pMaskDict->SetNewFor<CPDF_Name>("Subtype", "Image");
+ pMaskDict->SetNewFor<CPDF_Number>("Width", maskWidth);
+ pMaskDict->SetNewFor<CPDF_Number>("Height", maskHeight);
+ pMaskDict->SetNewFor<CPDF_Name>("ColorSpace", "DeviceGray");
+ pMaskDict->SetNewFor<CPDF_Number>("BitsPerComponent", 8);
if (pMaskBitmap->GetBPP() == 8 &&
(iCompress & PDF_IMAGE_MASK_LOSSY_COMPRESS) != 0) {
} else if (pMaskBitmap->GetFormat() == FXDIB_1bppMask) {
@@ -283,10 +280,11 @@ void CPDF_Image::SetImage(const CFX_DIBitmap* pBitmap, int32_t iCompress) {
maskWidth);
}
}
- pMaskDict->SetIntegerFor("Length", mask_size);
- pDict->SetReferenceFor(
+ pMaskDict->SetNewFor<CPDF_Number>("Length", mask_size);
+ pDict->SetNewFor<CPDF_Reference>(
"SMask", m_pDocument,
- m_pDocument->NewIndirect<CPDF_Stream>(mask_buf, mask_size, pMaskDict));
+ m_pDocument->NewIndirect<CPDF_Stream>(mask_buf, mask_size, pMaskDict)
+ ->GetObjNum());
if (bDeleteMask)
delete pMaskBitmap;
}
diff --git a/core/fpdfapi/page/cpdf_streamcontentparser.cpp b/core/fpdfapi/page/cpdf_streamcontentparser.cpp
index aed5d4b2e2..6ddd278e27 100644
--- a/core/fpdfapi/page/cpdf_streamcontentparser.cpp
+++ b/core/fpdfapi/page/cpdf_streamcontentparser.cpp
@@ -30,6 +30,7 @@
#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/fpdf_parser_decode.h"
#include "core/fxcrt/fx_safe_types.h"
@@ -172,7 +173,7 @@ void ReplaceAbbr(CPDF_Object* pObj) {
std::vector<AbbrReplacementOp> replacements;
for (const auto& it : *pDict) {
CFX_ByteString key = it.first;
- CPDF_Object* value = it.second;
+ CPDF_Object* value = it.second.get();
CFX_ByteStringC fullname = FindFullName(
InlineKeyAbbr, FX_ArraySize(InlineKeyAbbr), key.AsStringC());
if (!fullname.IsEmpty()) {
@@ -203,7 +204,7 @@ void ReplaceAbbr(CPDF_Object* pObj) {
if (op.is_replace_key)
pDict->ReplaceKey(op.key, CFX_ByteString(op.replacement));
else
- pDict->SetNameFor(op.key, CFX_ByteString(op.replacement));
+ pDict->SetNewFor<CPDF_Name>(op.key, CFX_ByteString(op.replacement));
}
break;
}
@@ -650,13 +651,13 @@ void CPDF_StreamContentParser::Handle_BeginImage() {
}
CFX_ByteString key((const FX_CHAR*)m_pSyntax->GetWordBuf() + 1,
m_pSyntax->GetWordSize() - 1);
- std::unique_ptr<CPDF_Object> pObj(m_pSyntax->ReadNextObject(false, 0));
+ auto pObj = pdfium::WrapUnique(m_pSyntax->ReadNextObject(false, 0));
if (!key.IsEmpty()) {
uint32_t dwObjNum = pObj ? pObj->GetObjNum() : 0;
if (dwObjNum)
- pDict->SetReferenceFor(key, m_pDocument, dwObjNum);
+ pDict->SetNewFor<CPDF_Reference>(key, m_pDocument, dwObjNum);
else
- pDict->SetFor(key, pObj.release());
+ pDict->SetFor(key, std::move(pObj));
}
}
ReplaceAbbr(pDict);
@@ -667,14 +668,12 @@ void CPDF_StreamContentParser::Handle_BeginImage() {
CFX_ByteString name = pCSObj->GetString();
if (name != "DeviceRGB" && name != "DeviceGray" && name != "DeviceCMYK") {
pCSObj = FindResourceObj("ColorSpace", name);
- if (pCSObj && pCSObj->IsInline()) {
- pCSObj = pCSObj->Clone().release();
- pDict->SetFor("ColorSpace", pCSObj);
- }
+ if (pCSObj && pCSObj->IsInline())
+ pDict->SetFor("ColorSpace", pCSObj->Clone());
}
}
}
- pDict->SetNameFor("Subtype", "Image");
+ pDict->SetNewFor<CPDF_Name>("Subtype", "Image");
std::unique_ptr<CPDF_Stream> pStream(
m_pSyntax->ReadInlineStream(m_pDocument, pDict, pCSObj));
bool bGaveDictAway = !!pStream;
diff --git a/core/fpdfapi/page/cpdf_streamparser.cpp b/core/fpdfapi/page/cpdf_streamparser.cpp
index 2c2be0bd27..6b4a362257 100644
--- a/core/fpdfapi/page/cpdf_streamparser.cpp
+++ b/core/fpdfapi/page/cpdf_streamparser.cpp
@@ -8,6 +8,8 @@
#include <limits.h>
+#include <utility>
+
#include "core/fpdfapi/cpdf_modulemgr.h"
#include "core/fpdfapi/page/cpdf_docpagedata.h"
#include "core/fpdfapi/parser/cpdf_array.h"
@@ -230,7 +232,7 @@ CPDF_Stream* CPDF_StreamParser::ReadInlineStream(CPDF_Document* pDoc,
FXSYS_memcpy(pData, m_pBuf + m_Pos, dwStreamSize);
m_Pos += dwStreamSize;
}
- pDict->SetIntegerFor("Length", (int)dwStreamSize);
+ pDict->SetNewFor<CPDF_Number>("Length", (int)dwStreamSize);
return new CPDF_Stream(pData, dwStreamSize, pDict);
}
@@ -361,16 +363,13 @@ CPDF_Object* CPDF_StreamParser::ReadNextObject(bool bAllowNestedArray,
CFX_ByteString key =
PDF_NameDecode(CFX_ByteStringC(m_WordBuffer + 1, m_WordSize - 1));
- CPDF_Object* pObj = ReadNextObject(true, 0);
+ auto pObj = pdfium::WrapUnique(ReadNextObject(true, 0));
if (!pObj) {
delete pDict;
return nullptr;
}
-
- if (key.IsEmpty())
- delete pObj;
- else
- pDict->SetFor(key, pObj);
+ if (!key.IsEmpty())
+ pDict->SetFor(key, std::move(pObj));
}
return pDict;
}