From 267d2a862fd9ec7bc722533914e8e5af8a19df26 Mon Sep 17 00:00:00 2001 From: Nicolas Pena Date: Fri, 10 Nov 2017 19:22:24 +0000 Subject: Cleanup public methods of CXFA_TextLayout MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I532c3d7b76b650bbc262925b6a4a26f596a16814 Reviewed-on: https://pdfium-review.googlesource.com/18331 Reviewed-by: Ryan Harrison Commit-Queue: Nicolás Peña Moreno --- xfa/fxfa/cxfa_fffield.cpp | 10 ++-- xfa/fxfa/cxfa_ffpushbutton.cpp | 6 +-- xfa/fxfa/cxfa_textlayout.cpp | 106 +++++++++++++++++++---------------------- xfa/fxfa/cxfa_textlayout.h | 28 +++++------ xfa/fxfa/cxfa_widgetacc.cpp | 7 +-- 5 files changed, 72 insertions(+), 85 deletions(-) (limited to 'xfa/fxfa') diff --git a/xfa/fxfa/cxfa_fffield.cpp b/xfa/fxfa/cxfa_fffield.cpp index 67a4cb1aca..a58fd00cce 100644 --- a/xfa/fxfa/cxfa_fffield.cpp +++ b/xfa/fxfa/cxfa_fffield.cpp @@ -216,10 +216,9 @@ void CXFA_FFField::CapPlacement() { CXFA_TextLayout* pCapTextLayout = m_pDataAcc->GetCaptionTextLayout(); if (fCapReserve <= 0 && pCapTextLayout) { - CFX_SizeF size; CFX_SizeF minSize; CFX_SizeF maxSize; - pCapTextLayout->CalcSize(minSize, maxSize, size); + CFX_SizeF size = pCapTextLayout->CalcSize(minSize, maxSize); if (iCapPlacement == XFA_ATTRIBUTEENUM_Top || iCapPlacement == XFA_ATTRIBUTEENUM_Bottom) { fCapReserve = size.height; @@ -592,9 +591,8 @@ void CXFA_FFField::LayoutCaption() { if (!pCapTextLayout) return; - float fHeight = 0; - pCapTextLayout->Layout(CFX_SizeF(m_rtCaption.width, m_rtCaption.height), - &fHeight); + float fHeight = + pCapTextLayout->Layout(CFX_SizeF(m_rtCaption.width, m_rtCaption.height)); if (m_rtCaption.height < fHeight) m_rtCaption.height = fHeight; } @@ -619,7 +617,7 @@ void CXFA_FFField::RenderCaption(CXFA_Graphics* pGS, CFX_Matrix* pMatrix) { rtClip = pMatrix->TransformRect(rtClip); mt.Concat(*pMatrix); } - pCapTextLayout->DrawString(pRenderDevice, mt, rtClip); + pCapTextLayout->DrawString(pRenderDevice, mt, rtClip, 0); } bool CXFA_FFField::ProcessCommittedData() { diff --git a/xfa/fxfa/cxfa_ffpushbutton.cpp b/xfa/fxfa/cxfa_ffpushbutton.cpp index fbadfcecd2..c966cdacfd 100644 --- a/xfa/fxfa/cxfa_ffpushbutton.cpp +++ b/xfa/fxfa/cxfa_ffpushbutton.cpp @@ -182,15 +182,15 @@ void CXFA_FFPushButton::RenderHighlightCaption(CXFA_Graphics* pGS, uint32_t dwState = m_pNormalWidget->GetStates(); if (m_pDownTextLayout && (dwState & FWL_STATE_PSB_Pressed) && (dwState & FWL_STATE_PSB_Hovered)) { - if (m_pDownTextLayout->DrawString(pRenderDevice, mt, rtClip)) + if (m_pDownTextLayout->DrawString(pRenderDevice, mt, rtClip, 0)) return; } else if (m_pRolloverTextLayout && (dwState & FWL_STATE_PSB_Hovered)) { - if (m_pRolloverTextLayout->DrawString(pRenderDevice, mt, rtClip)) + if (m_pRolloverTextLayout->DrawString(pRenderDevice, mt, rtClip, 0)) return; } if (pCapTextLayout) - pCapTextLayout->DrawString(pRenderDevice, mt, rtClip); + pCapTextLayout->DrawString(pRenderDevice, mt, rtClip, 0); } void CXFA_FFPushButton::OnProcessMessage(CFWL_Message* pMessage) { diff --git a/xfa/fxfa/cxfa_textlayout.cpp b/xfa/fxfa/cxfa_textlayout.cpp index 9be3c4f5fa..532079e4a7 100644 --- a/xfa/fxfa/cxfa_textlayout.cpp +++ b/xfa/fxfa/cxfa_textlayout.cpp @@ -246,10 +246,9 @@ float CXFA_TextLayout::GetLayoutHeight() { if (m_pLoader->m_lineHeights.empty() && m_pLoader->m_fWidth > 0) { CFX_SizeF szMax(m_pLoader->m_fWidth, m_pLoader->m_fHeight); - CFX_SizeF szDef; m_pLoader->m_bSaveLineHeight = true; m_pLoader->m_fLastPos = 0; - CalcSize(szMax, szMax, szDef); + CFX_SizeF szDef = CalcSize(szMax, szMax); m_pLoader->m_bSaveLineHeight = false; return szDef.height; } @@ -276,24 +275,24 @@ float CXFA_TextLayout::StartLayout(float fWidth) { } m_pLoader->m_fWidth = fWidth; - if (fWidth < 0) { - CFX_SizeF szMax; - CFX_SizeF szDef; - m_pLoader->m_bSaveLineHeight = true; - m_pLoader->m_fLastPos = 0; - CalcSize(szMax, szMax, szDef); - m_pLoader->m_bSaveLineHeight = false; - fWidth = szDef.width; - } - return fWidth; + if (fWidth >= 0) + return fWidth; + + CFX_SizeF szMax; + + m_pLoader->m_bSaveLineHeight = true; + m_pLoader->m_fLastPos = 0; + CFX_SizeF szDef = CalcSize(szMax, szMax); + m_pLoader->m_bSaveLineHeight = false; + return szDef.width; } -bool CXFA_TextLayout::DoLayout(int32_t iBlockIndex, - float& fCalcHeight, - float fContentAreaHeight, - float fTextHeight) { +float CXFA_TextLayout::DoLayout(int32_t iBlockIndex, + float fCalcHeight, + float fContentAreaHeight, + float fTextHeight) { if (!m_pLoader) - return false; + return fCalcHeight; int32_t iBlockCount = pdfium::CollectionSize(m_Blocks); float fHeight = fTextHeight; @@ -302,7 +301,7 @@ bool CXFA_TextLayout::DoLayout(int32_t iBlockIndex, m_pLoader->m_fHeight = fHeight; if (fContentAreaHeight < 0) - return false; + return fCalcHeight; m_bHasBlock = true; if (iBlockCount == 0 && fHeight > 0) { @@ -335,10 +334,9 @@ bool CXFA_TextLayout::DoLayout(int32_t iBlockIndex, int32_t i = 0; for (i = iLineIndex; i < iCount; i++) { float fLineHeight = m_pLoader->m_lineHeights[i]; - if (i == iLineIndex && fLineHeight - fContentAreaHeight > 0.001) { - fCalcHeight = 0; - return true; - } + if (i == iLineIndex && fLineHeight - fContentAreaHeight > 0.001) + return 0; + if (fLinePos + fLineHeight - fContentAreaHeight > 0.001) { if (iBlockCount >= (iBlockIndex + 1) * 2) { m_Blocks[iBlockIndex * 2] = iLineIndex; @@ -358,15 +356,13 @@ bool CXFA_TextLayout::DoLayout(int32_t iBlockIndex, m_pLoader->m_BlocksHeight.push_back(fCalcHeight); } } - return true; + return fCalcHeight; } - - fCalcHeight = fLinePos; - return true; + return fLinePos; } fLinePos += fLineHeight; } - return false; + return fCalcHeight; } int32_t CXFA_TextLayout::CountBlocks() const { @@ -374,29 +370,27 @@ int32_t CXFA_TextLayout::CountBlocks() const { return iCount > 0 ? iCount : 1; } -bool CXFA_TextLayout::CalcSize(const CFX_SizeF& minSize, - const CFX_SizeF& maxSize, - CFX_SizeF& defaultSize) { - defaultSize.width = maxSize.width; - if (defaultSize.width < 1) - defaultSize.width = 0xFFFF; +CFX_SizeF CXFA_TextLayout::CalcSize(const CFX_SizeF& minSize, + const CFX_SizeF& maxSize) { + float width = maxSize.width; + if (width < 1) + width = 0xFFFF; m_pBreak = CreateBreak(false); float fLinePos = 0; m_iLines = 0; m_fMaxWidth = 0; - Loader(defaultSize, fLinePos, false); + Loader(width, fLinePos, false); if (fLinePos < 0.1f) fLinePos = m_textParser.GetFontSize(m_pTextProvider, nullptr); m_pTabstopContext.reset(); - defaultSize = CFX_SizeF(m_fMaxWidth, fLinePos); - return true; + return CFX_SizeF(m_fMaxWidth, fLinePos); } -bool CXFA_TextLayout::Layout(const CFX_SizeF& size, float* fHeight) { +float CXFA_TextLayout::Layout(const CFX_SizeF& size) { if (size.width < 1) - return false; + return 0.f; Unload(); m_pBreak = CreateBreak(true); @@ -407,12 +401,10 @@ bool CXFA_TextLayout::Layout(const CFX_SizeF& size, float* fHeight) { m_iLines = 0; float fLinePos = 0; - Loader(size, fLinePos, true); + Loader(size.width, fLinePos, true); UpdateAlign(size.height, fLinePos); m_pTabstopContext.reset(); - if (fHeight) - *fHeight = fLinePos; - return true; + return fLinePos; } bool CXFA_TextLayout::Layout(int32_t iBlock) { @@ -443,7 +435,7 @@ bool CXFA_TextLayout::Layout(int32_t iBlock) { if (iCount > 1) m_pLoader->m_iTotalLines = m_Blocks[iBlock * 2 + 1]; - Loader(szText, fLinePos, true); + Loader(szText.width, fLinePos, true); if (iCount == 0 && m_pLoader->m_fStartLineOffset < 0.1f) UpdateAlign(szText.height, fLinePos); } else if (m_pTextDataNode) { @@ -464,8 +456,8 @@ bool CXFA_TextLayout::Layout(int32_t iBlock) { CFX_XMLNode* pSaveXMLNode = m_pLoader->m_pXMLNode; for (; pXMLNode; pXMLNode = pXMLNode->GetNodeItem(CFX_XMLNode::NextSibling)) { - if (!LoadRichText(pXMLNode, szText, fLinePos, m_pLoader->m_pParentStyle, - true, nullptr)) { + if (!LoadRichText(pXMLNode, szText.width, fLinePos, + m_pLoader->m_pParentStyle, true, nullptr)) { break; } } @@ -473,8 +465,8 @@ bool CXFA_TextLayout::Layout(int32_t iBlock) { pXMLNode = pSaveXMLNode->GetNodeItem(CFX_XMLNode::Parent); if (pXMLNode == pContainerNode) break; - if (!LoadRichText(pXMLNode, szText, fLinePos, m_pLoader->m_pParentStyle, - true, nullptr, false)) { + if (!LoadRichText(pXMLNode, szText.width, fLinePos, + m_pLoader->m_pParentStyle, true, nullptr, false)) { break; } pSaveXMLNode = pXMLNode; @@ -483,7 +475,7 @@ bool CXFA_TextLayout::Layout(int32_t iBlock) { continue; for (; pXMLNode; pXMLNode = pXMLNode->GetNodeItem(CFX_XMLNode::NextSibling)) { - if (!LoadRichText(pXMLNode, szText, fLinePos, + if (!LoadRichText(pXMLNode, szText.width, fLinePos, m_pLoader->m_pParentStyle, true, nullptr)) { break; } @@ -493,7 +485,7 @@ bool CXFA_TextLayout::Layout(int32_t iBlock) { pNode = m_pLoader->m_pNode; if (!pNode) return true; - LoadText(pNode, szText, fLinePos, true); + LoadText(pNode, szText.width, fLinePos, true); } } if (iBlock == iCount) { @@ -624,7 +616,7 @@ void CXFA_TextLayout::UpdateAlign(float fHeight, float fBottom) { } } -bool CXFA_TextLayout::Loader(const CFX_SizeF& szText, +bool CXFA_TextLayout::Loader(float textWidth, float& fLinePos, bool bSavePieces) { GetTextDataNode(); @@ -638,20 +630,20 @@ bool CXFA_TextLayout::Loader(const CFX_SizeF& szText, m_textParser.DoParse(pXMLContainer, m_pTextProvider); auto pRootStyle = m_textParser.CreateRootStyle(m_pTextProvider); - LoadRichText(pXMLContainer, szText, fLinePos, pRootStyle, bSavePieces, + LoadRichText(pXMLContainer, textWidth, fLinePos, pRootStyle, bSavePieces, nullptr); } } else { - LoadText(m_pTextDataNode, szText, fLinePos, bSavePieces); + LoadText(m_pTextDataNode, textWidth, fLinePos, bSavePieces); } return true; } void CXFA_TextLayout::LoadText(CXFA_Node* pNode, - const CFX_SizeF& szText, + float textWidth, float& fLinePos, bool bSavePieces) { - InitBreak(szText.width); + InitBreak(textWidth); CXFA_ParaData paraData = m_pTextProvider->GetParaData(); float fSpaceAbove = 0; @@ -682,7 +674,7 @@ void CXFA_TextLayout::LoadText(CXFA_Node* pNode, bool CXFA_TextLayout::LoadRichText( CFX_XMLNode* pXMLNode, - const CFX_SizeF& szText, + float textWidth, float& fLinePos, const RetainPtr& pParentStyle, bool bSavePieces, @@ -729,7 +721,7 @@ bool CXFA_TextLayout::LoadRichText( pStyle = m_textParser.ComputeStyle(pXMLNode, pParentStyle.Get()); InitBreak(bContentNode ? pParentStyle.Get() : pStyle.Get(), eDisplay, - szText.width, pXMLNode, pParentStyle.Get()); + textWidth, pXMLNode, pParentStyle.Get()); if ((eDisplay == CFX_CSSDisplay::Block || eDisplay == CFX_CSSDisplay::ListItem) && pStyle && @@ -828,7 +820,7 @@ bool CXFA_TextLayout::LoadRichText( if (bCurOl) iLiCount++; - if (!LoadRichText(pChildNode, szText, fLinePos, + if (!LoadRichText(pChildNode, textWidth, fLinePos, pContext ? pStyle : pParentStyle, bSavePieces, pLinkData, true, bIsOl, iLiCount)) return false; diff --git a/xfa/fxfa/cxfa_textlayout.h b/xfa/fxfa/cxfa_textlayout.h index 1811d964be..070a2bd87d 100644 --- a/xfa/fxfa/cxfa_textlayout.h +++ b/xfa/fxfa/cxfa_textlayout.h @@ -34,21 +34,19 @@ class CXFA_TextLayout { ~CXFA_TextLayout(); float GetLayoutHeight(); - float StartLayout(float fWidth = -1); - bool DoLayout(int32_t iBlockIndex, - float& fCalcHeight, - float fContentAreaHeight = -1, - float fTextHeight = -1); + float StartLayout(float fWidth); + float DoLayout(int32_t iBlockIndex, + float fCalcHeight, + float fContentAreaHeight, + float fTextHeight); + float Layout(const CFX_SizeF& size); - bool CalcSize(const CFX_SizeF& minSize, - const CFX_SizeF& maxSize, - CFX_SizeF& defaultSize); - bool Layout(const CFX_SizeF& size, float* fHeight = nullptr); + CFX_SizeF CalcSize(const CFX_SizeF& minSize, const CFX_SizeF& maxSize); void ItemBlocks(const CFX_RectF& rtText, int32_t iBlockIndex); bool DrawString(CFX_RenderDevice* pFxDevice, const CFX_Matrix& tmDoc2Device, const CFX_RectF& rtClip, - int32_t iBlock = 0); + int32_t iBlock); bool IsLoaded() const { return !m_pieceLines.empty(); } void Unload(); const std::vector>* GetPieceLines() const { @@ -67,16 +65,14 @@ class CXFA_TextLayout { CFX_CSSDisplay eDisplay, float fLineWidth, CFX_XMLNode* pXMLNode, - CFX_CSSComputedStyle* pParentStyle = nullptr); - bool Loader(const CFX_SizeF& szText, - float& fLinePos, - bool bSavePieces = true); + CFX_CSSComputedStyle* pParentStyle); + bool Loader(float textWidth, float& fLinePos, bool bSavePieces); void LoadText(CXFA_Node* pNode, - const CFX_SizeF& szText, + float textWidth, float& fLinePos, bool bSavePieces); bool LoadRichText(CFX_XMLNode* pXMLNode, - const CFX_SizeF& szText, + float textWidth, float& fLinePos, const RetainPtr& pParentStyle, bool bSavePieces, diff --git a/xfa/fxfa/cxfa_widgetacc.cpp b/xfa/fxfa/cxfa_widgetacc.cpp index 2c54c3cf49..cb43783bdc 100644 --- a/xfa/fxfa/cxfa_widgetacc.cpp +++ b/xfa/fxfa/cxfa_widgetacc.cpp @@ -709,7 +709,7 @@ void CXFA_WidgetAcc::CalcCaptionSize(CFX_SizeF& szCap) { szCap.width = fCapReserve; CFX_SizeF minSize; - pCapTextLayout->CalcSize(minSize, szCap, szCap); + szCap = pCapTextLayout->CalcSize(minSize, szCap); if (bReserveExit) bVert ? szCap.height = fCapReserve : szCap.width = fCapReserve; } else { @@ -1181,8 +1181,9 @@ bool CXFA_WidgetAcc::FindSplitPos(int32_t iBlockIndex, float& fCalcHeight) { CXFA_TextLayout* pTextLayout = static_cast(m_pLayoutData.get())->GetTextLayout(); - pTextLayout->DoLayout(iBlockIndex, fCalcHeight, fCalcHeight, - m_pLayoutData->m_fWidgetHeight - fTopInset); + fCalcHeight = + pTextLayout->DoLayout(iBlockIndex, fCalcHeight, fCalcHeight, + m_pLayoutData->m_fWidgetHeight - fTopInset); if (fCalcHeight != 0) { if (iBlockIndex == 0) fCalcHeight = fCalcHeight + fTopInset; -- cgit v1.2.3