Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Unified Diff: core/fpdfdoc/cpdf_variabletext.cpp

Issue 1959253002: Remove unneeded CPVT classes. (try 2) (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: Make m_WordArray hold unique_ptrs Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: core/fpdfdoc/cpdf_variabletext.cpp
diff --git a/core/fpdfdoc/cpdf_variabletext.cpp b/core/fpdfdoc/cpdf_variabletext.cpp
index 67887400a47e940523399f7581d60ee80c227780..51220c77386b6cb3b2382045b465df8fecd064a5 100644
--- a/core/fpdfdoc/cpdf_variabletext.cpp
+++ b/core/fpdfdoc/cpdf_variabletext.cpp
@@ -4,10 +4,11 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+#include "core/fpdfdoc/include/cpdf_variabletext.h"
+
#include "core/fpdfapi/fpdf_font/include/cpdf_font.h"
#include "core/fpdfdoc/cpvt_wordinfo.h"
#include "core/fpdfdoc/csection.h"
-#include "core/fpdfdoc/include/cpdf_variabletext.h"
#include "core/fpdfdoc/include/cpvt_section.h"
#include "core/fpdfdoc/include/cpvt_word.h"
#include "core/fpdfdoc/include/ipvt_fontmap.h"
@@ -70,11 +71,8 @@ int32_t CPDF_VariableText::Provider::GetWordFontIndex(uint16_t word,
}
FX_BOOL CPDF_VariableText::Provider::IsLatinWord(uint16_t word) {
- if ((word >= 0x61 && word <= 0x7A) || (word >= 0x41 && word <= 0x5A) ||
- word == 0x2D || word == 0x27) {
- return TRUE;
- }
- return FALSE;
+ return (word >= 0x61 && word <= 0x7A) || (word >= 0x41 && word <= 0x5A) ||
+ word == 0x2D || word == 0x27;
}
int32_t CPDF_VariableText::Provider::GetDefaultFontIndex() {
@@ -164,40 +162,45 @@ FX_BOOL CPDF_VariableText::Iterator::PrevSection() {
FX_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_FloatPoint(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 (!pSection->m_LineArray.GetAt(m_CurPos.nLineIndex))
+ return FALSE;
+
+ const CPVT_WordInfo* pWord = pSection->GetWord(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_FloatPoint(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;
}
FX_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;
+
+ const CPVT_WordInfo* pWord = pSection->GetWord(m_CurPos.nWordIndex);
+ if (!pWord)
+ return FALSE;
+
+ if (pWord->pWordProps)
+ *pWord->pWordProps = word.WordProps;
+ return TRUE;
}
FX_BOOL CPDF_VariableText::Iterator::GetLine(CPVT_Line& line) const {
@@ -332,29 +335,29 @@ CPVT_WordPlace CPDF_VariableText::InsertSection(
CPVT_WordPlace wordplace = place;
UpdateWordPlace(wordplace);
CPVT_WordPlace newplace = place;
- if (CSection* pSection = m_SectionArray.GetAt(wordplace.nSecIndex)) {
- CPVT_WordPlace NewPlace(wordplace.nSecIndex + 1, 0, -1);
- CPVT_SectionInfo secinfo;
- if (m_bRichText) {
- if (pSecProps)
- secinfo.pSecProps = new CPVT_SecProps(*pSecProps);
- if (pWordProps)
- secinfo.pWordProps = new CPVT_WordProps(*pWordProps);
- }
- AddSection(NewPlace, secinfo);
- newplace = NewPlace;
- if (CSection* pNewSection = m_SectionArray.GetAt(NewPlace.nSecIndex)) {
- for (int32_t w = wordplace.nWordIndex + 1,
- sz = pSection->m_WordArray.GetSize();
- w < sz; w++) {
- if (CPVT_WordInfo* pWord = pSection->m_WordArray.GetAt(w)) {
- NewPlace.nWordIndex++;
- pNewSection->AddWord(NewPlace, *pWord);
- }
- }
+ CSection* pSection = m_SectionArray.GetAt(wordplace.nSecIndex);
+ if (!pSection)
+ return newplace;
+
+ CPVT_WordPlace NewPlace(wordplace.nSecIndex + 1, 0, -1);
+ CPVT_SectionInfo secinfo;
+ if (m_bRichText) {
+ if (pSecProps)
+ secinfo.pSecProps = new CPVT_SecProps(*pSecProps);
+ if (pWordProps)
+ secinfo.pWordProps = new CPVT_WordProps(*pWordProps);
+ }
+ AddSection(NewPlace, secinfo);
+ newplace = NewPlace;
+ if (CSection* pNewSection = m_SectionArray.GetAt(NewPlace.nSecIndex)) {
+ for (int32_t i = wordplace.nWordIndex + 1; i < pSection->GetNumberOfWords();
+ ++i) {
+ const CPVT_WordInfo* pWord = pSection->GetWord(i);
+ NewPlace.nWordIndex++;
+ pNewSection->AddWord(NewPlace, *pWord);
}
- ClearSectionRightWords(wordplace);
}
+ ClearSectionRightWords(wordplace);
return newplace;
}
@@ -499,7 +502,7 @@ int32_t CPDF_VariableText::WordPlaceToWordIndex(
for (i = 0, sz = m_SectionArray.GetSize(); i < sz && i < newplace.nSecIndex;
i++) {
if (CSection* pSection = m_SectionArray.GetAt(i)) {
- nIndex += pSection->m_WordArray.GetSize();
+ nIndex += pSection->GetNumberOfWords();
if (i != m_SectionArray.GetSize() - 1)
nIndex += kReturnLength;
}
@@ -515,12 +518,13 @@ CPVT_WordPlace CPDF_VariableText::WordIndexToWordPlace(int32_t index) const {
FX_BOOL bFind = FALSE;
for (int32_t i = 0, sz = m_SectionArray.GetSize(); i < sz; i++) {
if (CSection* pSection = m_SectionArray.GetAt(i)) {
- nIndex += pSection->m_WordArray.GetSize();
+ nIndex += pSection->GetNumberOfWords();
if (nIndex == index) {
place = pSection->GetEndWordPlace();
bFind = TRUE;
break;
- } else if (nIndex > index) {
+ }
+ if (nIndex > index) {
place.nSecIndex = i;
place.nWordIndex = index - nOldIndex - 1;
pSection->UpdateWordPlace(place);
@@ -696,7 +700,7 @@ int32_t CPDF_VariableText::GetTotalWords() const {
int32_t nTotal = 0;
for (int32_t i = 0, sz = m_SectionArray.GetSize(); i < sz; i++) {
if (CSection* pSection = m_SectionArray.GetAt(i))
- nTotal += (pSection->m_WordArray.GetSize() + kReturnLength);
+ nTotal += (pSection->GetNumberOfWords() + kReturnLength);
}
return nTotal - kReturnLength;
@@ -729,7 +733,7 @@ CPVT_WordPlace CPDF_VariableText::AddSection(const CPVT_WordPlace& place,
CPVT_WordPlace CPDF_VariableText::AddLine(const CPVT_WordPlace& place,
const CPVT_LineInfo& lineinfo) {
- if (m_SectionArray.IsEmpty())
+ if (m_SectionArray.GetSize() == 0)
return place;
if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex))
return pSection->AddLine(lineinfo);
@@ -738,9 +742,9 @@ CPVT_WordPlace CPDF_VariableText::AddLine(const CPVT_WordPlace& place,
CPVT_WordPlace CPDF_VariableText::AddWord(const CPVT_WordPlace& place,
const CPVT_WordInfo& wordinfo) {
- if (m_SectionArray.GetSize() <= 0) {
+ if (m_SectionArray.GetSize() <= 0)
return place;
- }
+
CPVT_WordPlace newplace = place;
newplace.nSecIndex =
std::max(std::min(newplace.nSecIndex, m_SectionArray.GetSize() - 1), 0);
@@ -751,24 +755,30 @@ CPVT_WordPlace CPDF_VariableText::AddWord(const CPVT_WordPlace& place,
FX_BOOL CPDF_VariableText::GetWordInfo(const CPVT_WordPlace& place,
CPVT_WordInfo& wordinfo) {
- if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) {
- if (CPVT_WordInfo* pWord = pSection->m_WordArray.GetAt(place.nWordIndex)) {
- wordinfo = *pWord;
- return TRUE;
- }
- }
- return FALSE;
+ CSection* pSection = m_SectionArray.GetAt(place.nSecIndex);
+ if (!pSection)
+ return FALSE;
+
+ const CPVT_WordInfo* pWord = pSection->GetWord(place.nWordIndex);
+ if (!pWord)
+ return FALSE;
+
+ wordinfo = *pWord;
+ return TRUE;
}
FX_BOOL CPDF_VariableText::SetWordInfo(const CPVT_WordPlace& place,
const CPVT_WordInfo& wordinfo) {
- if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) {
- if (CPVT_WordInfo* pWord = pSection->m_WordArray.GetAt(place.nWordIndex)) {
- *pWord = wordinfo;
- return TRUE;
- }
- }
- return FALSE;
+ CSection* pSection = m_SectionArray.GetAt(place.nSecIndex);
+ if (!pSection)
+ return FALSE;
+
+ CPVT_WordInfo* pWord = pSection->GetWord(place.nWordIndex);
+ if (!pWord)
+ return FALSE;
+
+ *pWord = wordinfo;
+ return TRUE;
}
FX_BOOL CPDF_VariableText::GetLineInfo(const CPVT_WordPlace& place,
@@ -906,13 +916,9 @@ int32_t CPDF_VariableText::GetHorzScale(const CPVT_WordInfo& WordInfo) {
void CPDF_VariableText::ClearSectionRightWords(const CPVT_WordPlace& place) {
CPVT_WordPlace wordplace = AdjustLineHeader(place, TRUE);
- if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) {
- for (int32_t w = pSection->m_WordArray.GetSize() - 1;
- w > wordplace.nWordIndex; w--) {
- delete pSection->m_WordArray.GetAt(w);
- pSection->m_WordArray.RemoveAt(w);
- }
- }
+ CSection* pSection = m_SectionArray.GetAt(place.nSecIndex);
+ if (pSection)
+ pSection->ClearRightWords(wordplace.nWordIndex);
dsinclair 2016/05/16 14:12:27 ClearRightWords is ... confusing. ClearWordsFrom m
}
CPVT_WordPlace CPDF_VariableText::AdjustLineHeader(const CPVT_WordPlace& place,
@@ -926,7 +932,7 @@ FX_BOOL CPDF_VariableText::ClearEmptySection(const CPVT_WordPlace& place) {
if (place.nSecIndex == 0 && m_SectionArray.GetSize() == 1)
return FALSE;
if (CSection* pSection = m_SectionArray.GetAt(place.nSecIndex)) {
- if (pSection->m_WordArray.GetSize() == 0) {
+ if (pSection->IsWordArrayEmpty()) {
dsinclair 2016/05/16 14:12:27 Can this use GetSize() == 0? We got rid of IsEmpty
delete pSection;
m_SectionArray.RemoveAt(place.nSecIndex);
return TRUE;
@@ -948,12 +954,10 @@ void CPDF_VariableText::LinkLatterSection(const CPVT_WordPlace& place) {
CPVT_WordPlace oldplace = AdjustLineHeader(place, TRUE);
if (CSection* pNextSection = m_SectionArray.GetAt(place.nSecIndex + 1)) {
if (CSection* pSection = m_SectionArray.GetAt(oldplace.nSecIndex)) {
- for (int32_t w = 0, sz = pNextSection->m_WordArray.GetSize(); w < sz;
- w++) {
- if (CPVT_WordInfo* pWord = pNextSection->m_WordArray.GetAt(w)) {
- oldplace.nWordIndex++;
- pSection->AddWord(oldplace, *pWord);
- }
+ for (int32_t i = 0; i < pNextSection->GetNumberOfWords(); ++i) {
+ const CPVT_WordInfo* pWord = pNextSection->GetWord(i);
dsinclair 2016/05/16 14:12:27 It's no longer possible for pWord to be nullptr?
+ oldplace.nWordIndex++;
+ pSection->AddWord(oldplace, *pWord);
}
}
delete pNextSection;
@@ -977,7 +981,7 @@ CPVT_WordPlace CPDF_VariableText::ClearLeftWord(const CPVT_WordPlace& place) {
CPVT_WordPlace leftplace = GetPrevWordPlace(place);
if (leftplace != place) {
if (leftplace.nSecIndex != place.nSecIndex) {
- if (pSection->m_WordArray.GetSize() == 0)
+ if (pSection->IsWordArrayEmpty())
ClearEmptySection(place);
else
LinkLatterSection(leftplace);
@@ -1053,22 +1057,20 @@ FX_FLOAT CPDF_VariableText::GetAutoFontSize() {
return (FX_FLOAT)gFontSizeSteps[nMid];
}
-FX_BOOL CPDF_VariableText::IsBigger(FX_FLOAT fFontSize) {
- FX_BOOL bBigger = FALSE;
- CPVT_Size szTotal;
+bool CPDF_VariableText::IsBigger(FX_FLOAT fFontSize) const {
+ CFX_PointF szTotal;
for (int32_t s = 0, sz = m_SectionArray.GetSize(); s < sz; s++) {
if (CSection* pSection = m_SectionArray.GetAt(s)) {
- CPVT_Size size = pSection->GetSectionSize(fFontSize);
+ CFX_PointF size = pSection->GetSectionSize(fFontSize);
szTotal.x = std::max(size.x, szTotal.x);
szTotal.y += size.y;
if (IsFloatBigger(szTotal.x, GetPlateWidth()) ||
IsFloatBigger(szTotal.y, GetPlateHeight())) {
- bBigger = TRUE;
- break;
+ return true;
}
}
}
- return bBigger;
+ return false;
}
CPVT_FloatRect CPDF_VariableText::RearrangeSections(
« no previous file with comments | « BUILD.gn ('k') | core/fpdfdoc/cpvt_generateap.cpp » ('j') | core/fpdfdoc/csection.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698