summaryrefslogtreecommitdiff
path: root/core/fpdfdoc/cpdf_variabletext.cpp
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2017-03-17 14:17:25 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-03-17 21:58:51 +0000
commit7a1220dc1c0051f2a6bf50f3f38419ae51ecb9a1 (patch)
tree72d186d4898da33e9f582a791aaa2562f74628e4 /core/fpdfdoc/cpdf_variabletext.cpp
parentf8b15f46e69fdec04a03afeb6f2bf60f90dff433 (diff)
downloadpdfium-7a1220dc1c0051f2a6bf50f3f38419ae51ecb9a1.tar.xz
Replace CLines class with std::vector<Cline>.
m_LineArray only grows via push_back of non-null pointer, so remove some null checks. Another little idiosyncrasy is CLines::Clear() doesn't clear the items in CLines, only the things that were once in CLines but aren't anymore. So don't call it. Change-Id: Icc434be94b1b0522533c7533b8f6b2736bb864c4 Reviewed-on: https://pdfium-review.googlesource.com/3099 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'core/fpdfdoc/cpdf_variabletext.cpp')
-rw-r--r--core/fpdfdoc/cpdf_variabletext.cpp202
1 files changed, 111 insertions, 91 deletions
diff --git a/core/fpdfdoc/cpdf_variabletext.cpp b/core/fpdfdoc/cpdf_variabletext.cpp
index 5dabf8db0c..d5333192f5 100644
--- a/core/fpdfdoc/cpdf_variabletext.cpp
+++ b/core/fpdfdoc/cpdf_variabletext.cpp
@@ -16,6 +16,7 @@
#include "core/fpdfdoc/csection.h"
#include "core/fpdfdoc/ipvt_fontmap.h"
#include "third_party/base/ptr_util.h"
+#include "third_party/base/stl_util.h"
namespace {
@@ -112,37 +113,41 @@ bool CPDF_VariableText::Iterator::PrevWord() {
}
bool CPDF_VariableText::Iterator::NextLine() {
- if (CSection* pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) {
- if (m_CurPos.nLineIndex < pSection->m_LineArray.GetSize() - 1) {
- m_CurPos =
- CPVT_WordPlace(m_CurPos.nSecIndex, m_CurPos.nLineIndex + 1, -1);
- return true;
- }
- if (m_CurPos.nSecIndex < m_pVT->m_SectionArray.GetSize() - 1) {
- m_CurPos = CPVT_WordPlace(m_CurPos.nSecIndex + 1, 0, -1);
- return true;
- }
+ CSection* pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex);
+ if (!pSection)
+ return false;
+
+ if (m_CurPos.nLineIndex <
+ pdfium::CollectionSize<int32_t>(pSection->m_LineArray) - 1) {
+ m_CurPos = CPVT_WordPlace(m_CurPos.nSecIndex, m_CurPos.nLineIndex + 1, -1);
+ return true;
+ }
+ if (m_CurPos.nSecIndex < m_pVT->m_SectionArray.GetSize() - 1) {
+ m_CurPos = CPVT_WordPlace(m_CurPos.nSecIndex + 1, 0, -1);
+ return true;
}
return false;
}
bool CPDF_VariableText::Iterator::PrevLine() {
- if (m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) {
- if (m_CurPos.nLineIndex > 0) {
- m_CurPos =
- CPVT_WordPlace(m_CurPos.nSecIndex, m_CurPos.nLineIndex - 1, -1);
- return true;
- }
- if (m_CurPos.nSecIndex > 0) {
- if (CSection* pLastSection =
- m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex - 1)) {
- m_CurPos = CPVT_WordPlace(m_CurPos.nSecIndex - 1,
- pLastSection->m_LineArray.GetSize() - 1, -1);
- return true;
- }
- }
+ if (!m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex))
+ return false;
+
+ if (m_CurPos.nLineIndex > 0) {
+ m_CurPos = CPVT_WordPlace(m_CurPos.nSecIndex, m_CurPos.nLineIndex - 1, -1);
+ return true;
}
- return false;
+ if (m_CurPos.nSecIndex <= 0)
+ return false;
+
+ CSection* pLastSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex - 1);
+ if (!pLastSection)
+ return false;
+
+ m_CurPos = CPVT_WordPlace(
+ m_CurPos.nSecIndex - 1,
+ pdfium::CollectionSize<int32_t>(pLastSection->m_LineArray) - 1, -1);
+ return true;
}
bool CPDF_VariableText::Iterator::NextSection() {
@@ -164,58 +169,65 @@ bool CPDF_VariableText::Iterator::PrevSection() {
bool CPDF_VariableText::Iterator::GetWord(CPVT_Word& word) const {
word.WordPlace = m_CurPos;
- if (CSection* pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) {
- if (pSection->m_LineArray.GetAt(m_CurPos.nLineIndex)) {
- if (CPVT_WordInfo* pWord =
- pSection->m_WordArray.GetAt(m_CurPos.nWordIndex)) {
- word.Word = pWord->Word;
- word.nCharset = pWord->nCharset;
- word.fWidth = m_pVT->GetWordWidth(*pWord);
- word.ptWord = m_pVT->InToOut(
- CFX_PointF(pWord->fWordX + pSection->m_SecInfo.rcSection.left,
- pWord->fWordY + pSection->m_SecInfo.rcSection.top));
- word.fAscent = m_pVT->GetWordAscent(*pWord);
- word.fDescent = m_pVT->GetWordDescent(*pWord);
- if (pWord->pWordProps)
- word.WordProps = *pWord->pWordProps;
-
- word.nFontIndex = m_pVT->GetWordFontIndex(*pWord);
- word.fFontSize = m_pVT->GetWordFontSize(*pWord);
- return true;
- }
- }
- }
- return false;
+ CSection* pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex);
+ if (!pSection)
+ return false;
+
+ if (!pdfium::IndexInBounds(pSection->m_LineArray, m_CurPos.nLineIndex))
+ return false;
+
+ CPVT_WordInfo* pWord = pSection->m_WordArray.GetAt(m_CurPos.nWordIndex);
+ if (!pWord)
+ return false;
+
+ word.Word = pWord->Word;
+ word.nCharset = pWord->nCharset;
+ word.fWidth = m_pVT->GetWordWidth(*pWord);
+ word.ptWord = m_pVT->InToOut(
+ CFX_PointF(pWord->fWordX + pSection->m_SecInfo.rcSection.left,
+ pWord->fWordY + pSection->m_SecInfo.rcSection.top));
+ word.fAscent = m_pVT->GetWordAscent(*pWord);
+ word.fDescent = m_pVT->GetWordDescent(*pWord);
+ if (pWord->pWordProps)
+ word.WordProps = *pWord->pWordProps;
+ word.nFontIndex = m_pVT->GetWordFontIndex(*pWord);
+ word.fFontSize = m_pVT->GetWordFontSize(*pWord);
+ return true;
}
bool CPDF_VariableText::Iterator::SetWord(const CPVT_Word& word) {
- if (CSection* pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) {
- if (CPVT_WordInfo* pWord =
- pSection->m_WordArray.GetAt(m_CurPos.nWordIndex)) {
- if (pWord->pWordProps)
- *pWord->pWordProps = word.WordProps;
- return true;
- }
- }
- return false;
+ CSection* pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex);
+ if (!pSection)
+ return false;
+
+ CPVT_WordInfo* pWord = pSection->m_WordArray.GetAt(m_CurPos.nWordIndex);
+ if (!pWord)
+ return false;
+
+ if (pWord->pWordProps)
+ *pWord->pWordProps = word.WordProps;
+ return true;
}
bool CPDF_VariableText::Iterator::GetLine(CPVT_Line& line) const {
ASSERT(m_pVT);
line.lineplace = CPVT_WordPlace(m_CurPos.nSecIndex, m_CurPos.nLineIndex, -1);
- if (CSection* pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) {
- if (CLine* pLine = pSection->m_LineArray.GetAt(m_CurPos.nLineIndex)) {
- line.ptLine = m_pVT->InToOut(CFX_PointF(
- pLine->m_LineInfo.fLineX + pSection->m_SecInfo.rcSection.left,
- pLine->m_LineInfo.fLineY + pSection->m_SecInfo.rcSection.top));
- line.fLineWidth = pLine->m_LineInfo.fLineWidth;
- line.fLineAscent = pLine->m_LineInfo.fLineAscent;
- line.fLineDescent = pLine->m_LineInfo.fLineDescent;
- line.lineEnd = pLine->GetEndWordPlace();
- return true;
- }
- }
- return false;
+ CSection* pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex);
+ if (!pSection)
+ return false;
+
+ if (!pdfium::IndexInBounds(pSection->m_LineArray, m_CurPos.nLineIndex))
+ return false;
+
+ CLine* pLine = pSection->m_LineArray[m_CurPos.nLineIndex].get();
+ line.ptLine = m_pVT->InToOut(
+ CFX_PointF(pLine->m_LineInfo.fLineX + pSection->m_SecInfo.rcSection.left,
+ pLine->m_LineInfo.fLineY + pSection->m_SecInfo.rcSection.top));
+ line.fLineWidth = pLine->m_LineInfo.fLineWidth;
+ line.fLineAscent = pLine->m_LineInfo.fLineAscent;
+ line.fLineDescent = pLine->m_LineInfo.fLineDescent;
+ line.lineEnd = pLine->GetEndWordPlace();
+ return true;
}
bool CPDF_VariableText::Iterator::GetSection(CPVT_Section& section) const {
@@ -232,14 +244,15 @@ bool CPDF_VariableText::Iterator::GetSection(CPVT_Section& section) const {
}
bool CPDF_VariableText::Iterator::SetSection(const CPVT_Section& section) {
- if (CSection* pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex)) {
- if (pSection->m_SecInfo.pSecProps)
- *pSection->m_SecInfo.pSecProps = section.SecProps;
- if (pSection->m_SecInfo.pWordProps)
- *pSection->m_SecInfo.pWordProps = section.WordProps;
- return true;
- }
- return false;
+ CSection* pSection = m_pVT->m_SectionArray.GetAt(m_CurPos.nSecIndex);
+ if (!pSection)
+ return false;
+
+ if (pSection->m_SecInfo.pSecProps)
+ *pSection->m_SecInfo.pSecProps = section.SecProps;
+ if (pSection->m_SecInfo.pWordProps)
+ *pSection->m_SecInfo.pWordProps = section.WordProps;
+ return true;
}
CPDF_VariableText::CPDF_VariableText()
@@ -602,7 +615,8 @@ CPVT_WordPlace CPDF_VariableText::GetUpWordPlace(
}
if (temp.nSecIndex-- > 0) {
if (CSection* pLastSection = m_SectionArray.GetAt(temp.nSecIndex)) {
- temp.nLineIndex = pLastSection->m_LineArray.GetSize() - 1;
+ temp.nLineIndex =
+ pdfium::CollectionSize<int32_t>(pLastSection->m_LineArray) - 1;
return pLastSection->SearchWordPlace(
pt.x - pLastSection->m_SecInfo.rcSection.left, temp);
}
@@ -617,7 +631,8 @@ CPVT_WordPlace CPDF_VariableText::GetDownWordPlace(
if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) {
CPVT_WordPlace temp = place;
CFX_PointF pt = OutToIn(point);
- if (temp.nLineIndex++ < pSection->m_LineArray.GetSize() - 1) {
+ if (temp.nLineIndex++ <
+ pdfium::CollectionSize<int32_t>(pSection->m_LineArray) - 1) {
return pSection->SearchWordPlace(
pt.x - pSection->m_SecInfo.rcSection.left, temp);
}
@@ -639,11 +654,14 @@ CPVT_WordPlace CPDF_VariableText::GetLineBeginPlace(
CPVT_WordPlace CPDF_VariableText::GetLineEndPlace(
const CPVT_WordPlace& place) const {
- if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) {
- if (CLine* pLine = pSection->m_LineArray.GetAt(place.nLineIndex))
- return pLine->GetEndWordPlace();
- }
- return place;
+ CSection* pSection = m_SectionArray.GetAt(place.nSecIndex);
+ if (!pSection)
+ return place;
+
+ if (!pdfium::IndexInBounds(pSection->m_LineArray, place.nLineIndex))
+ return place;
+
+ return pSection->m_LineArray[place.nLineIndex]->GetEndWordPlace();
}
CPVT_WordPlace CPDF_VariableText::GetSectionBeginPlace(
@@ -739,13 +757,15 @@ bool CPDF_VariableText::SetWordInfo(const CPVT_WordPlace& place,
bool CPDF_VariableText::GetLineInfo(const CPVT_WordPlace& place,
CPVT_LineInfo& lineinfo) {
- if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) {
- if (CLine* pLine = pSection->m_LineArray.GetAt(place.nLineIndex)) {
- lineinfo = pLine->m_LineInfo;
- return true;
- }
- }
- return false;
+ CSection* pSection = m_SectionArray.GetAt(place.nSecIndex);
+ if (!pSection)
+ return false;
+
+ if (!pdfium::IndexInBounds(pSection->m_LineArray, place.nLineIndex))
+ return false;
+
+ lineinfo = pSection->m_LineArray[place.nLineIndex]->m_LineInfo;
+ return true;
}
bool CPDF_VariableText::GetSectionInfo(const CPVT_WordPlace& place,