summaryrefslogtreecommitdiff
path: root/core/src/fpdftext
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2016-02-09 09:55:54 -0800
committerTom Sepez <tsepez@chromium.org>2016-02-09 09:55:54 -0800
commit11d93559cea7a0894e05249e7dac2035ad79994e (patch)
tree801b9cd68ffef73b861708759c0304097a384fa4 /core/src/fpdftext
parent56cf589f6ecc85a84c183956bdcb071ec16567d9 (diff)
downloadpdfium-11d93559cea7a0894e05249e7dac2035ad79994e.tar.xz
Banish CFX_WordArray to XFA-land.
R=thestig@chromium.org Review URL: https://codereview.chromium.org/1676913004 .
Diffstat (limited to 'core/src/fpdftext')
-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
3 files changed, 76 insertions, 87 deletions
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;