summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authortsepez <tsepez@chromium.org>2017-01-09 07:01:36 -0800
committerCommit bot <commit-bot@chromium.org>2017-01-09 07:01:36 -0800
commit0fa471794a88b262f9114b973d74b1c33e4e592b (patch)
tree0922c56f6e8ba029cd59dc85c8e2c05689cc334a /core
parent5037839bb0b91792b81a3e455dead1314fcc7a6d (diff)
downloadpdfium-0fa471794a88b262f9114b973d74b1c33e4e592b.tar.xz
Remove CFX_ArrayTemplate from fpdfapi
Review-Url: https://codereview.chromium.org/2611413002
Diffstat (limited to 'core')
-rw-r--r--core/fpdfapi/edit/cpdf_creator.h3
-rw-r--r--core/fpdfapi/edit/fpdf_edit_create.cpp107
-rw-r--r--core/fpdfapi/font/cpdf_cidfont.cpp42
-rw-r--r--core/fpdfapi/font/cpdf_cidfont.h7
-rw-r--r--core/fpdfapi/font/font_int.h3
-rw-r--r--core/fpdfapi/font/fpdf_font_cid.cpp10
-rw-r--r--core/fpdfapi/parser/cpdf_data_avail.cpp61
-rw-r--r--core/fpdfapi/parser/cpdf_data_avail.h4
-rw-r--r--core/fpdfapi/parser/cpdf_document.cpp44
-rw-r--r--core/fpdfapi/parser/cpdf_document.h2
-rw-r--r--core/fpdfapi/parser/cpdf_document_unittest.cpp4
-rw-r--r--core/fpdfapi/render/cpdf_rendercontext.cpp26
-rw-r--r--core/fpdfapi/render/cpdf_rendercontext.h8
-rw-r--r--core/fpdfapi/render/cpdf_renderstatus.cpp15
-rw-r--r--core/fpdfapi/render/cpdf_renderstatus.h3
15 files changed, 151 insertions, 188 deletions
diff --git a/core/fpdfapi/edit/cpdf_creator.h b/core/fpdfapi/edit/cpdf_creator.h
index aeb7d6675c..0840e4b7a6 100644
--- a/core/fpdfapi/edit/cpdf_creator.h
+++ b/core/fpdfapi/edit/cpdf_creator.h
@@ -8,6 +8,7 @@
#define CORE_FPDFAPI_EDIT_CPDF_CREATOR_H_
#include <memory>
+#include <vector>
#include "core/fxcrt/cfx_retain_ptr.h"
#include "core/fxcrt/fx_basic.h"
@@ -94,7 +95,7 @@ class CPDF_Creator {
FX_POSITION m_Pos;
FX_FILESIZE m_XrefStart;
CFX_FileSizeListArray m_ObjectOffset;
- CFX_ArrayTemplate<uint32_t> m_NewObjNumArray;
+ std::vector<uint32_t> m_NewObjNumArray; // Sorted, ascending.
std::unique_ptr<CPDF_Array> m_pIDArray;
int32_t m_FileVersion;
};
diff --git a/core/fpdfapi/edit/fpdf_edit_create.cpp b/core/fpdfapi/edit/fpdf_edit_create.cpp
index 7b38883ef8..fec0de9512 100644
--- a/core/fpdfapi/edit/fpdf_edit_create.cpp
+++ b/core/fpdfapi/edit/fpdf_edit_create.cpp
@@ -1313,11 +1313,12 @@ int32_t CPDF_Creator::WriteOldObjs(IFX_Pause* pPause) {
}
return 0;
}
+
int32_t CPDF_Creator::WriteNewObjs(bool bIncremental, IFX_Pause* pPause) {
- int32_t iCount = m_NewObjNumArray.GetSize();
- int32_t index = (int32_t)(uintptr_t)m_Pos;
+ size_t iCount = m_NewObjNumArray.size();
+ size_t index = (size_t)(uintptr_t)m_Pos;
while (index < iCount) {
- uint32_t objnum = m_NewObjNumArray.ElementAt(index);
+ uint32_t objnum = m_NewObjNumArray[index];
CPDF_Object* pObj = m_pDocument->GetIndirectObject(objnum);
if (!pObj) {
++index;
@@ -1335,6 +1336,7 @@ int32_t CPDF_Creator::WriteNewObjs(bool bIncremental, IFX_Pause* pPause) {
}
return 0;
}
+
void CPDF_Creator::InitOldObjNumOffsets() {
if (!m_pParser) {
return;
@@ -1373,15 +1375,15 @@ void CPDF_Creator::InitNewObjNumOffsets() {
AppendNewObjNum(objnum);
}
- int32_t iCount = m_NewObjNumArray.GetSize();
+ size_t iCount = m_NewObjNumArray.size();
if (iCount == 0)
return;
- int32_t i = 0;
+ size_t i = 0;
uint32_t dwStartObjNum = 0;
bool bCrossRefValid = m_pParser && m_pParser->GetLastXRefOffset() > 0;
while (i < iCount) {
- dwStartObjNum = m_NewObjNumArray.ElementAt(i);
+ dwStartObjNum = m_NewObjNumArray[i];
if ((bIncremental && (bNoOriginal || bCrossRefValid)) ||
!m_ObjectOffset.GetPtrAt(dwStartObjNum)) {
break;
@@ -1395,7 +1397,7 @@ void CPDF_Creator::InitNewObjNumOffsets() {
i++;
bool bNewStart = false;
for (; i < iCount; i++) {
- uint32_t dwCurObjNum = m_NewObjNumArray.ElementAt(i);
+ uint32_t dwCurObjNum = m_NewObjNumArray[i];
bool bExist = m_pParser && m_pParser->IsValidObjectNumber(dwCurObjNum) &&
m_ObjectOffset.GetPtrAt(dwCurObjNum);
if (bExist || dwCurObjNum - dwLastObjNum > 1) {
@@ -1412,29 +1414,12 @@ void CPDF_Creator::InitNewObjNumOffsets() {
m_ObjectOffset.Add(dwStartObjNum, dwLastObjNum - dwStartObjNum + 1);
}
-void CPDF_Creator::AppendNewObjNum(uint32_t objbum) {
- int32_t iStart = 0, iFind = 0;
- int32_t iEnd = m_NewObjNumArray.GetUpperBound();
- while (iStart <= iEnd) {
- int32_t iMid = (iStart + iEnd) / 2;
- uint32_t dwMid = m_NewObjNumArray.ElementAt(iMid);
- if (objbum < dwMid) {
- iEnd = iMid - 1;
- } else {
- if (iMid == iEnd) {
- iFind = iMid + 1;
- break;
- }
- uint32_t dwNext = m_NewObjNumArray.ElementAt(iMid + 1);
- if (objbum < dwNext) {
- iFind = iMid + 1;
- break;
- }
- iStart = iMid + 1;
- }
- }
- m_NewObjNumArray.InsertAt(iFind, objbum);
+void CPDF_Creator::AppendNewObjNum(uint32_t objnum) {
+ m_NewObjNumArray.insert(std::lower_bound(m_NewObjNumArray.begin(),
+ m_NewObjNumArray.end(), objnum),
+ objnum);
}
+
int32_t CPDF_Creator::WriteDoc_Stage1(IFX_Pause* pPause) {
ASSERT(m_iStage > -1 || m_iStage < 20);
if (m_iStage == 0) {
@@ -1565,15 +1550,14 @@ int32_t CPDF_Creator::WriteDoc_Stage2(IFX_Pause* pPause) {
if (m_pEncryptDict && m_pEncryptDict->IsInline()) {
m_dwLastObjNum += 1;
FX_FILESIZE saveOffset = m_Offset;
- if (WriteIndirectObj(m_dwLastObjNum, m_pEncryptDict) < 0) {
+ if (WriteIndirectObj(m_dwLastObjNum, m_pEncryptDict) < 0)
return -1;
- }
+
m_ObjectOffset.Add(m_dwLastObjNum, 1);
m_ObjectOffset[m_dwLastObjNum] = saveOffset;
m_dwEncryptObjNum = m_dwLastObjNum;
- if (m_dwFlags & FPDFCREATE_INCREMENTAL) {
- m_NewObjNumArray.Add(m_dwLastObjNum);
- }
+ if (m_dwFlags & FPDFCREATE_INCREMENTAL)
+ m_NewObjNumArray.push_back(m_dwLastObjNum);
}
m_iStage = 80;
}
@@ -1652,22 +1636,20 @@ int32_t CPDF_Creator::WriteDoc_Stage3(IFX_Pause* pPause) {
}
if (m_iStage == 82) {
CFX_ByteString str;
- int32_t iCount = m_NewObjNumArray.GetSize();
- int32_t i = (int32_t)(uintptr_t)m_Pos;
+ size_t iCount = m_NewObjNumArray.size();
+ size_t i = (size_t)(uintptr_t)m_Pos;
while (i < iCount) {
- int32_t j = i;
- uint32_t objnum = m_NewObjNumArray.ElementAt(i);
+ size_t j = i;
+ uint32_t objnum = m_NewObjNumArray[i];
while (j < iCount) {
- if (++j == iCount) {
+ if (++j == iCount)
break;
- }
- uint32_t dwCurrent = m_NewObjNumArray.ElementAt(j);
- if (dwCurrent - objnum > 1) {
+ uint32_t dwCurrent = m_NewObjNumArray[j];
+ if (dwCurrent - objnum > 1)
break;
- }
objnum = dwCurrent;
}
- objnum = m_NewObjNumArray.ElementAt(i);
+ objnum = m_NewObjNumArray[i];
if (objnum == 1) {
str.Format("0 %d\r\n0000000000 65535 f\r\n", j - i + 1);
} else {
@@ -1677,11 +1659,10 @@ int32_t CPDF_Creator::WriteDoc_Stage3(IFX_Pause* pPause) {
return -1;
}
while (i < j) {
- objnum = m_NewObjNumArray.ElementAt(i++);
+ objnum = m_NewObjNumArray[i++];
str.Format("%010d 00000 n\r\n", m_ObjectOffset[objnum]);
- if (m_File.AppendBlock(str.c_str(), str.GetLength()) < 0) {
+ if (m_File.AppendBlock(str.c_str(), str.GetLength()) < 0)
return -1;
- }
}
if (pPause && (i % 100) == 0 && pPause->NeedToPauseNow()) {
m_Pos = (void*)(uintptr_t)i;
@@ -1847,41 +1828,33 @@ int32_t CPDF_Creator::WriteDoc_Stage4(IFX_Pause* pPause) {
}
for (i = 0; i < m_dwLastObjNum; i++) {
FX_FILESIZE* offset = m_ObjectOffset.GetPtrAt(i);
- if (!offset) {
+ if (!offset)
continue;
- }
OutputIndex(&m_File, *offset);
}
} else {
- int count = m_NewObjNumArray.GetSize();
- int32_t i = 0;
+ size_t count = m_NewObjNumArray.size();
+ size_t i = 0;
for (i = 0; i < count; i++) {
- uint32_t objnum = m_NewObjNumArray.ElementAt(i);
- if (m_File.AppendDWord(objnum) < 0) {
+ if (m_File.AppendDWord(m_NewObjNumArray[i]) < 0)
return -1;
- }
- if (m_File.AppendString(" 1 ") < 0) {
+ if (m_File.AppendString(" 1 ") < 0)
return -1;
- }
}
- if (m_File.AppendString("]/Length ") < 0) {
+ if (m_File.AppendString("]/Length ") < 0)
return -1;
- }
- if (m_File.AppendDWord(count * 5) < 0) {
+ if (m_File.AppendDWord(count * 5) < 0)
return -1;
- }
- if (m_File.AppendString(">>stream\r\n") < 0) {
+ if (m_File.AppendString(">>stream\r\n") < 0)
return -1;
- }
for (i = 0; i < count; i++) {
- uint32_t objnum = m_NewObjNumArray.ElementAt(i);
+ uint32_t objnum = m_NewObjNumArray[i];
FX_FILESIZE offset = m_ObjectOffset[objnum];
OutputIndex(&m_File, offset);
}
}
- if (m_File.AppendString("\r\nendstream") < 0) {
+ if (m_File.AppendString("\r\nendstream") < 0)
return -1;
- }
}
}
if (m_File.AppendString("\r\nstartxref\r\n") < 0) {
@@ -1903,7 +1876,7 @@ int32_t CPDF_Creator::WriteDoc_Stage4(IFX_Pause* pPause) {
void CPDF_Creator::Clear() {
m_pXRefStream.reset();
m_File.Clear();
- m_NewObjNumArray.RemoveAll();
+ m_NewObjNumArray.clear();
m_pIDArray.reset();
}
@@ -1919,7 +1892,7 @@ bool CPDF_Creator::Create(uint32_t flags) {
m_Offset = 0;
m_dwLastObjNum = m_pDocument->GetLastObjNum();
m_ObjectOffset.Clear();
- m_NewObjNumArray.RemoveAll();
+ m_NewObjNumArray.clear();
InitID();
if (flags & FPDFCREATE_PROGRESSIVE)
return true;
diff --git a/core/fpdfapi/font/cpdf_cidfont.cpp b/core/fpdfapi/font/cpdf_cidfont.cpp
index 91df025e0f..c6c6992562 100644
--- a/core/fpdfapi/font/cpdf_cidfont.cpp
+++ b/core/fpdfapi/font/cpdf_cidfont.cpp
@@ -391,7 +391,7 @@ bool CPDF_CIDFont::Load() {
m_DefaultWidth = pCIDFontDict->GetIntegerFor("DW", 1000);
CPDF_Array* pWidthArray = pCIDFontDict->GetArrayFor("W");
if (pWidthArray)
- LoadMetricsArray(pWidthArray, m_WidthList, 1);
+ LoadMetricsArray(pWidthArray, &m_WidthList, 1);
if (!IsEmbedded())
LoadSubstFont();
@@ -416,7 +416,7 @@ bool CPDF_CIDFont::Load() {
if (IsVertWriting()) {
pWidthArray = pCIDFontDict->GetArrayFor("W2");
if (pWidthArray)
- LoadMetricsArray(pWidthArray, m_VertMetrics, 3);
+ LoadMetricsArray(pWidthArray, &m_VertMetrics, 3);
CPDF_Array* pDefaultArray = pCIDFontDict->GetArrayFor("DW2");
if (pDefaultArray) {
m_DefaultVY = pDefaultArray->GetIntegerAt(0);
@@ -505,9 +505,9 @@ int CPDF_CIDFont::GetCharWidthF(uint32_t charcode) {
return (charcode >= 32 && charcode < 127) ? 500 : 0;
uint16_t cid = CIDFromCharCode(charcode);
- int size = m_WidthList.GetSize();
- const uint32_t* pList = m_WidthList.GetData();
- for (int i = 0; i < size; i += 3) {
+ size_t size = m_WidthList.size();
+ const uint32_t* pList = m_WidthList.data();
+ for (size_t i = 0; i < size; i += 3) {
const uint32_t* pEntry = pList + i;
if (IsMetricForCID(pEntry, cid))
return static_cast<int>(pEntry[2]);
@@ -516,10 +516,10 @@ int CPDF_CIDFont::GetCharWidthF(uint32_t charcode) {
}
short CPDF_CIDFont::GetVertWidth(uint16_t CID) const {
- uint32_t vertsize = m_VertMetrics.GetSize() / 5;
+ size_t vertsize = m_VertMetrics.size() / 5;
if (vertsize) {
- const uint32_t* pTable = m_VertMetrics.GetData();
- for (uint32_t i = 0; i < vertsize; i++) {
+ const uint32_t* pTable = m_VertMetrics.data();
+ for (size_t i = 0; i < vertsize; i++) {
const uint32_t* pEntry = pTable + (i * 5);
if (IsMetricForCID(pEntry, CID))
return static_cast<short>(pEntry[2]);
@@ -529,10 +529,10 @@ short CPDF_CIDFont::GetVertWidth(uint16_t CID) const {
}
void CPDF_CIDFont::GetVertOrigin(uint16_t CID, short& vx, short& vy) const {
- uint32_t vertsize = m_VertMetrics.GetSize() / 5;
+ size_t vertsize = m_VertMetrics.size() / 5;
if (vertsize) {
- const uint32_t* pTable = m_VertMetrics.GetData();
- for (uint32_t i = 0; i < vertsize; i++) {
+ const uint32_t* pTable = m_VertMetrics.data();
+ for (size_t i = 0; i < vertsize; i++) {
const uint32_t* pEntry = pTable + (i * 5);
if (IsMetricForCID(pEntry, CID)) {
vx = static_cast<short>(pEntry[3]);
@@ -542,9 +542,9 @@ void CPDF_CIDFont::GetVertOrigin(uint16_t CID, short& vx, short& vy) const {
}
}
uint32_t dwWidth = m_DefaultWidth;
- int size = m_WidthList.GetSize();
- const uint32_t* pList = m_WidthList.GetData();
- for (int i = 0; i < size; i += 3) {
+ size_t size = m_WidthList.size();
+ const uint32_t* pList = m_WidthList.data();
+ for (size_t i = 0; i < size; i += 3) {
const uint32_t* pEntry = pList + i;
if (IsMetricForCID(pEntry, CID)) {
dwWidth = pEntry[2];
@@ -771,7 +771,7 @@ void CPDF_CIDFont::LoadSubstFont() {
}
void CPDF_CIDFont::LoadMetricsArray(CPDF_Array* pArray,
- CFX_ArrayTemplate<uint32_t>& result,
+ std::vector<uint32_t>* result,
int nElements) {
int width_status = 0;
int iCurElement = 0;
@@ -787,10 +787,10 @@ void CPDF_CIDFont::LoadMetricsArray(CPDF_Array* pArray,
return;
for (size_t j = 0; j < pObjArray->GetCount(); j += nElements) {
- result.Add(first_code);
- result.Add(first_code);
+ result->push_back(first_code);
+ result->push_back(first_code);
for (int k = 0; k < nElements; k++)
- result.Add(pObjArray->GetIntegerAt(j + k));
+ result->push_back(pObjArray->GetIntegerAt(j + k));
first_code++;
}
width_status = 0;
@@ -804,10 +804,10 @@ void CPDF_CIDFont::LoadMetricsArray(CPDF_Array* pArray,
iCurElement = 0;
} else {
if (!iCurElement) {
- result.Add(first_code);
- result.Add(last_code);
+ result->push_back(first_code);
+ result->push_back(last_code);
}
- result.Add(pObj->GetInteger());
+ result->push_back(pObj->GetInteger());
iCurElement++;
if (iCurElement == nElements)
width_status = 0;
diff --git a/core/fpdfapi/font/cpdf_cidfont.h b/core/fpdfapi/font/cpdf_cidfont.h
index a2d16ed14c..ae3be3908f 100644
--- a/core/fpdfapi/font/cpdf_cidfont.h
+++ b/core/fpdfapi/font/cpdf_cidfont.h
@@ -8,6 +8,7 @@
#define CORE_FPDFAPI_FONT_CPDF_CIDFONT_H_
#include <memory>
+#include <vector>
#include "core/fpdfapi/font/cpdf_font.h"
#include "core/fxcrt/fx_string.h"
@@ -65,7 +66,7 @@ class CPDF_CIDFont : public CPDF_Font {
int GetGlyphIndex(uint32_t unicodeb, bool* pVertGlyph);
int GetVerticalGlyph(int index, bool* pVertGlyph);
void LoadMetricsArray(CPDF_Array* pArray,
- CFX_ArrayTemplate<uint32_t>& result,
+ std::vector<uint32_t>* result,
int nElements);
void LoadSubstFont();
FX_WCHAR GetUnicodeFromCharCode(uint32_t charcode) const;
@@ -80,10 +81,10 @@ class CPDF_CIDFont : public CPDF_Font {
std::unique_ptr<CPDF_StreamAcc> m_pStreamAcc;
bool m_bAnsiWidthsFixed;
FX_RECT m_CharBBox[256];
- CFX_ArrayTemplate<uint32_t> m_WidthList;
+ std::vector<uint32_t> m_WidthList;
short m_DefaultVY;
short m_DefaultW1;
- CFX_ArrayTemplate<uint32_t> m_VertMetrics;
+ std::vector<uint32_t> m_VertMetrics;
bool m_bAdobeCourierStd;
std::unique_ptr<CFX_CTTGSUBTable> m_pTTGSUBTable;
};
diff --git a/core/fpdfapi/font/font_int.h b/core/fpdfapi/font/font_int.h
index 02131eb67c..2410741e53 100644
--- a/core/fpdfapi/font/font_int.h
+++ b/core/fpdfapi/font/font_int.h
@@ -9,6 +9,7 @@
#include <map>
#include <memory>
+#include <vector>
#include "core/fpdfapi/font/cpdf_cidfont.h"
#include "core/fxcrt/fx_basic.h"
@@ -107,7 +108,7 @@ class CPDF_CMapParser {
int m_Status;
int m_CodeSeq;
uint32_t m_CodePoints[4];
- CFX_ArrayTemplate<CMap_CodeRange> m_CodeRanges;
+ std::vector<CMap_CodeRange> m_CodeRanges;
CFX_ByteString m_LastWord;
};
diff --git a/core/fpdfapi/font/fpdf_font_cid.cpp b/core/fpdfapi/font/fpdf_font_cid.cpp
index 02f8f7f058..010c94ced2 100644
--- a/core/fpdfapi/font/fpdf_font_cid.cpp
+++ b/core/fpdfapi/font/fpdf_font_cid.cpp
@@ -15,6 +15,7 @@
#include "core/fpdfapi/parser/cpdf_simple_parser.h"
#include "core/fxcrt/fx_ext.h"
#include "core/fxge/fx_freetype.h"
+#include "third_party/base/stl_util.h"
namespace {
@@ -403,14 +404,14 @@ void CPDF_CMapParser::ParseWord(const CFX_ByteStringC& word) {
m_Status = 0;
} else if (m_Status == 7) {
if (word == "endcodespacerange") {
- int nSegs = m_CodeRanges.GetSize();
+ uint32_t nSegs = pdfium::CollectionSize<uint32_t>(m_CodeRanges);
if (nSegs > 1) {
m_pCMap->m_CodingScheme = CPDF_CMap::MixedFourBytes;
m_pCMap->m_nCodeRanges = nSegs;
FX_Free(m_pCMap->m_pLeadingBytes);
m_pCMap->m_pLeadingBytes =
FX_Alloc2D(uint8_t, nSegs, sizeof(CMap_CodeRange));
- FXSYS_memcpy(m_pCMap->m_pLeadingBytes, m_CodeRanges.GetData(),
+ FXSYS_memcpy(m_pCMap->m_pLeadingBytes, m_CodeRanges.data(),
nSegs * sizeof(CMap_CodeRange));
} else if (nSegs == 1) {
m_pCMap->m_CodingScheme = (m_CodeRanges[0].m_CharSize == 2)
@@ -424,9 +425,8 @@ void CPDF_CMapParser::ParseWord(const CFX_ByteStringC& word) {
}
if (m_CodeSeq % 2) {
CMap_CodeRange range;
- if (CMap_GetCodeRange(range, m_LastWord.AsStringC(), word)) {
- m_CodeRanges.Add(range);
- }
+ if (CMap_GetCodeRange(range, m_LastWord.AsStringC(), word))
+ m_CodeRanges.push_back(range);
}
m_CodeSeq++;
}
diff --git a/core/fpdfapi/parser/cpdf_data_avail.cpp b/core/fpdfapi/parser/cpdf_data_avail.cpp
index d94ef2c69c..4205ed2456 100644
--- a/core/fpdfapi/parser/cpdf_data_avail.cpp
+++ b/core/fpdfapi/parser/cpdf_data_avail.cpp
@@ -453,24 +453,21 @@ void CPDF_DataAvail::ResetFirstCheck(uint32_t dwPage) {
}
bool CPDF_DataAvail::CheckPage(DownloadHints* pHints) {
- uint32_t iPageObjs = m_PageObjList.GetSize();
- CFX_ArrayTemplate<uint32_t> UnavailObjList;
- for (uint32_t i = 0; i < iPageObjs; ++i) {
- uint32_t dwPageObjNum = m_PageObjList.GetAt(i);
- bool bExist = false;
+ std::vector<uint32_t> UnavailObjList;
+ for (uint32_t dwPageObjNum : m_PageObjList) {
+ bool bExists = false;
std::unique_ptr<CPDF_Object> pObj =
- GetObject(dwPageObjNum, pHints, &bExist);
+ GetObject(dwPageObjNum, pHints, &bExists);
if (!pObj) {
- if (bExist)
- UnavailObjList.Add(dwPageObjNum);
+ if (bExists)
+ UnavailObjList.push_back(dwPageObjNum);
continue;
}
-
CPDF_Array* pArray = ToArray(pObj.get());
if (pArray) {
for (const auto& pArrayObj : *pArray) {
if (CPDF_Reference* pRef = ToReference(pArrayObj.get()))
- UnavailObjList.Add(pRef->GetRefObjNum());
+ UnavailObjList.push_back(pRef->GetRefObjNum());
}
}
if (!pObj->IsDictionary())
@@ -482,15 +479,13 @@ bool CPDF_DataAvail::CheckPage(DownloadHints* pHints) {
continue;
}
}
-
- m_PageObjList.RemoveAll();
- if (UnavailObjList.GetSize()) {
- m_PageObjList.Append(UnavailObjList);
+ m_PageObjList.clear();
+ if (!UnavailObjList.empty()) {
+ m_PageObjList = std::move(UnavailObjList);
return false;
}
-
- uint32_t iPages = m_PagesArray.size();
- for (uint32_t i = 0; i < iPages; i++) {
+ size_t iPages = m_PagesArray.size();
+ for (size_t i = 0; i < iPages; ++i) {
std::unique_ptr<CPDF_Object> pPages = std::move(m_PagesArray[i]);
if (pPages && !GetPageKids(m_pCurrentParser, pPages.get())) {
m_PagesArray.clear();
@@ -499,7 +494,7 @@ bool CPDF_DataAvail::CheckPage(DownloadHints* pHints) {
}
}
m_PagesArray.clear();
- if (!m_PageObjList.GetSize())
+ if (m_PageObjList.empty())
m_docStatus = PDF_DATAAVAIL_DONE;
return true;
@@ -518,13 +513,13 @@ bool CPDF_DataAvail::GetPageKids(CPDF_Parser* pParser, CPDF_Object* pPages) {
switch (pKids->GetType()) {
case CPDF_Object::REFERENCE:
- m_PageObjList.Add(pKids->AsReference()->GetRefObjNum());
+ m_PageObjList.push_back(pKids->AsReference()->GetRefObjNum());
break;
case CPDF_Object::ARRAY: {
CPDF_Array* pKidsArray = pKids->AsArray();
for (size_t i = 0; i < pKidsArray->GetCount(); ++i) {
if (CPDF_Reference* pRef = ToReference(pKidsArray->GetObjectAt(i)))
- m_PageObjList.Add(pRef->GetRefObjNum());
+ m_PageObjList.push_back(pRef->GetRefObjNum());
}
} break;
default:
@@ -535,10 +530,10 @@ bool CPDF_DataAvail::GetPageKids(CPDF_Parser* pParser, CPDF_Object* pPages) {
}
bool CPDF_DataAvail::CheckPages(DownloadHints* pHints) {
- bool bExist = false;
+ bool bExists = false;
std::unique_ptr<CPDF_Object> pPages =
- GetObject(m_PagesObjNum, pHints, &bExist);
- if (!bExist) {
+ GetObject(m_PagesObjNum, pHints, &bExists);
+ if (!bExists) {
m_docStatus = PDF_DATAAVAIL_LOADALLFILE;
return true;
}
@@ -1121,9 +1116,9 @@ bool CPDF_DataAvail::CheckPage(uint32_t dwPage, DownloadHints* pHints) {
bool CPDF_DataAvail::CheckArrayPageNode(uint32_t dwPageNo,
PageNode* pPageNode,
DownloadHints* pHints) {
- bool bExist = false;
- std::unique_ptr<CPDF_Object> pPages = GetObject(dwPageNo, pHints, &bExist);
- if (!bExist) {
+ bool bExists = false;
+ std::unique_ptr<CPDF_Object> pPages = GetObject(dwPageNo, pHints, &bExists);
+ if (!bExists) {
m_docStatus = PDF_DATAAVAIL_ERROR;
return false;
}
@@ -1158,9 +1153,9 @@ bool CPDF_DataAvail::CheckArrayPageNode(uint32_t dwPageNo,
bool CPDF_DataAvail::CheckUnknownPageNode(uint32_t dwPageNo,
PageNode* pPageNode,
DownloadHints* pHints) {
- bool bExist = false;
- std::unique_ptr<CPDF_Object> pPage = GetObject(dwPageNo, pHints, &bExist);
- if (!bExist) {
+ bool bExists = false;
+ std::unique_ptr<CPDF_Object> pPage = GetObject(dwPageNo, pHints, &bExists);
+ if (!bExists) {
m_docStatus = PDF_DATAAVAIL_ERROR;
return false;
}
@@ -1292,14 +1287,13 @@ bool CPDF_DataAvail::LoadDocPage(uint32_t dwPage, DownloadHints* pHints) {
}
bool CPDF_DataAvail::CheckPageCount(DownloadHints* pHints) {
- bool bExist = false;
+ bool bExists = false;
std::unique_ptr<CPDF_Object> pPages =
- GetObject(m_PagesObjNum, pHints, &bExist);
- if (!bExist) {
+ GetObject(m_PagesObjNum, pHints, &bExists);
+ if (!bExists) {
m_docStatus = PDF_DATAAVAIL_ERROR;
return false;
}
-
if (!pPages)
return false;
@@ -1308,7 +1302,6 @@ bool CPDF_DataAvail::CheckPageCount(DownloadHints* pHints) {
m_docStatus = PDF_DATAAVAIL_ERROR;
return false;
}
-
if (!pPagesDict->KeyExist("Kids"))
return true;
diff --git a/core/fpdfapi/parser/cpdf_data_avail.h b/core/fpdfapi/parser/cpdf_data_avail.h
index 42013e93ec..65638cff0b 100644
--- a/core/fpdfapi/parser/cpdf_data_avail.h
+++ b/core/fpdfapi/parser/cpdf_data_avail.h
@@ -221,8 +221,8 @@ class CPDF_DataAvail final {
uint32_t m_bufferSize;
CFX_ByteString m_WordBuf;
uint8_t m_bufferData[512];
- CFX_ArrayTemplate<uint32_t> m_XRefStreamList;
- CFX_ArrayTemplate<uint32_t> m_PageObjList;
+ std::vector<uint32_t> m_XRefStreamList;
+ std::vector<uint32_t> m_PageObjList;
uint32_t m_PagesObjNum;
bool m_bLinearedDataOK;
bool m_bMainXRefLoadTried;
diff --git a/core/fpdfapi/parser/cpdf_document.cpp b/core/fpdfapi/parser/cpdf_document.cpp
index 4ac0aa6aa9..9e60aaa882 100644
--- a/core/fpdfapi/parser/cpdf_document.cpp
+++ b/core/fpdfapi/parser/cpdf_document.cpp
@@ -381,20 +381,20 @@ void CPDF_Document::LoadDocInternal() {
void CPDF_Document::LoadDoc() {
LoadDocInternal();
- m_PageList.SetSize(RetrievePageCount());
+ LoadPages();
}
void CPDF_Document::LoadLinearizedDoc(
const CPDF_LinearizedHeader* pLinearizationParams) {
m_bLinearized = true;
LoadDocInternal();
- m_PageList.SetSize(pLinearizationParams->GetPageCount());
+ m_PageList.resize(pLinearizationParams->GetPageCount());
m_iFirstPageNo = pLinearizationParams->GetFirstPageNo();
m_dwFirstPageObjNum = pLinearizationParams->GetFirstPageObjNum();
}
void CPDF_Document::LoadPages() {
- m_PageList.SetSize(RetrievePageCount());
+ m_PageList.resize(RetrievePageCount());
}
CPDF_Dictionary* CPDF_Document::TraversePDFPages(int iPage,
@@ -402,21 +402,20 @@ CPDF_Dictionary* CPDF_Document::TraversePDFPages(int iPage,
size_t level) {
if (*nPagesToGo < 0 || m_bReachedMaxPageLevel)
return nullptr;
+
CPDF_Dictionary* pPages = m_pTreeTraversal[level].first;
CPDF_Array* pKidList = pPages->GetArrayFor("Kids");
if (!pKidList) {
if (*nPagesToGo != 1)
return nullptr;
- m_PageList.SetAt(iPage, pPages->GetObjNum());
+ m_PageList[iPage] = pPages->GetObjNum();
return pPages;
}
-
if (level >= FX_MAX_PAGE_LEVEL) {
m_pTreeTraversal.pop_back();
m_bReachedMaxPageLevel = true;
return nullptr;
}
-
CPDF_Dictionary* page = nullptr;
for (size_t i = m_pTreeTraversal[level].second; i < pKidList->GetCount();
i++) {
@@ -433,7 +432,7 @@ CPDF_Dictionary* CPDF_Document::TraversePDFPages(int iPage,
continue;
}
if (!pKid->KeyExist("Kids")) {
- m_PageList.SetAt(iPage - (*nPagesToGo) + 1, pKid->GetObjNum());
+ m_PageList[iPage - (*nPagesToGo) + 1] = pKid->GetObjNum();
(*nPagesToGo)--;
m_pTreeTraversal[level].second++;
if (*nPagesToGo == 0) {
@@ -474,11 +473,11 @@ CPDF_Dictionary* CPDF_Document::GetPagesDict() const {
}
bool CPDF_Document::IsPageLoaded(int iPage) const {
- return !!m_PageList.GetAt(iPage);
+ return !!m_PageList[iPage];
}
CPDF_Dictionary* CPDF_Document::GetPage(int iPage) {
- if (iPage < 0 || iPage >= m_PageList.GetSize())
+ if (iPage < 0 || iPage >= pdfium::CollectionSize<int>(m_PageList))
return nullptr;
if (m_bLinearized && (iPage == m_iFirstPageNo)) {
@@ -487,13 +486,9 @@ CPDF_Dictionary* CPDF_Document::GetPage(int iPage) {
return pDict;
}
}
-
- int objnum = m_PageList.GetAt(iPage);
- if (objnum) {
- if (CPDF_Dictionary* pDict = ToDictionary(GetOrParseIndirectObject(objnum)))
- return pDict;
- return nullptr;
- }
+ uint32_t objnum = m_PageList[iPage];
+ if (objnum)
+ return ToDictionary(GetOrParseIndirectObject(objnum));
CPDF_Dictionary* pPages = GetPagesDict();
if (!pPages)
@@ -517,7 +512,7 @@ CPDF_Dictionary* CPDF_Document::GetPage(int iPage) {
}
void CPDF_Document::SetPageObjNum(int iPage, uint32_t objNum) {
- m_PageList.SetAt(iPage, objNum);
+ m_PageList[iPage] = objNum;
}
int CPDF_Document::FindPageIndex(CPDF_Dictionary* pNode,
@@ -554,7 +549,7 @@ int CPDF_Document::FindPageIndex(CPDF_Dictionary* pNode,
for (size_t i = 0; i < count; i++) {
if (CPDF_Reference* pKid = ToReference(pKidList->GetObjectAt(i))) {
if (pKid->GetRefObjNum() == objnum) {
- m_PageList.SetAt(index + i, objnum);
+ m_PageList[index + i] = objnum;
return static_cast<int>(index + i);
}
}
@@ -574,15 +569,14 @@ int CPDF_Document::FindPageIndex(CPDF_Dictionary* pNode,
}
int CPDF_Document::GetPageIndex(uint32_t objnum) {
- uint32_t nPages = m_PageList.GetSize();
+ uint32_t nPages = m_PageList.size();
uint32_t skip_count = 0;
bool bSkipped = false;
for (uint32_t i = 0; i < nPages; i++) {
- uint32_t objnum1 = m_PageList.GetAt(i);
- if (objnum1 == objnum)
+ if (m_PageList[i] == objnum)
return i;
- if (!bSkipped && objnum1 == 0) {
+ if (!bSkipped && m_PageList[i] == 0) {
skip_count = i;
bSkipped = true;
}
@@ -596,7 +590,7 @@ int CPDF_Document::GetPageIndex(uint32_t objnum) {
}
int CPDF_Document::GetPageCount() const {
- return m_PageList.GetSize();
+ return pdfium::CollectionSize<int>(m_PageList);
}
int CPDF_Document::RetrievePageCount() const {
@@ -747,7 +741,7 @@ bool CPDF_Document::InsertNewPage(int iPage, CPDF_Dictionary* pPageDict) {
if (!InsertDeletePDFPage(pPages, iPage, pPageDict, true, &stack))
return false;
}
- m_PageList.InsertAt(iPage, pPageDict->GetObjNum());
+ m_PageList.insert(m_PageList.begin() + iPage, pPageDict->GetObjNum());
return true;
}
@@ -764,7 +758,7 @@ void CPDF_Document::DeletePage(int iPage) {
if (!InsertDeletePDFPage(pPages, iPage, nullptr, false, &stack))
return;
- m_PageList.RemoveAt(iPage);
+ m_PageList.erase(m_PageList.begin() + iPage);
}
CPDF_Font* CPDF_Document::AddStandardFont(const FX_CHAR* font,
diff --git a/core/fpdfapi/parser/cpdf_document.h b/core/fpdfapi/parser/cpdf_document.h
index 0da6577360..65455480a4 100644
--- a/core/fpdfapi/parser/cpdf_document.h
+++ b/core/fpdfapi/parser/cpdf_document.h
@@ -147,7 +147,7 @@ class CPDF_Document : public CPDF_IndirectObjectHolder {
std::unique_ptr<CPDF_DocRenderData> m_pDocRender;
std::unique_ptr<JBig2_DocumentContext> m_pCodecContext;
std::unique_ptr<CPDF_LinkList> m_pLinksContext;
- CFX_ArrayTemplate<uint32_t> m_PageList;
+ std::vector<uint32_t> m_PageList;
};
#endif // CORE_FPDFAPI_PARSER_CPDF_DOCUMENT_H_
diff --git a/core/fpdfapi/parser/cpdf_document_unittest.cpp b/core/fpdfapi/parser/cpdf_document_unittest.cpp
index 91beba3a6b..4815ffba52 100644
--- a/core/fpdfapi/parser/cpdf_document_unittest.cpp
+++ b/core/fpdfapi/parser/cpdf_document_unittest.cpp
@@ -88,7 +88,7 @@ class CPDF_TestDocumentForPages : public CPDF_Document {
m_pOwnedRootDict->SetNewFor<CPDF_Reference>("Pages", this,
pagesDict->GetObjNum());
m_pRootDict = m_pOwnedRootDict.get();
- m_PageList.SetSize(7);
+ m_PageList.resize(7);
}
private:
@@ -112,7 +112,7 @@ class CPDF_TestDocumentWithPageWithoutPageNum : public CPDF_Document {
m_pOwnedRootDict->SetNewFor<CPDF_Reference>("Pages", this,
pagesDict->GetObjNum());
m_pRootDict = m_pOwnedRootDict.get();
- m_PageList.SetSize(3);
+ m_PageList.resize(3);
}
private:
diff --git a/core/fpdfapi/render/cpdf_rendercontext.cpp b/core/fpdfapi/render/cpdf_rendercontext.cpp
index 2efdb81f8a..d74f729858 100644
--- a/core/fpdfapi/render/cpdf_rendercontext.cpp
+++ b/core/fpdfapi/render/cpdf_rendercontext.cpp
@@ -44,12 +44,12 @@ void CPDF_RenderContext::GetBackground(CFX_DIBitmap* pBuffer,
void CPDF_RenderContext::AppendLayer(CPDF_PageObjectHolder* pObjectHolder,
const CFX_Matrix* pObject2Device) {
- Layer* pLayer = m_Layers.AddSpace();
- pLayer->m_pObjectHolder = pObjectHolder;
+ m_Layers.emplace_back();
+ m_Layers.back().m_pObjectHolder = pObjectHolder;
if (pObject2Device)
- pLayer->m_Matrix = *pObject2Device;
+ m_Layers.back().m_Matrix = *pObject2Device;
else
- pLayer->m_Matrix.SetIdentity();
+ m_Layers.back().m_Matrix.SetIdentity();
}
void CPDF_RenderContext::Render(CFX_RenderDevice* pDevice,
@@ -62,18 +62,16 @@ void CPDF_RenderContext::Render(CFX_RenderDevice* pDevice,
const CPDF_PageObject* pStopObj,
const CPDF_RenderOptions* pOptions,
const CFX_Matrix* pLastMatrix) {
- int count = m_Layers.GetSize();
- for (int j = 0; j < count; j++) {
+ for (auto& layer : m_Layers) {
pDevice->SaveState();
- Layer* pLayer = m_Layers.GetDataPtr(j);
if (pLastMatrix) {
- CFX_Matrix FinalMatrix = pLayer->m_Matrix;
+ CFX_Matrix FinalMatrix = layer.m_Matrix;
FinalMatrix.Concat(*pLastMatrix);
CPDF_RenderStatus status;
status.Initialize(this, pDevice, pLastMatrix, pStopObj, nullptr, nullptr,
- pOptions, pLayer->m_pObjectHolder->m_Transparency,
- false, nullptr);
- status.RenderObjectList(pLayer->m_pObjectHolder, &FinalMatrix);
+ pOptions, layer.m_pObjectHolder->m_Transparency, false,
+ nullptr);
+ status.RenderObjectList(layer.m_pObjectHolder, &FinalMatrix);
if (status.m_Options.m_Flags & RENDER_LIMITEDIMAGECACHE)
m_pPageCache->CacheOptimization(status.m_Options.m_dwLimitCacheSize);
if (status.m_bStopped) {
@@ -83,9 +81,9 @@ void CPDF_RenderContext::Render(CFX_RenderDevice* pDevice,
} else {
CPDF_RenderStatus status;
status.Initialize(this, pDevice, nullptr, pStopObj, nullptr, nullptr,
- pOptions, pLayer->m_pObjectHolder->m_Transparency,
- false, nullptr);
- status.RenderObjectList(pLayer->m_pObjectHolder, &pLayer->m_Matrix);
+ pOptions, layer.m_pObjectHolder->m_Transparency, false,
+ nullptr);
+ status.RenderObjectList(layer.m_pObjectHolder, &layer.m_Matrix);
if (status.m_Options.m_Flags & RENDER_LIMITEDIMAGECACHE)
m_pPageCache->CacheOptimization(status.m_Options.m_dwLimitCacheSize);
if (status.m_bStopped) {
diff --git a/core/fpdfapi/render/cpdf_rendercontext.h b/core/fpdfapi/render/cpdf_rendercontext.h
index 676b89a4f4..a9fd2db78b 100644
--- a/core/fpdfapi/render/cpdf_rendercontext.h
+++ b/core/fpdfapi/render/cpdf_rendercontext.h
@@ -7,6 +7,8 @@
#ifndef CORE_FPDFAPI_RENDER_CPDF_RENDERCONTEXT_H_
#define CORE_FPDFAPI_RENDER_CPDF_RENDERCONTEXT_H_
+#include <vector>
+
#include "core/fxcrt/fx_basic.h"
#include "core/fxcrt/fx_coordinates.h"
@@ -50,8 +52,8 @@ class CPDF_RenderContext {
const CPDF_RenderOptions* pOptions,
CFX_Matrix* pFinalMatrix);
- uint32_t CountLayers() const { return m_Layers.GetSize(); }
- Layer* GetLayer(uint32_t index) { return m_Layers.GetDataPtr(index); }
+ size_t CountLayers() const { return m_Layers.size(); }
+ Layer* GetLayer(uint32_t index) { return &m_Layers[index]; }
CPDF_Document* GetDocument() const { return m_pDocument; }
CPDF_Dictionary* GetPageResources() const { return m_pPageResources; }
@@ -61,7 +63,7 @@ class CPDF_RenderContext {
CPDF_Document* const m_pDocument;
CPDF_Dictionary* m_pPageResources;
CPDF_PageRenderCache* m_pPageCache;
- CFX_ArrayTemplate<Layer> m_Layers;
+ std::vector<Layer> m_Layers;
};
#endif // CORE_FPDFAPI_RENDER_CPDF_RENDERCONTEXT_H_
diff --git a/core/fpdfapi/render/cpdf_renderstatus.cpp b/core/fpdfapi/render/cpdf_renderstatus.cpp
index 01026f44a9..35d061616b 100644
--- a/core/fpdfapi/render/cpdf_renderstatus.cpp
+++ b/core/fpdfapi/render/cpdf_renderstatus.cpp
@@ -55,6 +55,7 @@
#include "core/fxge/ifx_renderdevicedriver.h"
#include "third_party/base/numerics/safe_math.h"
#include "third_party/base/ptr_util.h"
+#include "third_party/base/stl_util.h"
#ifdef _SKIA_SUPPORT_
#include "core/fxge/skia/fx_skia_device.h"
@@ -1782,10 +1783,8 @@ CPDF_Type3Cache* CPDF_RenderStatus::GetCachedType3(CPDF_Type3Font* pFont) {
bool CPDF_RenderStatus::ProcessType3Text(CPDF_TextObject* textobj,
const CFX_Matrix* pObj2Device) {
CPDF_Type3Font* pType3Font = textobj->m_TextState.GetFont()->AsType3Font();
- for (int i = 0; i < m_Type3FontCache.GetSize(); ++i) {
- if (m_Type3FontCache.GetAt(i) == pType3Font)
- return true;
- }
+ if (pdfium::ContainsValue(m_Type3FontCache, pType3Font))
+ return true;
CFX_Matrix dCTM = m_pDevice->GetCTM();
FX_FLOAT sa = FXSYS_fabs(dCTM.a);
@@ -1851,8 +1850,8 @@ bool CPDF_RenderStatus::ProcessType3Text(CPDF_TextObject* textobj,
pStates, &Options,
pType3Char->m_pForm->m_Transparency, m_bDropObjects,
pFormResource, false, pType3Char, fill_argb);
- status.m_Type3FontCache.Append(m_Type3FontCache);
- status.m_Type3FontCache.Add(pType3Font);
+ status.m_Type3FontCache = m_Type3FontCache;
+ status.m_Type3FontCache.push_back(pType3Font);
m_pDevice->SaveState();
status.RenderObjectList(pType3Char->m_pForm.get(), &matrix);
m_pDevice->RestoreState(false);
@@ -1872,8 +1871,8 @@ bool CPDF_RenderStatus::ProcessType3Text(CPDF_TextObject* textobj,
pStates, &Options,
pType3Char->m_pForm->m_Transparency, m_bDropObjects,
pFormResource, false, pType3Char, fill_argb);
- status.m_Type3FontCache.Append(m_Type3FontCache);
- status.m_Type3FontCache.Add(pType3Font);
+ status.m_Type3FontCache = m_Type3FontCache;
+ status.m_Type3FontCache.push_back(pType3Font);
matrix.TranslateI(-rect.left, -rect.top);
matrix.Scale(sa, sd);
status.RenderObjectList(pType3Char->m_pForm.get(), &matrix);
diff --git a/core/fpdfapi/render/cpdf_renderstatus.h b/core/fpdfapi/render/cpdf_renderstatus.h
index abc8458d9e..25ddfb06c3 100644
--- a/core/fpdfapi/render/cpdf_renderstatus.h
+++ b/core/fpdfapi/render/cpdf_renderstatus.h
@@ -8,6 +8,7 @@
#define CORE_FPDFAPI_RENDER_CPDF_RENDERSTATUS_H_
#include <memory>
+#include <vector>
#include "core/fpdfapi/page/cpdf_clippath.h"
#include "core/fpdfapi/page/cpdf_graphicstates.h"
@@ -69,7 +70,7 @@ class CPDF_RenderStatus {
CPDF_RenderOptions m_Options;
CPDF_Dictionary* m_pFormResource;
CPDF_Dictionary* m_pPageResource;
- CFX_ArrayTemplate<CPDF_Type3Font*> m_Type3FontCache;
+ std::vector<CPDF_Type3Font*> m_Type3FontCache;
private:
friend class CPDF_ImageRenderer;