Use even more size_t in CXFA_TextLayout.
Also rename the private Layout() to LayoutInternal() to avoid
overloading.
Change-Id: Ia8a47ec109d8bd6e8f3a95297c53c040ff0b0962
Reviewed-on: https://pdfium-review.googlesource.com/c/49716
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 89ba07e..0902bb7 100644
--- a/xfa/fxfa/cxfa_textlayout.cpp
+++ b/xfa/fxfa/cxfa_textlayout.cpp
@@ -393,9 +393,9 @@
return fCalcHeight;
}
-int32_t CXFA_TextLayout::CountBlocks() const {
- int32_t iCount = pdfium::CollectionSize<int32_t>(m_Blocks);
- return iCount > 0 ? iCount : 1;
+size_t CXFA_TextLayout::CountBlocks() const {
+ size_t szCount = m_Blocks.size();
+ return szCount > 0 ? szCount : 1;
}
size_t CXFA_TextLayout::GetNextIndexFromLastBlockData() const {
@@ -445,10 +445,10 @@
return fLinePos;
}
-bool CXFA_TextLayout::Layout(int32_t iBlock) {
- if (!m_pLoader || iBlock < 0 || iBlock >= CountBlocks())
- return false;
- if (m_pLoader->fWidth < 1)
+bool CXFA_TextLayout::LayoutInternal(size_t szBlockIndex) {
+ ASSERT(szBlockIndex < CountBlocks());
+
+ if (!m_pLoader || m_pLoader->fWidth < 1)
return false;
m_pLoader->iTotalLines = -1;
@@ -456,28 +456,25 @@
float fLinePos = 0;
CXFA_Node* pNode = nullptr;
CFX_SizeF szText(m_pLoader->fWidth, m_pLoader->fHeight);
- int32_t iCount = pdfium::CollectionSize<int32_t>(m_Blocks);
- int32_t iBlocksHeightCount =
- pdfium::CollectionSize<int32_t>(m_pLoader->blockHeights);
- if (iBlock < iBlocksHeightCount)
+ if (szBlockIndex < m_pLoader->blockHeights.size())
return true;
- if (iBlock == iBlocksHeightCount) {
+ if (szBlockIndex == m_pLoader->blockHeights.size()) {
Unload();
m_pBreak = CreateBreak(true);
fLinePos = m_pLoader->fStartLineOffset;
- for (int32_t i = 0; i < iBlocksHeightCount; i++)
+ for (size_t i = 0; i < m_pLoader->blockHeights.size(); ++i)
fLinePos -= m_pLoader->blockHeights[i].fHeight;
m_pLoader->iChar = 0;
- if (iCount > 0)
- m_pLoader->iTotalLines = m_Blocks[iBlock].szLength;
+ if (!m_Blocks.empty())
+ m_pLoader->iTotalLines = m_Blocks[szBlockIndex].szLength;
Loader(szText.width, &fLinePos, true);
- if (iCount == 0 && m_pLoader->fStartLineOffset < 0.1f)
+ if (m_Blocks.empty() && m_pLoader->fStartLineOffset < 0.1f)
UpdateAlign(szText.height, fLinePos);
} else if (m_pTextDataNode) {
- if (iBlock < iCount - 1)
- m_pLoader->iTotalLines = m_Blocks[iBlock].szLength;
+ if (!m_Blocks.empty() && szBlockIndex < m_Blocks.size() - 1)
+ m_pLoader->iTotalLines = m_Blocks[szBlockIndex].szLength;
m_pBreak->Reset();
if (m_bRichText) {
@@ -525,7 +522,7 @@
LoadText(pNode, szText.width, &fLinePos, true);
}
}
- if (iBlock == iCount) {
+ if (szBlockIndex == m_Blocks.size()) {
m_pTabstopContext.reset();
m_pLoader.reset();
}
@@ -575,9 +572,9 @@
pFxDevice->SetClip_Rect(rtClip);
if (m_pieceLines.empty()) {
- int32_t iBlockCount = CountBlocks();
- for (int32_t i = 0; i < iBlockCount; i++)
- Layout(i);
+ size_t szBlockCount = CountBlocks();
+ for (size_t i = 0; i < szBlockCount; ++i)
+ LayoutInternal(i);
}
TextCharPos* pCharPos = FX_Alloc(TextCharPos, 1);
diff --git a/xfa/fxfa/cxfa_textlayout.h b/xfa/fxfa/cxfa_textlayout.h
index c7fcf81..f09653b 100644
--- a/xfa/fxfa/cxfa_textlayout.h
+++ b/xfa/fxfa/cxfa_textlayout.h
@@ -114,8 +114,8 @@
size_t GetDisplayPos(const CXFA_TextPiece* pPiece, TextCharPos* pCharPos);
bool ToRun(const CXFA_TextPiece* pPiece, FX_RTFTEXTOBJ* tr);
void DoTabstops(CFX_CSSComputedStyle* pStyle, CXFA_PieceLine* pPieceLine);
- bool Layout(int32_t iBlock);
- int32_t CountBlocks() const;
+ bool LayoutInternal(size_t szBlockIndex);
+ size_t CountBlocks() const;
size_t GetNextIndexFromLastBlockData() const;
void UpdateLoaderHeight(float fTextHeight);