summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorthestig <thestig@chromium.org>2016-05-11 12:59:22 -0700
committerCommit bot <commit-bot@chromium.org>2016-05-11 12:59:22 -0700
commit821d59e1d66b67af970c59b7681828b1b82858b6 (patch)
tree60e71c3c317f5843d0488e827c6932a956df7866 /core
parenta244dfe2ba2cc82ee264475253cc16222e022524 (diff)
downloadpdfium-821d59e1d66b67af970c59b7681828b1b82858b6.tar.xz
CPDF_VariableText::GetIterator() never returns NULL.
Same goes for CFX_Edit::GetIterator(). Review-Url: https://codereview.chromium.org/1967963002
Diffstat (limited to 'core')
-rw-r--r--core/fpdfdoc/cpdf_variabletext.cpp8
-rw-r--r--core/fpdfdoc/cpvt_generateap.cpp119
-rw-r--r--core/fpdfdoc/include/cpdf_variabletext.h4
3 files changed, 64 insertions, 67 deletions
diff --git a/core/fpdfdoc/cpdf_variabletext.cpp b/core/fpdfdoc/cpdf_variabletext.cpp
index 427cd5d306..3c71ed8786 100644
--- a/core/fpdfdoc/cpdf_variabletext.cpp
+++ b/core/fpdfdoc/cpdf_variabletext.cpp
@@ -256,11 +256,9 @@ CPDF_VariableText::CPDF_VariableText()
m_fFontSize(0.0f),
m_bInitial(FALSE),
m_bRichText(FALSE),
- m_pVTProvider(nullptr),
- m_pVTIterator(nullptr) {}
+ m_pVTProvider(nullptr) {}
CPDF_VariableText::~CPDF_VariableText() {
- delete m_pVTIterator;
ResetAll();
}
@@ -1149,8 +1147,8 @@ FX_BOOL CPDF_VariableText::IsLatinWord(uint16_t word) {
CPDF_VariableText::Iterator* CPDF_VariableText::GetIterator() {
if (!m_pVTIterator)
- m_pVTIterator = new CPDF_VariableText::Iterator(this);
- return m_pVTIterator;
+ m_pVTIterator.reset(new CPDF_VariableText::Iterator(this));
+ return m_pVTIterator.get();
}
void CPDF_VariableText::SetProvider(CPDF_VariableText::Provider* pProvider) {
diff --git a/core/fpdfdoc/cpvt_generateap.cpp b/core/fpdfdoc/cpvt_generateap.cpp
index 5ec9513e84..7fcd90969e 100644
--- a/core/fpdfdoc/cpvt_generateap.cpp
+++ b/core/fpdfdoc/cpvt_generateap.cpp
@@ -507,76 +507,73 @@ CFX_ByteString CPVT_GenerateAP::GenerateEditAP(
CFX_ByteTextBuf sEditStream, sLineStream, sWords;
CFX_FloatPoint ptOld(0.0f, 0.0f), ptNew(0.0f, 0.0f);
int32_t nCurFontIndex = -1;
- if (pIterator) {
- pIterator->SetAt(0);
-
- CPVT_WordPlace oldplace;
- while (pIterator->NextWord()) {
- CPVT_WordPlace place = pIterator->GetAt();
- if (bContinuous) {
- if (place.LineCmp(oldplace) != 0) {
- if (sWords.GetSize() > 0) {
- sLineStream << GetWordRenderString(sWords.AsStringC());
- sEditStream << sLineStream;
- sLineStream.Clear();
- sWords.Clear();
- }
- CPVT_Word word;
- if (pIterator->GetWord(word)) {
- ptNew = CFX_FloatPoint(word.ptWord.x + ptOffset.x,
- word.ptWord.y + ptOffset.y);
- } else {
- CPVT_Line line;
- pIterator->GetLine(line);
- ptNew = CFX_FloatPoint(line.ptLine.x + ptOffset.x,
- line.ptLine.y + ptOffset.y);
- }
- if (ptNew.x != ptOld.x || ptNew.y != ptOld.y) {
- sLineStream << ptNew.x - ptOld.x << " " << ptNew.y - ptOld.y
- << " Td\n";
- ptOld = ptNew;
- }
+ pIterator->SetAt(0);
+
+ CPVT_WordPlace oldplace;
+ while (pIterator->NextWord()) {
+ CPVT_WordPlace place = pIterator->GetAt();
+ if (bContinuous) {
+ if (place.LineCmp(oldplace) != 0) {
+ if (sWords.GetSize() > 0) {
+ sLineStream << GetWordRenderString(sWords.AsStringC());
+ sEditStream << sLineStream;
+ sLineStream.Clear();
+ sWords.Clear();
}
CPVT_Word word;
if (pIterator->GetWord(word)) {
- if (word.nFontIndex != nCurFontIndex) {
- if (sWords.GetSize() > 0) {
- sLineStream << GetWordRenderString(sWords.AsStringC());
- sWords.Clear();
- }
- sLineStream << GetFontSetString(pFontMap, word.nFontIndex,
- word.fFontSize);
- nCurFontIndex = word.nFontIndex;
- }
- sWords << GetPDFWordString(pFontMap, nCurFontIndex, word.Word,
- SubWord);
- }
- oldplace = place;
- } else {
- CPVT_Word word;
- if (pIterator->GetWord(word)) {
ptNew = CFX_FloatPoint(word.ptWord.x + ptOffset.x,
word.ptWord.y + ptOffset.y);
- if (ptNew.x != ptOld.x || ptNew.y != ptOld.y) {
- sEditStream << ptNew.x - ptOld.x << " " << ptNew.y - ptOld.y
- << " Td\n";
- ptOld = ptNew;
- }
- if (word.nFontIndex != nCurFontIndex) {
- sEditStream << GetFontSetString(pFontMap, word.nFontIndex,
- word.fFontSize);
- nCurFontIndex = word.nFontIndex;
+ } else {
+ CPVT_Line line;
+ pIterator->GetLine(line);
+ ptNew = CFX_FloatPoint(line.ptLine.x + ptOffset.x,
+ line.ptLine.y + ptOffset.y);
+ }
+ if (ptNew.x != ptOld.x || ptNew.y != ptOld.y) {
+ sLineStream << ptNew.x - ptOld.x << " " << ptNew.y - ptOld.y
+ << " Td\n";
+ ptOld = ptNew;
+ }
+ }
+ CPVT_Word word;
+ if (pIterator->GetWord(word)) {
+ if (word.nFontIndex != nCurFontIndex) {
+ if (sWords.GetSize() > 0) {
+ sLineStream << GetWordRenderString(sWords.AsStringC());
+ sWords.Clear();
}
- sEditStream << GetWordRenderString(
- GetPDFWordString(pFontMap, nCurFontIndex, word.Word, SubWord));
+ sLineStream << GetFontSetString(pFontMap, word.nFontIndex,
+ word.fFontSize);
+ nCurFontIndex = word.nFontIndex;
}
+ sWords << GetPDFWordString(pFontMap, nCurFontIndex, word.Word, SubWord);
+ }
+ oldplace = place;
+ } else {
+ CPVT_Word word;
+ if (pIterator->GetWord(word)) {
+ ptNew = CFX_FloatPoint(word.ptWord.x + ptOffset.x,
+ word.ptWord.y + ptOffset.y);
+ if (ptNew.x != ptOld.x || ptNew.y != ptOld.y) {
+ sEditStream << ptNew.x - ptOld.x << " " << ptNew.y - ptOld.y
+ << " Td\n";
+ ptOld = ptNew;
+ }
+ if (word.nFontIndex != nCurFontIndex) {
+ sEditStream << GetFontSetString(pFontMap, word.nFontIndex,
+ word.fFontSize);
+ nCurFontIndex = word.nFontIndex;
+ }
+ sEditStream << GetWordRenderString(
+ GetPDFWordString(pFontMap, nCurFontIndex, word.Word, SubWord));
}
}
- if (sWords.GetSize() > 0) {
- sLineStream << GetWordRenderString(sWords.AsStringC());
- sEditStream << sLineStream;
- sWords.Clear();
- }
+ }
+ if (sWords.GetSize() > 0) {
+ sLineStream << GetWordRenderString(sWords.AsStringC());
+ sEditStream << sLineStream;
+ sWords.Clear();
}
return sEditStream.AsStringC();
}
diff --git a/core/fpdfdoc/include/cpdf_variabletext.h b/core/fpdfdoc/include/cpdf_variabletext.h
index a14ad52752..c9184bc7c0 100644
--- a/core/fpdfdoc/include/cpdf_variabletext.h
+++ b/core/fpdfdoc/include/cpdf_variabletext.h
@@ -7,6 +7,8 @@
#ifndef CORE_FPDFDOC_INCLUDE_CPDF_VARIABLETEXT_H_
#define CORE_FPDFDOC_INCLUDE_CPDF_VARIABLETEXT_H_
+#include <memory>
+
#include "core/fpdfdoc/cpvt_floatrect.h"
#include "core/fpdfdoc/cpvt_lineinfo.h"
#include "core/fpdfdoc/include/cpvt_line.h"
@@ -246,7 +248,7 @@ class CPDF_VariableText : private CPDF_EditContainer {
FX_BOOL m_bInitial;
FX_BOOL m_bRichText;
CPDF_VariableText::Provider* m_pVTProvider;
- CPDF_VariableText::Iterator* m_pVTIterator;
+ std::unique_ptr<CPDF_VariableText::Iterator> m_pVTIterator;
};
#endif // CORE_FPDFDOC_INCLUDE_CPDF_VARIABLETEXT_H_