Change CXFA_ContentLayoutItem::GetIndex() to return size_t. Update callers to work with size_t. Also remove GetCount(), which is unused. Change-Id: I6c2612b327fe8b5278360b0783bab84b126cd37c Reviewed-on: https://pdfium-review.googlesource.com/c/49714 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 037a2cf..610da73 100644 --- a/xfa/fxfa/cxfa_textlayout.cpp +++ b/xfa/fxfa/cxfa_textlayout.cpp
@@ -321,11 +321,9 @@ return fTextHeight; } -float CXFA_TextLayout::DoSplitLayout(int32_t iBlockIndex, +float CXFA_TextLayout::DoSplitLayout(size_t szBlockIndex, float fCalcHeight, float fTextHeight) { - ASSERT(iBlockIndex >= 0); - if (!m_pLoader) return fCalcHeight; @@ -334,7 +332,6 @@ if (fCalcHeight < 0) return fCalcHeight; - size_t szBlockIndex = static_cast<size_t>(iBlockIndex); m_bHasBlock = true; if (m_Blocks.empty() && m_pLoader->fHeight > 0) { float fHeight = fTextHeight - GetLayoutHeight(); @@ -535,7 +532,7 @@ return true; } -void CXFA_TextLayout::ItemBlocks(const CFX_RectF& rtText, int32_t iBlockIndex) { +void CXFA_TextLayout::ItemBlocks(const CFX_RectF& rtText, size_t szBlockIndex) { if (!m_pLoader) return; @@ -544,12 +541,9 @@ float fLinePos = m_pLoader->fStartLineOffset; size_t szLineIndex = 0; - if (iBlockIndex > 0) { - // TODO(thestig): Check this code for correctness, and convert to size_t. - int32_t iBlockHeightCount = - pdfium::CollectionSize<int32_t>(m_pLoader->blockHeights); - if (iBlockIndex <= iBlockHeightCount) { - for (int32_t i = 0; i < iBlockIndex; i++) + if (szBlockIndex > 0) { + if (szBlockIndex <= m_pLoader->blockHeights.size()) { + for (size_t i = 0; i < szBlockIndex; ++i) fLinePos -= m_pLoader->blockHeights[i].fHeight; } else { fLinePos = 0; @@ -573,7 +567,7 @@ bool CXFA_TextLayout::DrawString(CFX_RenderDevice* pFxDevice, const CFX_Matrix& tmDoc2Device, const CFX_RectF& rtClip, - int32_t iBlock) { + size_t szBlockIndex) { if (!pFxDevice) return false; @@ -592,9 +586,9 @@ int32_t iLineStart = 0; int32_t iPieceLines = pdfium::CollectionSize<int32_t>(m_pieceLines); if (!m_Blocks.empty()) { - if (iBlock < pdfium::CollectionSize<int32_t>(m_Blocks)) { - iLineStart = m_Blocks[iBlock].szIndex; - iPieceLines = m_Blocks[iBlock].szLength; + if (szBlockIndex < m_Blocks.size()) { + iLineStart = m_Blocks[szBlockIndex].szIndex; + iPieceLines = m_Blocks[szBlockIndex].szLength; } else { iPieceLines = 0; }
diff --git a/xfa/fxfa/cxfa_textlayout.h b/xfa/fxfa/cxfa_textlayout.h index 3a3f658..a55b757 100644 --- a/xfa/fxfa/cxfa_textlayout.h +++ b/xfa/fxfa/cxfa_textlayout.h
@@ -33,23 +33,23 @@ class CXFA_TextLayout { public: - explicit CXFA_TextLayout(CXFA_FFDoc* doc, CXFA_TextProvider* pTextProvider); + CXFA_TextLayout(CXFA_FFDoc* doc, CXFA_TextProvider* pTextProvider); ~CXFA_TextLayout(); float GetLayoutHeight(); float StartLayout(float fWidth); float DoLayout(float fTextHeight); - float DoSplitLayout(int32_t iBlockIndex, + float DoSplitLayout(size_t szBlockIndex, float fCalcHeight, float fTextHeight); float Layout(const CFX_SizeF& size); CFX_SizeF CalcSize(const CFX_SizeF& minSize, const CFX_SizeF& maxSize); - void ItemBlocks(const CFX_RectF& rtText, int32_t iBlockIndex); + void ItemBlocks(const CFX_RectF& rtText, size_t szBlockIndex); bool DrawString(CFX_RenderDevice* pFxDevice, const CFX_Matrix& tmDoc2Device, const CFX_RectF& rtClip, - int32_t iBlock); + size_t szBlockIndex); bool IsLoaded() const { return !m_pieceLines.empty(); } void Unload();
diff --git a/xfa/fxfa/parser/cxfa_contentlayoutitem.cpp b/xfa/fxfa/parser/cxfa_contentlayoutitem.cpp index 79b3cb7..58e65e0 100644 --- a/xfa/fxfa/parser/cxfa_contentlayoutitem.cpp +++ b/xfa/fxfa/parser/cxfa_contentlayoutitem.cpp
@@ -97,22 +97,12 @@ return CFX_RectF(sPos, sSize); } -int32_t CXFA_ContentLayoutItem::GetIndex() const { - int32_t iIndex = 0; +size_t CXFA_ContentLayoutItem::GetIndex() const { + size_t szIndex = 0; const CXFA_ContentLayoutItem* pCurNode = this; while (auto* pPrev = pCurNode->GetPrev()) { pCurNode = pPrev; - ++iIndex; + ++szIndex; } - return iIndex; -} - -int32_t CXFA_ContentLayoutItem::GetCount() const { - int32_t iCount = GetIndex() + 1; - const CXFA_ContentLayoutItem* pCurNode = this; - while (auto* pNext = pCurNode->GetNext()) { - pCurNode = pNext; - iCount++; - } - return iCount; + return szIndex; }
diff --git a/xfa/fxfa/parser/cxfa_contentlayoutitem.h b/xfa/fxfa/parser/cxfa_contentlayoutitem.h index 7313a1e..b002e88 100644 --- a/xfa/fxfa/parser/cxfa_contentlayoutitem.h +++ b/xfa/fxfa/parser/cxfa_contentlayoutitem.h
@@ -26,8 +26,7 @@ void InsertAfter(CXFA_ContentLayoutItem* pNext); CFX_RectF GetRect(bool bRelative) const; - int32_t GetIndex() const; - int32_t GetCount() const; + size_t GetIndex() const; CFX_PointF m_sPos; CFX_SizeF m_sSize;
diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp index c32fd48..08fe391 100644 --- a/xfa/fxfa/parser/cxfa_node.cpp +++ b/xfa/fxfa/parser/cxfa_node.cpp
@@ -3438,7 +3438,7 @@ } bool CXFA_Node::FindSplitPos(CXFA_FFDocView* docView, - int32_t iBlockIndex, + size_t szBlockIndex, float* pCalcHeight) { if (GetFFWidgetType() == XFA_FFWidgetType::kSubform) return false; @@ -3456,7 +3456,7 @@ float fTopInset = 0; float fBottomInset = 0; - if (iBlockIndex == 0) { + if (szBlockIndex == 0) { CXFA_Margin* margin = GetMarginIfExists(); if (margin) { fTopInset = margin->GetTopInset(); @@ -3469,16 +3469,16 @@ } if (GetFFWidgetType() == XFA_FFWidgetType::kText) { float fHeight = *pCalcHeight; - if (iBlockIndex == 0) { + if (szBlockIndex == 0) { *pCalcHeight -= fTopInset; *pCalcHeight = std::max(*pCalcHeight, 0.0f); } CXFA_TextLayout* pTextLayout = m_pLayoutData->AsTextLayoutData()->GetTextLayout(); *pCalcHeight = pTextLayout->DoSplitLayout( - iBlockIndex, *pCalcHeight, m_pLayoutData->m_fWidgetHeight - fTopInset); + szBlockIndex, *pCalcHeight, m_pLayoutData->m_fWidgetHeight - fTopInset); if (*pCalcHeight != 0) { - if (iBlockIndex == 0) + if (szBlockIndex == 0) *pCalcHeight += fTopInset; if (fabs(fHeight - *pCalcHeight) < kXFAWidgetPrecision) return false; @@ -3488,7 +3488,7 @@ XFA_AttributeValue iCapPlacement = XFA_AttributeValue::Unknown; float fCapReserve = 0; - if (iBlockIndex == 0) { + if (szBlockIndex == 0) { CXFA_Caption* caption = GetCaptionIfExists(); if (caption && !caption->IsHidden()) { iCapPlacement = caption->GetPlacementType(); @@ -3522,11 +3522,11 @@ iLinesCount = pFieldData->m_pTextOut->GetTotalLines(); } std::vector<float>* pFieldArray = &pFieldData->m_FieldSplitArray; - int32_t iFieldSplitCount = pdfium::CollectionSize<int32_t>(*pFieldArray); - if (iFieldSplitCount < (iBlockIndex * 3)) + size_t szFieldSplitCount = pFieldArray->size(); + if (szFieldSplitCount < szBlockIndex * 3) return false; - for (int32_t i = 0; i < iBlockIndex * 3; i += 3) { + for (size_t i = 0; i < szBlockIndex * 3; i += 3) { iLinesCount -= (int32_t)(*pFieldArray)[i + 1]; fHeight -= (*pFieldArray)[i + 2]; } @@ -3538,7 +3538,7 @@ float fTextHeight = iLinesCount * fLineHeight - fLineHeight + fFontSize; float fSpaceAbove = 0; float fStartOffset = 0; - if (fHeight > 0.1f && iBlockIndex == 0) { + if (fHeight > 0.1f && szBlockIndex == 0) { fStartOffset = fTopInset; fHeight -= (fTopInset + fBottomInset); CXFA_Para* para = GetParaIfExists(); @@ -3564,12 +3564,13 @@ if (fStartOffset < 0.1f) fStartOffset = 0; } - for (int32_t i = iBlockIndex - 1; iBlockIndex > 0 && i < iBlockIndex; i++) { + if (szBlockIndex > 0) { + size_t i = szBlockIndex - 1; fStartOffset = (*pFieldArray)[i * 3] - (*pFieldArray)[i * 3 + 2]; if (fStartOffset < 0.1f) fStartOffset = 0; } - if (iFieldSplitCount / 3 == (iBlockIndex + 1)) + if (szFieldSplitCount / 3 == (szBlockIndex + 1)) (*pFieldArray)[0] = fStartOffset; else pFieldArray->push_back(fStartOffset); @@ -3602,9 +3603,9 @@ return true; } if (fStartOffset + kXFAWidgetPrecision >= *pCalcHeight) { - if (iFieldSplitCount / 3 == (iBlockIndex + 1)) { - (*pFieldArray)[iBlockIndex * 3 + 1] = 0; - (*pFieldArray)[iBlockIndex * 3 + 2] = *pCalcHeight; + if (szFieldSplitCount / 3 == (szBlockIndex + 1)) { + (*pFieldArray)[szBlockIndex * 3 + 1] = 0; + (*pFieldArray)[szBlockIndex * 3 + 2] = *pCalcHeight; } else { pFieldArray->push_back(0); pFieldArray->push_back(*pCalcHeight); @@ -3613,9 +3614,9 @@ } if (*pCalcHeight - fStartOffset < fLineHeight) { *pCalcHeight = fStartOffset; - if (iFieldSplitCount / 3 == (iBlockIndex + 1)) { - (*pFieldArray)[iBlockIndex * 3 + 1] = 0; - (*pFieldArray)[iBlockIndex * 3 + 2] = *pCalcHeight; + if (szFieldSplitCount / 3 == (szBlockIndex + 1)) { + (*pFieldArray)[szBlockIndex * 3 + 1] = 0; + (*pFieldArray)[szBlockIndex * 3 + 2] = *pCalcHeight; } else { pFieldArray->push_back(0); pFieldArray->push_back(*pCalcHeight); @@ -3628,9 +3629,9 @@ (int32_t)((fTextNum + (fLineHeight - fFontSize)) / fLineHeight); if (iLineNum >= iLinesCount) { if (*pCalcHeight - fStartOffset - fTextHeight >= fFontSize) { - if (iFieldSplitCount / 3 == (iBlockIndex + 1)) { - (*pFieldArray)[iBlockIndex * 3 + 1] = iLinesCount; - (*pFieldArray)[iBlockIndex * 3 + 2] = *pCalcHeight; + if (szFieldSplitCount / 3 == (szBlockIndex + 1)) { + (*pFieldArray)[szBlockIndex * 3 + 1] = iLinesCount; + (*pFieldArray)[szBlockIndex * 3 + 2] = *pCalcHeight; } else { pFieldArray->push_back(iLinesCount); pFieldArray->push_back(*pCalcHeight); @@ -3649,9 +3650,9 @@ } if (iLineNum > 0) { float fSplitHeight = iLineNum * fLineHeight + fCapReserve + fStartOffset; - if (iFieldSplitCount / 3 == (iBlockIndex + 1)) { - (*pFieldArray)[iBlockIndex * 3 + 1] = iLineNum; - (*pFieldArray)[iBlockIndex * 3 + 2] = fSplitHeight; + if (szFieldSplitCount / 3 == (szBlockIndex + 1)) { + (*pFieldArray)[szBlockIndex * 3 + 1] = iLineNum; + (*pFieldArray)[szBlockIndex * 3 + 2] = fSplitHeight; } else { pFieldArray->push_back(iLineNum); pFieldArray->push_back(fSplitHeight);
diff --git a/xfa/fxfa/parser/cxfa_node.h b/xfa/fxfa/parser/cxfa_node.h index 0bd1bde..941d5fc 100644 --- a/xfa/fxfa/parser/cxfa_node.h +++ b/xfa/fxfa/parser/cxfa_node.h
@@ -283,7 +283,7 @@ float* pCalcWidth, float* pCalcHeight); bool FindSplitPos(CXFA_FFDocView* docView, - int32_t iBlockIndex, + size_t szBlockIndex, float* pCalcHeight); bool LoadCaption(CXFA_FFDoc* doc);