Get rid of |CXFA_TextLayout::m_Blocks| wrappers.
Now that |m_Blocks| has been refactored, it is easier to access it
directly.
Change-Id: I72a1abe6b955284537fd4ce9e5a3511040cb2313
Reviewed-on: https://pdfium-review.googlesource.com/c/49495
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/xfa/fxfa/cxfa_textlayout.cpp b/xfa/fxfa/cxfa_textlayout.cpp
index d181683..786a8fe 100644
--- a/xfa/fxfa/cxfa_textlayout.cpp
+++ b/xfa/fxfa/cxfa_textlayout.cpp
@@ -347,10 +347,9 @@
int32_t iLineIndex = 0;
if (iBlockCount > 0) {
if (iBlockCount >= iBlockIndex + 1) {
- iLineIndex = GetBlockIndex(iBlockIndex);
+ iLineIndex = m_Blocks[iBlockIndex].iIndex;
} else {
- int32_t iLast = iBlockCount - 1;
- iLineIndex = GetBlockIndex(iLast) + GetBlockLength(iLast);
+ iLineIndex = GetNextIndexForLastBlockData();
}
if (!m_pLoader->blockHeights.empty()) {
for (int32_t i = 0; i < iBlockIndex; i++)
@@ -374,12 +373,10 @@
continue;
}
- if (iBlockCount >= iBlockIndex + 1) {
- GetBlockIndex(iBlockIndex) = iLineIndex;
- GetBlockLength(iBlockIndex) = i - iLineIndex;
- } else {
+ if (iBlockCount >= iBlockIndex + 1)
+ m_Blocks[iBlockIndex] = {iLineIndex, i - iLineIndex};
+ else
m_Blocks.push_back({iLineIndex, i - iLineIndex});
- }
if (i != iLineIndex)
return fLinePos;
@@ -404,6 +401,10 @@
return iCount > 0 ? iCount : 1;
}
+int32_t CXFA_TextLayout::GetNextIndexForLastBlockData() const {
+ return m_Blocks.back().iIndex + m_Blocks.back().iLength;
+}
+
CFX_SizeF CXFA_TextLayout::CalcSize(const CFX_SizeF& minSize,
const CFX_SizeF& maxSize) {
float width = maxSize.width;
@@ -466,14 +467,14 @@
m_pLoader->iChar = 0;
if (iCount > 0)
- m_pLoader->iTotalLines = GetBlockLength(iBlock);
+ m_pLoader->iTotalLines = m_Blocks[iBlock].iLength;
Loader(szText.width, &fLinePos, true);
if (iCount == 0 && m_pLoader->fStartLineOffset < 0.1f)
UpdateAlign(szText.height, fLinePos);
} else if (m_pTextDataNode) {
if (iBlock < iCount - 1)
- m_pLoader->iTotalLines = GetBlockLength(iBlock);
+ m_pLoader->iTotalLines = m_Blocks[iBlock].iLength;
m_pBreak->Reset();
if (m_bRichText) {
@@ -549,8 +550,7 @@
} else {
fLinePos = 0;
}
- int32_t iLast = pdfium::CollectionSize<int32_t>(m_Blocks) - 1;
- iLineIndex = GetBlockIndex(iLast) + GetBlockLength(iLast);
+ iLineIndex = GetNextIndexForLastBlockData();
}
int32_t i = 0;
@@ -589,8 +589,8 @@
int32_t iPieceLines = pdfium::CollectionSize<int32_t>(m_pieceLines);
if (!m_Blocks.empty()) {
if (iBlock < pdfium::CollectionSize<int32_t>(m_Blocks)) {
- iLineStart = GetBlockIndex(iBlock);
- iPieceLines = GetBlockLength(iBlock);
+ iLineStart = m_Blocks[iBlock].iIndex;
+ iPieceLines = m_Blocks[iBlock].iLength;
} else {
iPieceLines = 0;
}
diff --git a/xfa/fxfa/cxfa_textlayout.h b/xfa/fxfa/cxfa_textlayout.h
index fd60005..777ec1e 100644
--- a/xfa/fxfa/cxfa_textlayout.h
+++ b/xfa/fxfa/cxfa_textlayout.h
@@ -116,8 +116,7 @@
void DoTabstops(CFX_CSSComputedStyle* pStyle, CXFA_PieceLine* pPieceLine);
bool Layout(int32_t iBlock);
int32_t CountBlocks() const;
- int32_t& GetBlockIndex(int32_t index) { return m_Blocks[index].iIndex; }
- int32_t& GetBlockLength(int32_t index) { return m_Blocks[index].iLength; }
+ int GetNextIndexForLastBlockData() const;
bool m_bHasBlock = false;
bool m_bRichText = false;