Wrap direct access to elements in |CXFA_TextLayout::m_Blocks|.
Add helper methods to access |m_Blocks|, so the caller does not need to
manually calculate the offset.
Change-Id: I87001731e2bf666158befe5bf66ca0f2796c22e7
Reviewed-on: https://pdfium-review.googlesource.com/c/49510
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 b649a9b..bb7b99e 100644
--- a/xfa/fxfa/cxfa_textlayout.cpp
+++ b/xfa/fxfa/cxfa_textlayout.cpp
@@ -347,9 +347,10 @@
int32_t iLineIndex = 0;
if (iBlockCount > 1) {
if (iBlockCount >= (iBlockIndex + 1) * 2) {
- iLineIndex = m_Blocks[iBlockIndex * 2];
+ iLineIndex = GetBlockIndex(iBlockIndex);
} else {
- iLineIndex = m_Blocks[iBlockCount - 1] + m_Blocks[iBlockCount - 2];
+ int32_t iLast = iBlockCount / 2 - 1;
+ iLineIndex = GetBlockIndex(iLast) + GetBlockLength(iLast);
}
if (!m_pLoader->blockHeights.empty()) {
for (int32_t i = 0; i < iBlockIndex; i++)
@@ -374,8 +375,8 @@
}
if (iBlockCount >= (iBlockIndex + 1) * 2) {
- m_Blocks[iBlockIndex * 2] = iLineIndex;
- m_Blocks[iBlockIndex * 2 + 1] = i - iLineIndex;
+ GetBlockIndex(iBlockIndex) = iLineIndex;
+ GetBlockLength(iBlockIndex) = i - iLineIndex;
} else {
m_Blocks.push_back(iLineIndex);
m_Blocks.push_back(i - iLineIndex);
@@ -466,14 +467,14 @@
m_pLoader->iChar = 0;
if (iCount > 1)
- m_pLoader->iTotalLines = m_Blocks[iBlock * 2 + 1];
+ m_pLoader->iTotalLines = GetBlockLength(iBlock);
Loader(szText.width, &fLinePos, true);
if (iCount == 0 && m_pLoader->fStartLineOffset < 0.1f)
UpdateAlign(szText.height, fLinePos);
} else if (m_pTextDataNode) {
if (iBlock * 2 < iCount - 2)
- m_pLoader->iTotalLines = m_Blocks[iBlock * 2 + 1];
+ m_pLoader->iTotalLines = GetBlockLength(iBlock);
m_pBreak->Reset();
if (m_bRichText) {
@@ -550,7 +551,8 @@
} else {
fLinePos = 0;
}
- iLineIndex = m_Blocks[iBlockCount - 1] + m_Blocks[iBlockCount - 2];
+ int32_t iLast = iBlockCount / 2 - 1;
+ iLineIndex = GetBlockIndex(iLast) + GetBlockLength(iLast);
}
int32_t i = 0;
@@ -592,10 +594,9 @@
int32_t iPieceLines = pdfium::CollectionSize<int32_t>(m_pieceLines);
int32_t iCount = pdfium::CollectionSize<int32_t>(m_Blocks);
if (iCount > 0) {
- iBlock *= 2;
- if (iBlock < iCount) {
- iLineStart = m_Blocks[iBlock];
- iPieceLines = m_Blocks[iBlock + 1];
+ if (iBlock * 2 < iCount) {
+ iLineStart = GetBlockIndex(iBlock);
+ iPieceLines = GetBlockLength(iBlock);
} else {
iPieceLines = 0;
}
diff --git a/xfa/fxfa/cxfa_textlayout.h b/xfa/fxfa/cxfa_textlayout.h
index f6ca196..64c4c89 100644
--- a/xfa/fxfa/cxfa_textlayout.h
+++ b/xfa/fxfa/cxfa_textlayout.h
@@ -111,6 +111,8 @@
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 * 2]; }
+ int32_t& GetBlockLength(int32_t index) { return m_Blocks[index * 2 + 1]; }
bool m_bHasBlock = false;
bool m_bRichText = false;