summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/include/fxcrt/fx_basic.h2
-rw-r--r--core/src/fpdftext/fpdf_text.cpp45
-rw-r--r--core/src/fpdftext/fpdf_text_int.cpp113
-rw-r--r--core/src/fpdftext/text_int.h5
-rw-r--r--fpdfsdk/include/fsdk_mgr.h7
-rw-r--r--fpdfsdk/src/fpdfppo.cpp22
6 files changed, 92 insertions, 102 deletions
diff --git a/core/include/fxcrt/fx_basic.h b/core/include/fxcrt/fx_basic.h
index 449889efa0..7179abef05 100644
--- a/core/include/fxcrt/fx_basic.h
+++ b/core/include/fxcrt/fx_basic.h
@@ -435,10 +435,10 @@ class CFX_ArrayTemplate : public CFX_BasicArray {
return -1;
}
};
-typedef CFX_ArrayTemplate<FX_WORD> CFX_WordArray;
typedef CFX_ArrayTemplate<FX_DWORD> CFX_DWordArray;
typedef CFX_ArrayTemplate<void*> CFX_PtrArray;
#ifdef PDF_ENABLE_XFA
+typedef CFX_ArrayTemplate<FX_WORD> CFX_WordArray;
typedef CFX_ArrayTemplate<FX_FLOAT> CFX_FloatArray;
typedef CFX_ArrayTemplate<uint8_t> CFX_ByteArray;
typedef CFX_ArrayTemplate<int32_t> CFX_Int32Array;
diff --git a/core/src/fpdftext/fpdf_text.cpp b/core/src/fpdftext/fpdf_text.cpp
index 4653fa63fa..c052676a19 100644
--- a/core/src/fpdftext/fpdf_text.cpp
+++ b/core/src/fpdftext/fpdf_text.cpp
@@ -7,6 +7,7 @@
#include <cctype>
#include <cwctype>
#include <memory>
+#include <vector>
#include "core/include/fpdfapi/fpdf_page.h"
#include "core/include/fpdfapi/fpdf_pageobj.h"
@@ -16,6 +17,7 @@
#include "core/include/fxcrt/fx_ucd.h"
#include "core/src/fpdftext/text_int.h"
#include "core/src/fpdftext/txtproc.h"
+#include "third_party/base/stl_util.h"
CFX_ByteString CharFromUnicodeAlt(FX_WCHAR unicode,
int destcp,
@@ -309,22 +311,23 @@ void NormalizeCompositeChar(FX_WCHAR wChar, CFX_WideString& sDest) {
}
delete[] pDst;
}
+
void NormalizeString(CFX_WideString& str) {
if (str.GetLength() <= 0) {
return;
}
CFX_WideString sBuffer;
std::unique_ptr<CFX_BidiChar> pBidiChar(new CFX_BidiChar);
- CFX_WordArray order;
+ std::vector<FX_WORD> order;
FX_BOOL bR2L = FALSE;
int32_t start = 0, count = 0, i = 0;
int nR2L = 0, nL2R = 0;
for (i = 0; i < str.GetLength(); i++) {
if (pBidiChar->AppendChar(str.GetAt(i))) {
CFX_BidiChar::Direction ret = pBidiChar->GetBidiInfo(&start, &count);
- order.Add(start);
- order.Add(count);
- order.Add(ret);
+ order.push_back(start);
+ order.push_back(count);
+ order.push_back(ret);
if (!bR2L) {
if (ret == CFX_BidiChar::RIGHT) {
nR2L++;
@@ -336,9 +339,9 @@ void NormalizeString(CFX_WideString& str) {
}
if (pBidiChar->EndChar()) {
CFX_BidiChar::Direction ret = pBidiChar->GetBidiInfo(&start, &count);
- order.Add(start);
- order.Add(count);
- order.Add(ret);
+ order.push_back(start);
+ order.push_back(count);
+ order.push_back(ret);
if (!bR2L) {
if (ret == CFX_BidiChar::RIGHT) {
nR2L++;
@@ -351,11 +354,11 @@ void NormalizeString(CFX_WideString& str) {
bR2L = TRUE;
}
if (bR2L) {
- int count = order.GetSize();
+ int count = pdfium::CollectionSize<int>(order);
for (int j = count - 1; j > 0; j -= 3) {
- int ret = order.GetAt(j);
- int start = order.GetAt(j - 2);
- int count1 = order.GetAt(j - 1);
+ int ret = order[j];
+ int count1 = order[j - 1];
+ int start = order[j - 2];
if (ret == 2 || ret == 0) {
for (int i = start + count1 - 1; i >= start; i--) {
NormalizeCompositeChar(str[i], sBuffer);
@@ -363,8 +366,8 @@ void NormalizeString(CFX_WideString& str) {
} else {
i = j;
FX_BOOL bSymbol = FALSE;
- while (i > 0 && order.GetAt(i) != 2) {
- bSymbol = !order.GetAt(i);
+ while (i > 0 && order[i] != 2) {
+ bSymbol = !order[i];
i -= 3;
}
int end = start + count1;
@@ -382,8 +385,8 @@ void NormalizeString(CFX_WideString& str) {
i = j;
j = n;
for (; n <= i; n += 3) {
- int start = order.GetAt(n - 2);
- int count1 = order.GetAt(n - 1);
+ int start = order[n - 2];
+ int count1 = order[n - 1];
int end = start + count1;
for (int m = start; m < end; m++) {
sBuffer += str[m];
@@ -393,16 +396,16 @@ void NormalizeString(CFX_WideString& str) {
}
}
} else {
- int count = order.GetSize();
+ int count = pdfium::CollectionSize<int>(order);
FX_BOOL bL2R = FALSE;
for (int j = 0; j < count; j += 3) {
- int ret = order.GetAt(j + 2);
- int start = order.GetAt(j);
- int count1 = order.GetAt(j + 1);
+ int start = order[j];
+ int count1 = order[j + 1];
+ int ret = order[j + 2];
if (ret == 2 || (j == 0 && ret == 0 && !bL2R)) {
int i = j + 3;
while (bR2L && i < count) {
- if (order.GetAt(i + 2) == 1) {
+ if (order[i + 2] == 1) {
break;
} else {
i += 3;
@@ -415,7 +418,7 @@ void NormalizeString(CFX_WideString& str) {
}
int end = str.GetLength() - 1;
if (i < count) {
- end = order.GetAt(i) - 1;
+ end = order[i] - 1;
}
j = i - 3;
for (int n = end; n >= start; n--) {
diff --git a/core/src/fpdftext/fpdf_text_int.cpp b/core/src/fpdftext/fpdf_text_int.cpp
index 66d20aff08..ede5f83616 100644
--- a/core/src/fpdftext/fpdf_text_int.cpp
+++ b/core/src/fpdftext/fpdf_text_int.cpp
@@ -144,13 +144,13 @@ FX_BOOL CPDF_TextPage::ParseTextPage() {
m_pPreTextObj = NULL;
ProcessObject();
m_bIsParsed = true;
- m_CharIndex.RemoveAll();
+ m_CharIndex.clear();
int nCount = pdfium::CollectionSize<int>(m_CharList);
if (nCount) {
- m_CharIndex.Add(0);
+ m_CharIndex.push_back(0);
}
for (int i = 0; i < nCount; i++) {
- int indexSize = m_CharIndex.GetSize();
+ int indexSize = pdfium::CollectionSize<int>(m_CharIndex);
FX_BOOL bNormal = FALSE;
const PAGECHAR_INFO& charinfo = m_CharList[i];
if (charinfo.m_Flag == FPDFTEXT_CHAR_GENERATED) {
@@ -162,27 +162,27 @@ FX_BOOL CPDF_TextPage::ParseTextPage() {
}
if (bNormal) {
if (indexSize % 2) {
- m_CharIndex.Add(1);
+ m_CharIndex.push_back(1);
} else {
if (indexSize <= 0) {
continue;
}
- m_CharIndex.SetAt(indexSize - 1, m_CharIndex.GetAt(indexSize - 1) + 1);
+ m_CharIndex[indexSize - 1] += 1;
}
} else {
if (indexSize % 2) {
if (indexSize <= 0) {
continue;
}
- m_CharIndex.SetAt(indexSize - 1, i + 1);
+ m_CharIndex[indexSize - 1] = i + 1;
} else {
- m_CharIndex.Add(i + 1);
+ m_CharIndex.push_back(i + 1);
}
}
}
- int indexSize = m_CharIndex.GetSize();
+ int indexSize = pdfium::CollectionSize<int>(m_CharIndex);
if (indexSize % 2) {
- m_CharIndex.RemoveAt(indexSize - 1);
+ m_CharIndex.erase(m_CharIndex.begin() + indexSize - 1);
}
return TRUE;
}
@@ -190,28 +190,25 @@ int CPDF_TextPage::CountChars() const {
return pdfium::CollectionSize<int>(m_CharList);
}
int CPDF_TextPage::CharIndexFromTextIndex(int TextIndex) const {
- int indexSize = m_CharIndex.GetSize();
+ int indexSize = pdfium::CollectionSize<int>(m_CharIndex);
int count = 0;
for (int i = 0; i < indexSize; i += 2) {
- count += m_CharIndex.GetAt(i + 1);
- if (count > TextIndex) {
- return TextIndex - count + m_CharIndex.GetAt(i + 1) +
- m_CharIndex.GetAt(i);
- }
+ count += m_CharIndex[i + 1];
+ if (count > TextIndex)
+ return TextIndex - count + m_CharIndex[i + 1] + m_CharIndex[i];
}
return -1;
}
int CPDF_TextPage::TextIndexFromCharIndex(int CharIndex) const {
- int indexSize = m_CharIndex.GetSize();
+ int indexSize = pdfium::CollectionSize<int>(m_CharIndex);
int count = 0;
for (int i = 0; i < indexSize; i += 2) {
- count += m_CharIndex.GetAt(i + 1);
- if (m_CharIndex.GetAt(i + 1) + m_CharIndex.GetAt(i) > CharIndex) {
- if (CharIndex - m_CharIndex.GetAt(i) < 0) {
+ count += m_CharIndex[i + 1];
+ if (m_CharIndex[i + 1] + m_CharIndex[i] > CharIndex) {
+ if (CharIndex - m_CharIndex[i] < 0)
return -1;
- }
- return CharIndex - m_CharIndex.GetAt(i) + count -
- m_CharIndex.GetAt(i + 1);
+
+ return CharIndex - m_CharIndex[i] + count - m_CharIndex[i + 1];
}
}
return -1;
@@ -993,7 +990,7 @@ void CPDF_TextPage::CloseTempLine() {
}
std::unique_ptr<CFX_BidiChar> pBidiChar(new CFX_BidiChar);
CFX_WideString str = m_TempTextBuf.GetWideString();
- CFX_WordArray order;
+ std::vector<FX_WORD> order;
FX_BOOL bR2L = FALSE;
int32_t start = 0, count = 0;
int nR2L = 0, nL2R = 0;
@@ -1013,9 +1010,9 @@ void CPDF_TextPage::CloseTempLine() {
}
if (pBidiChar->AppendChar(str.GetAt(i))) {
CFX_BidiChar::Direction ret = pBidiChar->GetBidiInfo(&start, &count);
- order.Add(start);
- order.Add(count);
- order.Add(ret);
+ order.push_back(start);
+ order.push_back(count);
+ order.push_back(ret);
if (!bR2L) {
if (ret == CFX_BidiChar::RIGHT) {
nR2L++;
@@ -1027,9 +1024,9 @@ void CPDF_TextPage::CloseTempLine() {
}
if (pBidiChar->EndChar()) {
CFX_BidiChar::Direction ret = pBidiChar->GetBidiInfo(&start, &count);
- order.Add(start);
- order.Add(count);
- order.Add(ret);
+ order.push_back(start);
+ order.push_back(count);
+ order.push_back(ret);
if (!bR2L) {
if (ret == CFX_BidiChar::RIGHT) {
nR2L++;
@@ -1042,11 +1039,11 @@ void CPDF_TextPage::CloseTempLine() {
bR2L = TRUE;
}
if (m_parserflag == FPDFTEXT_RLTB || bR2L) {
- int count = order.GetSize();
+ int count = pdfium::CollectionSize<int>(order);
for (int i = count - 1; i > 0; i -= 3) {
- int ret = order.GetAt(i);
- int start = order.GetAt(i - 2);
- int count1 = order.GetAt(i - 1);
+ int ret = order[i];
+ int count1 = order[i - 1];
+ int start = order[i - 2];
if (ret == 2 || ret == 0) {
for (int j = start + count1 - 1; j >= start; j--) {
AddCharInfoByRLDirection(str, j);
@@ -1054,8 +1051,8 @@ void CPDF_TextPage::CloseTempLine() {
} else {
int j = i;
FX_BOOL bSymbol = FALSE;
- while (j > 0 && order.GetAt(j) != 2) {
- bSymbol = !order.GetAt(j);
+ while (j > 0 && order[j] != 2) {
+ bSymbol = !order[j];
j -= 3;
}
int end = start + count1;
@@ -1073,8 +1070,8 @@ void CPDF_TextPage::CloseTempLine() {
j = i;
i = n;
for (; n <= j; n += 3) {
- int start = order.GetAt(n - 2);
- int count1 = order.GetAt(n - 1);
+ int start = order[n - 2];
+ int count1 = order[n - 1];
int end = start + count1;
for (int m = start; m < end; m++) {
AddCharInfoByLRDirection(str, m);
@@ -1084,20 +1081,18 @@ void CPDF_TextPage::CloseTempLine() {
}
}
} else {
- int count = order.GetSize();
+ int count = pdfium::CollectionSize<int>(order);
FX_BOOL bL2R = FALSE;
for (int i = 0; i < count; i += 3) {
- int ret = order.GetAt(i + 2);
- int start = order.GetAt(i);
- int count1 = order.GetAt(i + 1);
+ int start = order[i];
+ int count1 = order[i + 1];
+ int ret = order[i + 2];
if (ret == 2 || (i == 0 && ret == 0 && !bL2R)) {
int j = i + 3;
while (bR2L && j < count) {
- if (order.GetAt(j + 2) == 1) {
+ if (order[j + 2] == 1)
break;
- } else {
- j += 3;
- }
+ j += 3;
}
if (j == 3) {
i = -3;
@@ -1106,7 +1101,7 @@ void CPDF_TextPage::CloseTempLine() {
}
int end = pdfium::CollectionSize<int>(m_TempCharList) - 1;
if (j < count) {
- end = order.GetAt(j) - 1;
+ end = order[j] - 1;
}
i = j - 3;
for (int n = end; n >= start; n--) {
@@ -1120,7 +1115,6 @@ void CPDF_TextPage::CloseTempLine() {
}
}
}
- order.RemoveAll();
m_TempCharList.clear();
m_TempTextBuf.Delete(0, m_TempTextBuf.GetLength());
}
@@ -2035,48 +2029,39 @@ CPDF_TextPageFind::CPDF_TextPageFind(const IPDF_TextPage* pTextPage)
m_strText = m_pTextPage->GetPageText();
int nCount = pTextPage->CountChars();
if (nCount) {
- m_CharIndex.Add(0);
+ m_CharIndex.push_back(0);
}
for (int i = 0; i < nCount; i++) {
FPDF_CHAR_INFO info;
pTextPage->GetCharInfo(i, &info);
- int indexSize = m_CharIndex.GetSize();
+ int indexSize = pdfium::CollectionSize<int>(m_CharIndex);
if (info.m_Flag == CHAR_NORMAL || info.m_Flag == CHAR_GENERATED) {
if (indexSize % 2) {
- m_CharIndex.Add(1);
+ m_CharIndex.push_back(1);
} else {
if (indexSize <= 0) {
continue;
}
- m_CharIndex.SetAt(indexSize - 1, m_CharIndex.GetAt(indexSize - 1) + 1);
+ m_CharIndex[indexSize - 1] += 1;
}
} else {
if (indexSize % 2) {
if (indexSize <= 0) {
continue;
}
- m_CharIndex.SetAt(indexSize - 1, i + 1);
+ m_CharIndex[indexSize - 1] = i + 1;
} else {
- m_CharIndex.Add(i + 1);
+ m_CharIndex.push_back(i + 1);
}
}
}
- int indexSize = m_CharIndex.GetSize();
+ int indexSize = pdfium::CollectionSize<int>(m_CharIndex);
if (indexSize % 2) {
- m_CharIndex.RemoveAt(indexSize - 1);
+ m_CharIndex.erase(m_CharIndex.begin() + indexSize - 1);
}
}
int CPDF_TextPageFind::GetCharIndex(int index) const {
return m_pTextPage->CharIndexFromTextIndex(index);
- int indexSize = m_CharIndex.GetSize();
- int count = 0;
- for (int i = 0; i < indexSize; i += 2) {
- count += m_CharIndex.GetAt(i + 1);
- if (count > index) {
- return index - count + m_CharIndex.GetAt(i + 1) + m_CharIndex.GetAt(i);
- }
- }
- return -1;
}
FX_BOOL CPDF_TextPageFind::FindFirst(const CFX_WideString& findwhat,
int flags,
diff --git a/core/src/fpdftext/text_int.h b/core/src/fpdftext/text_int.h
index 8a803261e9..c420bc7702 100644
--- a/core/src/fpdftext/text_int.h
+++ b/core/src/fpdftext/text_int.h
@@ -8,6 +8,7 @@
#define CORE_SRC_FPDFTEXT_TEXT_INT_H_
#include <deque>
+#include <vector>
#include "core/include/fpdftext/fpdf_text.h"
#include "core/include/fxcrt/fx_basic.h"
@@ -130,7 +131,7 @@ class CPDF_TextPage : public IPDF_TextPage {
const CPDF_Font* pFont,
int nItems) const;
- CFX_WordArray m_CharIndex;
+ std::vector<FX_WORD> m_CharIndex;
const CPDF_PageObjectList* const m_pPage;
std::deque<PAGECHAR_INFO> m_CharList;
std::deque<PAGECHAR_INFO> m_TempCharList;
@@ -180,7 +181,7 @@ class CPDF_TextPageFind : public IPDF_TextPageFind {
int GetCharIndex(int index) const;
private:
- CFX_WordArray m_CharIndex;
+ std::vector<FX_WORD> m_CharIndex;
const IPDF_TextPage* m_pTextPage;
CFX_WideString m_strText;
CFX_WideString m_findWhat;
diff --git a/fpdfsdk/include/fsdk_mgr.h b/fpdfsdk/include/fsdk_mgr.h
index 2df44c7ca1..bef3b980fe 100644
--- a/fpdfsdk/include/fsdk_mgr.h
+++ b/fpdfsdk/include/fsdk_mgr.h
@@ -9,6 +9,7 @@
#include <map>
#include <memory>
+#include <vector>
#include "core/include/fpdftext/fpdf_text.h"
#include "fsdk_actionhandler.h"
@@ -519,14 +520,14 @@ class CPDFSDK_Document {
FX_BOOL SetFocusAnnot(CPDFSDK_Annot* pAnnot, FX_UINT nFlag = 0);
FX_BOOL KillFocusAnnot(FX_UINT nFlag = 0);
- FX_BOOL ExtractPages(const CFX_WordArray& arrExtraPages,
+ FX_BOOL ExtractPages(const std::vector<FX_WORD>& arrExtraPages,
CPDF_Document* pDstDoc);
FX_BOOL InsertPages(int nInsertAt,
const CPDF_Document* pSrcDoc,
- const CFX_WordArray& arrSrcPages);
+ const std::vector<FX_WORD>& arrSrcPages);
FX_BOOL ReplacePages(int nPage,
const CPDF_Document* pSrcDoc,
- const CFX_WordArray& arrSrcPages);
+ const std::vector<FX_WORD>& arrSrcPages);
void OnCloseDocument();
diff --git a/fpdfsdk/src/fpdfppo.cpp b/fpdfsdk/src/fpdfppo.cpp
index c05c7f35f0..84ac41d60e 100644
--- a/fpdfsdk/src/fpdfppo.cpp
+++ b/fpdfsdk/src/fpdfppo.cpp
@@ -9,6 +9,7 @@
#include <memory>
#include "fpdfsdk/include/fsdk_define.h"
+#include "third_party/base/stl_util.h"
class CPDF_PageOrganizer {
public:
@@ -18,7 +19,7 @@ class CPDF_PageOrganizer {
FX_BOOL PDFDocInit(CPDF_Document* pDestPDFDoc, CPDF_Document* pSrcPDFDoc);
FX_BOOL ExportPage(CPDF_Document* pSrcPDFDoc,
- CFX_WordArray* nPageNum,
+ std::vector<FX_WORD>* pPageNums,
CPDF_Document* pDestPDFDoc,
int nIndex);
CPDF_Object* PageDictGetInheritableTag(CPDF_Dictionary* pDict,
@@ -87,16 +88,15 @@ FX_BOOL CPDF_PageOrganizer::PDFDocInit(CPDF_Document* pDestPDFDoc,
}
FX_BOOL CPDF_PageOrganizer::ExportPage(CPDF_Document* pSrcPDFDoc,
- CFX_WordArray* nPageNum,
+ std::vector<FX_WORD>* pPageNums,
CPDF_Document* pDestPDFDoc,
int nIndex) {
int curpage = nIndex;
-
std::unique_ptr<ObjectNumberMap> pObjNumberMap(new ObjectNumberMap);
-
- for (int i = 0; i < nPageNum->GetSize(); ++i) {
+ int nSize = pdfium::CollectionSize<int>(*pPageNums);
+ for (int i = 0; i < nSize; ++i) {
CPDF_Dictionary* pCurPageDict = pDestPDFDoc->CreateNewPage(curpage);
- CPDF_Dictionary* pSrcPageDict = pSrcPDFDoc->GetPage(nPageNum->GetAt(i) - 1);
+ CPDF_Dictionary* pSrcPageDict = pSrcPDFDoc->GetPage(pPageNums->at(i) - 1);
if (!pSrcPageDict || !pCurPageDict)
return FALSE;
@@ -306,7 +306,7 @@ FX_DWORD CPDF_PageOrganizer::GetNewObjId(CPDF_Document* pDoc,
}
FPDF_BOOL ParserPageRangeString(CFX_ByteString rangstring,
- CFX_WordArray* pageArray,
+ std::vector<FX_WORD>* pageArray,
int nCount) {
if (rangstring.GetLength() != 0) {
rangstring.Remove(' ');
@@ -329,7 +329,7 @@ FPDF_BOOL ParserPageRangeString(CFX_ByteString rangstring,
long lPageNum = atol(cbMidRange);
if (lPageNum <= 0 || lPageNum > nCount)
return FALSE;
- pageArray->Add((FX_WORD)lPageNum);
+ pageArray->push_back((FX_WORD)lPageNum);
} else {
int nStartPageNum = atol(cbMidRange.Mid(0, nMid));
if (nStartPageNum == 0)
@@ -346,7 +346,7 @@ FPDF_BOOL ParserPageRangeString(CFX_ByteString rangstring,
return FALSE;
}
for (int i = nStartPageNum; i <= nEndPageNum; ++i) {
- pageArray->Add(i);
+ pageArray->push_back(i);
}
}
nStringFrom = nStringTo + 1;
@@ -367,14 +367,14 @@ DLLEXPORT FPDF_BOOL STDCALL FPDF_ImportPages(FPDF_DOCUMENT dest_doc,
if (!pSrcDoc)
return FALSE;
- CFX_WordArray pageArray;
+ std::vector<FX_WORD> pageArray;
int nCount = pSrcDoc->GetPageCount();
if (pagerange) {
if (!ParserPageRangeString(pagerange, &pageArray, nCount))
return FALSE;
} else {
for (int i = 1; i <= nCount; ++i) {
- pageArray.Add(i);
+ pageArray.push_back(i);
}
}