From c222907f453e8a0e6376a86f89354eedb8285854 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Tue, 7 Feb 2017 09:04:28 -0500 Subject: Cleanup out params in XFA layout code. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This CL converts some of the out parameters in the XFA layout code to pointers instead of references. Change-Id: I6246b91b975e7bc08f8cfb040de9dfdc3c3bedee Reviewed-on: https://pdfium-review.googlesource.com/2531 Commit-Queue: dsinclair Reviewed-by: Nicolás Peña --- xfa/fxfa/app/xfa_fffield.cpp | 7 +- xfa/fxfa/app/xfa_ffnotify.cpp | 2 +- xfa/fxfa/app/xfa_fftext.cpp | 3 +- xfa/fxfa/app/xfa_ffwidget.cpp | 12 +- xfa/fxfa/parser/cscript_layoutpseudomodel.cpp | 5 +- xfa/fxfa/parser/cxfa_layoutitem.cpp | 10 +- xfa/fxfa/parser/cxfa_layoutitem.h | 4 +- xfa/fxfa/parser/cxfa_layoutpagemgr.cpp | 12 +- xfa/fxfa/parser/xfa_layout_itemlayout.cpp | 779 ++++++++++++-------------- xfa/fxfa/parser/xfa_layout_itemlayout.h | 38 +- xfa/fxfa/xfa_ffwidget.h | 2 +- 11 files changed, 409 insertions(+), 465 deletions(-) (limited to 'xfa/fxfa') diff --git a/xfa/fxfa/app/xfa_fffield.cpp b/xfa/fxfa/app/xfa_fffield.cpp index a8ee0b9acc..c053a8c6ca 100644 --- a/xfa/fxfa/app/xfa_fffield.cpp +++ b/xfa/fxfa/app/xfa_fffield.cpp @@ -30,6 +30,7 @@ CXFA_FFField::CXFA_FFField(CXFA_WidgetAcc* pDataAcc) m_rtUI.Set(0, 0, 0, 0); m_rtCaption.Set(0, 0, 0, 0); } + CXFA_FFField::~CXFA_FFField() { CXFA_FFField::UnloadWidget(); } @@ -196,12 +197,10 @@ void CXFA_FFField::CapPlacement() { rtWidget.height); } else { pItem = pItem->GetFirst(); - pItem->GetRect(m_rtCaption); + m_rtCaption = pItem->GetRect(false); pItem = pItem->GetNext(); while (pItem) { - CFX_RectF rtRect; - pItem->GetRect(rtRect); - m_rtCaption.height += rtRect.Height(); + m_rtCaption.height += pItem->GetRect(false).Height(); pItem = pItem->GetNext(); } XFA_RectWidthoutMargin(m_rtCaption, mgWidget); diff --git a/xfa/fxfa/app/xfa_ffnotify.cpp b/xfa/fxfa/app/xfa_ffnotify.cpp index d84ac0de37..0ea7a9c4e1 100644 --- a/xfa/fxfa/app/xfa_ffnotify.cpp +++ b/xfa/fxfa/app/xfa_ffnotify.cpp @@ -489,7 +489,7 @@ void CXFA_FFNotify::OnLayoutItemAdded(CXFA_LayoutProcessor* pLayout, if (pWidget->IsLoaded()) { CFX_RectF rtOld; pWidget->GetWidgetRect(rtOld); - if (rtOld != pWidget->ReCacheWidgetRect()) + if (rtOld != pWidget->RecacheWidgetRect()) pWidget->PerformLayout(); } else { pWidget->LoadWidget(); diff --git a/xfa/fxfa/app/xfa_fftext.cpp b/xfa/fxfa/app/xfa_fftext.cpp index 0cc6651d21..b87645d8a7 100644 --- a/xfa/fxfa/app/xfa_fftext.cpp +++ b/xfa/fxfa/app/xfa_fftext.cpp @@ -86,8 +86,7 @@ bool CXFA_FFText::PerformLayout() { } pItem = pItem->GetFirst(); while (pItem) { - CFX_RectF rtText; - pItem->GetRect(rtText); + CFX_RectF rtText = pItem->GetRect(false); if (CXFA_Margin mgWidget = m_pDataAcc->GetMargin()) { if (!pItem->GetPrev()) { FX_FLOAT fTopInset; diff --git a/xfa/fxfa/app/xfa_ffwidget.cpp b/xfa/fxfa/app/xfa_ffwidget.cpp index 29b10dd195..95cfe2e59f 100644 --- a/xfa/fxfa/app/xfa_ffwidget.cpp +++ b/xfa/fxfa/app/xfa_ffwidget.cpp @@ -46,15 +46,13 @@ const CFWL_App* CXFA_FFWidget::GetFWLApp() { } void CXFA_FFWidget::GetWidgetRect(CFX_RectF& rtWidget) { - if ((m_dwStatus & XFA_WidgetStatus_RectCached) == 0) { - m_dwStatus |= XFA_WidgetStatus_RectCached; - GetRect(m_rtWidget); - } + if ((m_dwStatus & XFA_WidgetStatus_RectCached) == 0) + RecacheWidgetRect(); rtWidget = m_rtWidget; } -CFX_RectF CXFA_FFWidget::ReCacheWidgetRect() { +CFX_RectF CXFA_FFWidget::RecacheWidgetRect() { m_dwStatus |= XFA_WidgetStatus_RectCached; - GetRect(m_rtWidget); + m_rtWidget = GetRect(false); return m_rtWidget; } void CXFA_FFWidget::GetRectWithoutRotate(CFX_RectF& rtWidget) { @@ -136,7 +134,7 @@ bool CXFA_FFWidget::LoadWidget() { } void CXFA_FFWidget::UnloadWidget() {} bool CXFA_FFWidget::PerformLayout() { - ReCacheWidgetRect(); + RecacheWidgetRect(); return true; } bool CXFA_FFWidget::UpdateFWLData() { diff --git a/xfa/fxfa/parser/cscript_layoutpseudomodel.cpp b/xfa/fxfa/parser/cscript_layoutpseudomodel.cpp index 7c0b93a671..152b568619 100644 --- a/xfa/fxfa/parser/cscript_layoutpseudomodel.cpp +++ b/xfa/fxfa/parser/cscript_layoutpseudomodel.cpp @@ -90,7 +90,7 @@ void CScript_LayoutPseudoModel::HWXY(CFXJSE_Arguments* pArguments, if (!pDocLayout) { return; } - CFX_RectF rtRect; + CXFA_Measurement measure; CXFA_LayoutItem* pLayoutItem = pDocLayout->GetLayoutItem(pNode); if (!pLayoutItem) { @@ -105,7 +105,8 @@ void CScript_LayoutPseudoModel::HWXY(CFXJSE_Arguments* pArguments, pValue->SetFloat(0); return; } - pLayoutItem->GetRect(rtRect, true); + + CFX_RectF rtRect = pLayoutItem->GetRect(true); switch (layoutModel) { case XFA_LAYOUTMODEL_H: measure.Set(rtRect.height, XFA_UNIT_Pt); diff --git a/xfa/fxfa/parser/cxfa_layoutitem.cpp b/xfa/fxfa/parser/cxfa_layoutitem.cpp index 55aa285e2d..7a373e1e9a 100644 --- a/xfa/fxfa/parser/cxfa_layoutitem.cpp +++ b/xfa/fxfa/parser/cxfa_layoutitem.cpp @@ -61,16 +61,16 @@ CXFA_ContainerLayoutItem* CXFA_LayoutItem::GetPage() const { return nullptr; } -void CXFA_LayoutItem::GetRect(CFX_RectF& rtLayout, bool bRelative) const { +CFX_RectF CXFA_LayoutItem::GetRect(bool bRelative) const { ASSERT(m_bIsContentLayoutItem); - const CXFA_ContentLayoutItem* pThis = - static_cast(this); + auto pThis = static_cast(this); CFX_PointF sPos = pThis->m_sPos; CFX_SizeF sSize = pThis->m_sSize; if (bRelative) { + CFX_RectF rtLayout; rtLayout.Set(sPos.x, sPos.y, sSize.x, sSize.y); - return; + return rtLayout; } for (CXFA_LayoutItem* pLayoutItem = pThis->m_pParent; pLayoutItem; @@ -100,7 +100,9 @@ void CXFA_LayoutItem::GetRect(CFX_RectF& rtLayout, bool bRelative) const { break; } + CFX_RectF rtLayout; rtLayout.Set(sPos.x, sPos.y, sSize.x, sSize.y); + return rtLayout; } CXFA_LayoutItem* CXFA_LayoutItem::GetFirst() { diff --git a/xfa/fxfa/parser/cxfa_layoutitem.h b/xfa/fxfa/parser/cxfa_layoutitem.h index 00f1917433..9c088601ef 100644 --- a/xfa/fxfa/parser/cxfa_layoutitem.h +++ b/xfa/fxfa/parser/cxfa_layoutitem.h @@ -26,9 +26,11 @@ class CXFA_LayoutItem { CXFA_ContainerLayoutItem* GetPage() const; CXFA_Node* GetFormNode() const { return m_pFormNode; } - void GetRect(CFX_RectF& rtLayout, bool bRelative = false) const; + CFX_RectF GetRect(bool bRelative) const; + int32_t GetIndex() const; int32_t GetCount() const; + CXFA_LayoutItem* GetParent() const { return m_pParent; } CXFA_LayoutItem* GetFirst(); const CXFA_LayoutItem* GetLast() const; diff --git a/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp b/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp index 1bd4836a7d..169ed04c70 100644 --- a/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp +++ b/xfa/fxfa/parser/cxfa_layoutpagemgr.cpp @@ -140,14 +140,14 @@ CXFA_Node* ResolveBreakTarget(CXFA_Node* pPageSetRoot, CFX_WideString wsTargetAll(wsTargetExpr); wsTargetAll.TrimLeft(); wsTargetAll.TrimRight(); - int32_t iSpliteIndex = 0; + int32_t iSplitIndex = 0; bool bTargetAllFind = true; - while (iSpliteIndex != -1) { + while (iSplitIndex != -1) { CFX_WideString wsExpr; - int32_t iSpliteNextIndex = 0; + int32_t iSplitNextIndex = 0; if (!bTargetAllFind) { - iSpliteNextIndex = wsTargetAll.Find(' ', iSpliteIndex); - wsExpr = wsTargetAll.Mid(iSpliteIndex, iSpliteNextIndex - iSpliteIndex); + iSplitNextIndex = wsTargetAll.Find(' ', iSplitIndex); + wsExpr = wsTargetAll.Mid(iSplitIndex, iSplitNextIndex - iSplitIndex); } else { wsExpr = wsTargetAll; } @@ -175,7 +175,7 @@ CXFA_Node* ResolveBreakTarget(CXFA_Node* pPageSetRoot, if (iCount > 0 && rs.nodes[0]->IsNode()) return rs.nodes[0]->AsNode(); } - iSpliteIndex = iSpliteNextIndex; + iSplitIndex = iSplitNextIndex; } return nullptr; } diff --git a/xfa/fxfa/parser/xfa_layout_itemlayout.cpp b/xfa/fxfa/parser/xfa_layout_itemlayout.cpp index bc3c06cd49..b2f6df585c 100644 --- a/xfa/fxfa/parser/xfa_layout_itemlayout.cpp +++ b/xfa/fxfa/parser/xfa_layout_itemlayout.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include "third_party/base/ptr_util.h" @@ -25,12 +26,12 @@ namespace { -int32_t SeparateStringW(const FX_WCHAR* pStr, - int32_t iStrLen, - FX_WCHAR delimiter, - std::vector& pieces) { +std::vector SeparateStringW(const FX_WCHAR* pStr, + int32_t iStrLen, + FX_WCHAR delimiter) { + std::vector ret; if (!pStr) - return 0; + return ret; if (iStrLen < 0) iStrLen = FXSYS_wcslen(pStr); @@ -38,35 +39,35 @@ int32_t SeparateStringW(const FX_WCHAR* pStr, const FX_WCHAR* pEnd = pStr + iStrLen; while (true) { if (pStr >= pEnd || delimiter == *pStr) { - pieces.push_back(CFX_WideString(pToken, pStr - pToken)); + ret.push_back(CFX_WideString(pToken, pStr - pToken)); pToken = pStr + 1; if (pStr >= pEnd) break; } pStr++; } - return pdfium::CollectionSize(pieces); + return ret; } void UpdateWidgetSize(CXFA_ContentLayoutItem* pLayoutItem, - FX_FLOAT& fWidth, - FX_FLOAT& fHeight) { + FX_FLOAT* fWidth, + FX_FLOAT* fHeight) { CXFA_Node* pNode = pLayoutItem->m_pFormNode; switch (pNode->GetElementType()) { case XFA_Element::Subform: case XFA_Element::Area: case XFA_Element::ExclGroup: case XFA_Element::SubformSet: { - if (fWidth < -XFA_LAYOUT_FLOAT_PERCISION) - fWidth = pLayoutItem->m_sSize.x; - if (fHeight < -XFA_LAYOUT_FLOAT_PERCISION) - fHeight = pLayoutItem->m_sSize.y; + if (*fWidth < -XFA_LAYOUT_FLOAT_PERCISION) + *fWidth = pLayoutItem->m_sSize.x; + if (*fHeight < -XFA_LAYOUT_FLOAT_PERCISION) + *fHeight = pLayoutItem->m_sSize.y; break; } case XFA_Element::Draw: case XFA_Element::Field: { - pNode->GetDocument()->GetNotify()->StartFieldDrawLayout(pNode, fWidth, - fHeight); + pNode->GetDocument()->GetNotify()->StartFieldDrawLayout(pNode, *fWidth, + *fHeight); break; } default: @@ -74,88 +75,85 @@ void UpdateWidgetSize(CXFA_ContentLayoutItem* pLayoutItem, } } -void CalculateContainerSpecfiedSize(CXFA_Node* pFormNode, - FX_FLOAT& fContainerWidth, - FX_FLOAT& fContainerHeight, - bool& bContainerWidthAutoSize, - bool& bContainerHeightAutoSize) { - fContainerWidth = 0; - fContainerHeight = 0; - bContainerWidthAutoSize = true; - bContainerHeightAutoSize = true; +CFX_SizeF CalculateContainerSpecifiedSize(CXFA_Node* pFormNode, + bool* bContainerWidthAutoSize, + bool* bContainerHeightAutoSize) { + *bContainerWidthAutoSize = true; + *bContainerHeightAutoSize = true; XFA_Element eType = pFormNode->GetElementType(); CXFA_Measurement mTmpValue; + CFX_SizeF containerSize; if ((eType == XFA_Element::Subform || eType == XFA_Element::ExclGroup) && pFormNode->TryMeasure(XFA_ATTRIBUTE_W, mTmpValue, false) && mTmpValue.GetValue() > XFA_LAYOUT_FLOAT_PERCISION) { - fContainerWidth = mTmpValue.ToUnit(XFA_UNIT_Pt); - bContainerWidthAutoSize = false; + containerSize.x = mTmpValue.ToUnit(XFA_UNIT_Pt); + *bContainerWidthAutoSize = false; } if ((eType == XFA_Element::Subform || eType == XFA_Element::ExclGroup) && pFormNode->TryMeasure(XFA_ATTRIBUTE_H, mTmpValue, false) && mTmpValue.GetValue() > XFA_LAYOUT_FLOAT_PERCISION) { - fContainerHeight = mTmpValue.ToUnit(XFA_UNIT_Pt); - bContainerHeightAutoSize = false; + containerSize.y = mTmpValue.ToUnit(XFA_UNIT_Pt); + *bContainerHeightAutoSize = false; } - if (bContainerWidthAutoSize && eType == XFA_Element::Subform && + if (*bContainerWidthAutoSize && eType == XFA_Element::Subform && pFormNode->TryMeasure(XFA_ATTRIBUTE_MaxW, mTmpValue, false) && mTmpValue.GetValue() > XFA_LAYOUT_FLOAT_PERCISION) { - fContainerWidth = mTmpValue.ToUnit(XFA_UNIT_Pt); - bContainerWidthAutoSize = false; + containerSize.x = mTmpValue.ToUnit(XFA_UNIT_Pt); + *bContainerWidthAutoSize = false; } - if (bContainerHeightAutoSize && eType == XFA_Element::Subform && + if (*bContainerHeightAutoSize && eType == XFA_Element::Subform && pFormNode->TryMeasure(XFA_ATTRIBUTE_MaxH, mTmpValue, false) && mTmpValue.GetValue() > XFA_LAYOUT_FLOAT_PERCISION) { - fContainerHeight = mTmpValue.ToUnit(XFA_UNIT_Pt); - bContainerHeightAutoSize = false; + containerSize.y = mTmpValue.ToUnit(XFA_UNIT_Pt); + *bContainerHeightAutoSize = false; } + return containerSize; } -void CalculateContainerComponentSizeFromContentSize( +CFX_SizeF CalculateContainerComponentSizeFromContentSize( CXFA_Node* pFormNode, bool bContainerWidthAutoSize, FX_FLOAT fContentCalculatedWidth, - FX_FLOAT& fContainerWidth, bool bContainerHeightAutoSize, FX_FLOAT fContentCalculatedHeight, - FX_FLOAT& fContainerHeight) { + const CFX_SizeF& currentContainerSize) { + CFX_SizeF componentSize = currentContainerSize; CXFA_Node* pMarginNode = pFormNode->GetFirstChildByClass(XFA_Element::Margin); CXFA_Measurement mTmpValue; if (bContainerWidthAutoSize) { - fContainerWidth = fContentCalculatedWidth; + componentSize.x = fContentCalculatedWidth; if (pMarginNode) { if (pMarginNode->TryMeasure(XFA_ATTRIBUTE_LeftInset, mTmpValue, false)) - fContainerWidth += mTmpValue.ToUnit(XFA_UNIT_Pt); + componentSize.x += mTmpValue.ToUnit(XFA_UNIT_Pt); if (pMarginNode->TryMeasure(XFA_ATTRIBUTE_RightInset, mTmpValue, false)) - fContainerWidth += mTmpValue.ToUnit(XFA_UNIT_Pt); + componentSize.x += mTmpValue.ToUnit(XFA_UNIT_Pt); } } if (bContainerHeightAutoSize) { - fContainerHeight = fContentCalculatedHeight; + componentSize.y = fContentCalculatedHeight; if (pMarginNode) { if (pMarginNode->TryMeasure(XFA_ATTRIBUTE_TopInset, mTmpValue, false)) - fContainerHeight += mTmpValue.ToUnit(XFA_UNIT_Pt); + componentSize.y += mTmpValue.ToUnit(XFA_UNIT_Pt); if (pMarginNode->TryMeasure(XFA_ATTRIBUTE_BottomInset, mTmpValue, false)) { - fContainerHeight += mTmpValue.ToUnit(XFA_UNIT_Pt); + componentSize.y += mTmpValue.ToUnit(XFA_UNIT_Pt); } } } + return componentSize; } void RelocateTableRowCells( CXFA_ContentLayoutItem* pLayoutRow, const CFX_ArrayTemplate& rgSpecifiedColumnWidths, XFA_ATTRIBUTEENUM eLayout) { - FX_FLOAT fContainerWidth = 0; - FX_FLOAT fContainerHeight = 0; bool bContainerWidthAutoSize = true; bool bContainerHeightAutoSize = true; - CalculateContainerSpecfiedSize(pLayoutRow->m_pFormNode, fContainerWidth, - fContainerHeight, bContainerWidthAutoSize, - bContainerHeightAutoSize); + CFX_SizeF containerSize = CalculateContainerSpecifiedSize( + pLayoutRow->m_pFormNode, &bContainerWidthAutoSize, + &bContainerHeightAutoSize); CXFA_Node* pMarginNode = pLayoutRow->m_pFormNode->GetFirstChildByClass(XFA_Element::Margin); FX_FLOAT fLeftInset = 0; @@ -175,7 +173,7 @@ void RelocateTableRowCells( FX_FLOAT fContentWidthLimit = bContainerWidthAutoSize ? FLT_MAX - : fContainerWidth - fLeftInset - fRightInset; + : containerSize.x - fLeftInset - fRightInset; FX_FLOAT fContentCurrentHeight = pLayoutRow->m_sSize.y - fTopInset - fBottomInset; FX_FLOAT fContentCalculatedWidth = 0; @@ -214,7 +212,7 @@ void RelocateTableRowCells( fCurrentColX += fColSpanWidth; nCurrentColIdx += nColSpan; FX_FLOAT fNewHeight = bContainerHeightAutoSize ? -1 : fContentCurrentHeight; - UpdateWidgetSize(pLayoutChild, fColSpanWidth, fNewHeight); + UpdateWidgetSize(pLayoutChild, &fColSpanWidth, &fNewHeight); pLayoutChild->m_sSize.y = fNewHeight; if (bContainerHeightAutoSize) { fContentCalculatedHeight = @@ -227,8 +225,8 @@ void RelocateTableRowCells( (CXFA_ContentLayoutItem*)pLayoutRow->m_pFirstChild; pLayoutChild; pLayoutChild = (CXFA_ContentLayoutItem*)pLayoutChild->m_pNextSibling) { - UpdateWidgetSize(pLayoutChild, pLayoutChild->m_sSize.x, - fContentCalculatedHeight); + UpdateWidgetSize(pLayoutChild, &pLayoutChild->m_sSize.x, + &fContentCalculatedHeight); FX_FLOAT fOldChildHeight = pLayoutChild->m_sSize.y; pLayoutChild->m_sSize.y = fContentCalculatedHeight; CXFA_Node* pParaNode = @@ -269,7 +267,7 @@ void RelocateTableRowCells( fContentCalculatedWidth = std::max(fContentCalculatedWidth, fChildSuppliedWidth); } else { - fContentCalculatedWidth = fContainerWidth - fLeftInset - fRightInset; + fContentCalculatedWidth = containerSize.x - fLeftInset - fRightInset; } if (pLayoutRow->m_pFormNode->GetEnum(XFA_ATTRIBUTE_Layout) == @@ -282,11 +280,9 @@ void RelocateTableRowCells( pLayoutChild->m_sPos.x - pLayoutChild->m_sSize.x; } } - CalculateContainerComponentSizeFromContentSize( + pLayoutRow->m_sSize = CalculateContainerComponentSizeFromContentSize( pLayoutRow->m_pFormNode, bContainerWidthAutoSize, fContentCalculatedWidth, - fContainerWidth, bContainerHeightAutoSize, fContentCalculatedHeight, - fContainerHeight); - pLayoutRow->m_sSize = CFX_SizeF(fContainerWidth, fContainerHeight); + bContainerHeightAutoSize, fContentCalculatedHeight, containerSize); } void UpdatePendingItemLayout(CXFA_ItemLayoutProcessor* pProcessor, @@ -460,15 +456,15 @@ FX_FLOAT InsertPendingItems(CXFA_ItemLayoutProcessor* pProcessor, return fTotalHeight; } -XFA_ATTRIBUTEENUM GetLayout(CXFA_Node* pFormNode, bool& bRootForceTb) { - bRootForceTb = false; +XFA_ATTRIBUTEENUM GetLayout(CXFA_Node* pFormNode, bool* bRootForceTb) { + *bRootForceTb = false; XFA_ATTRIBUTEENUM eLayoutMode; if (pFormNode->TryEnum(XFA_ATTRIBUTE_Layout, eLayoutMode, false)) return eLayoutMode; CXFA_Node* pParentNode = pFormNode->GetNodeItem(XFA_NODEITEM_Parent); if (pParentNode && pParentNode->GetElementType() == XFA_Element::Form) { - bRootForceTb = true; + *bRootForceTb = true; return XFA_ATTRIBUTEENUM_Tb; } return XFA_ATTRIBUTEENUM_Position; @@ -522,7 +518,7 @@ bool ExistContainerKeep(CXFA_Node* pCurNode, bool bPreFind) { bool FindBreakNode(CXFA_Node* pContainerNode, CXFA_Node*& pCurActionNode, - XFA_ItemLayoutProcessorStages& nCurStage, + XFA_ItemLayoutProcessorStages* nCurStage, bool bBreakBefore) { bool bFindRs = false; for (CXFA_Node* pBreakNode = pContainerNode; pBreakNode; @@ -535,7 +531,7 @@ bool FindBreakNode(CXFA_Node* pContainerNode, case XFA_Element::BreakBefore: { if (bBreakBefore) { pCurActionNode = pBreakNode; - nCurStage = XFA_ItemLayoutProcessorStages::BreakBefore; + *nCurStage = XFA_ItemLayoutProcessorStages::BreakBefore; bFindRs = true; } break; @@ -543,7 +539,7 @@ bool FindBreakNode(CXFA_Node* pContainerNode, case XFA_Element::BreakAfter: { if (!bBreakBefore) { pCurActionNode = pBreakNode; - nCurStage = XFA_ItemLayoutProcessorStages::BreakAfter; + *nCurStage = XFA_ItemLayoutProcessorStages::BreakAfter; bFindRs = true; } break; @@ -551,9 +547,9 @@ bool FindBreakNode(CXFA_Node* pContainerNode, case XFA_Element::Break: if (pBreakNode->GetEnum(eAttributeType) != XFA_ATTRIBUTEENUM_Auto) { pCurActionNode = pBreakNode; - nCurStage = XFA_ItemLayoutProcessorStages::BreakBefore; + *nCurStage = XFA_ItemLayoutProcessorStages::BreakBefore; if (!bBreakBefore) - nCurStage = XFA_ItemLayoutProcessorStages::BreakAfter; + *nCurStage = XFA_ItemLayoutProcessorStages::BreakAfter; bFindRs = true; } @@ -607,17 +603,17 @@ XFA_ItemLayoutProcessorResult InsertFlowedItem( bool bContainerHeightAutoSize, FX_FLOAT fContainerHeight, XFA_ATTRIBUTEENUM eFlowStrategy, - uint8_t& uCurHAlignState, + uint8_t* uCurHAlignState, CFX_ArrayTemplate (&rgCurLineLayoutItems)[3], bool bUseBreakControl, FX_FLOAT fAvailHeight, FX_FLOAT fRealHeight, - FX_FLOAT& fContentCurRowY, - FX_FLOAT& fContentWidthLimit, - FX_FLOAT& fContentCurRowAvailWidth, - FX_FLOAT& fContentCurRowHeight, - bool& bAddedItemInRow, - bool& bForceEndPage, + FX_FLOAT fContentWidthLimit, + FX_FLOAT* fContentCurRowY, + FX_FLOAT* fContentCurRowAvailWidth, + FX_FLOAT* fContentCurRowHeight, + bool* bAddedItemInRow, + bool* bForceEndPage, CXFA_LayoutContext* pLayoutContext, bool bNewRow) { bool bTakeSpace = @@ -627,23 +623,25 @@ XFA_ItemLayoutProcessorResult InsertFlowedItem( if (bContainerWidthAutoSize) uHAlign = 0; - if ((eFlowStrategy != XFA_ATTRIBUTEENUM_Rl_tb && uHAlign < uCurHAlignState) || - (eFlowStrategy == XFA_ATTRIBUTEENUM_Rl_tb && uHAlign > uCurHAlignState)) { + if ((eFlowStrategy != XFA_ATTRIBUTEENUM_Rl_tb && + uHAlign < *uCurHAlignState) || + (eFlowStrategy == XFA_ATTRIBUTEENUM_Rl_tb && + uHAlign > *uCurHAlignState)) { return XFA_ItemLayoutProcessorResult::RowFullBreak; } - uCurHAlignState = uHAlign; - bool bIsOwnSplite = + *uCurHAlignState = uHAlign; + bool bIsOwnSplit = pProcessor->m_pFormNode->GetIntact() == XFA_ATTRIBUTEENUM_None; bool bUseRealHeight = - bTakeSpace && bContainerHeightAutoSize && bIsOwnSplite && + bTakeSpace && bContainerHeightAutoSize && bIsOwnSplit && pProcessor->m_pFormNode->GetNodeItem(XFA_NODEITEM_Parent)->GetIntact() == XFA_ATTRIBUTEENUM_None; bool bIsTransHeight = bTakeSpace; - if (bIsTransHeight && !bIsOwnSplite) { + if (bIsTransHeight && !bIsOwnSplit) { bool bRootForceTb = false; XFA_ATTRIBUTEENUM eLayoutStrategy = - GetLayout(pProcessor->m_pFormNode, bRootForceTb); + GetLayout(pProcessor->m_pFormNode, &bRootForceTb); if (eLayoutStrategy == XFA_ATTRIBUTEENUM_Lr_tb || eLayoutStrategy == XFA_ATTRIBUTEENUM_Rl_tb) { bIsTransHeight = false; @@ -667,8 +665,8 @@ XFA_ItemLayoutProcessorResult InsertFlowedItem( pProcessor->m_ePreProcessRs == XFA_ItemLayoutProcessorResult::Done) { eRetValue = pProcessor->DoLayout( bTakeSpace ? bUseBreakControl : false, - bUseRealHeight ? fRealHeight - fContentCurRowY : FLT_MAX, - bIsTransHeight ? fRealHeight - fContentCurRowY : FLT_MAX, + bUseRealHeight ? fRealHeight - *fContentCurRowY : FLT_MAX, + bIsTransHeight ? fRealHeight - *fContentCurRowY : FLT_MAX, pLayoutContext); pProcessor->m_ePreProcessRs = eRetValue; } else { @@ -678,16 +676,14 @@ XFA_ItemLayoutProcessorResult InsertFlowedItem( if (pProcessor->HasLayoutItem() == false) return eRetValue; - FX_FLOAT fChildWidth; - FX_FLOAT fChildHeight; - pProcessor->GetCurrentComponentSize(fChildWidth, fChildHeight); + CFX_SizeF childSize = pProcessor->GetCurrentComponentSize(); if (bUseRealHeight && fRealHeight < XFA_LAYOUT_FLOAT_PERCISION) { fRealHeight = FLT_MAX; fAvailHeight = FLT_MAX; } if (bTakeSpace && - (fChildWidth > fContentCurRowAvailWidth + XFA_LAYOUT_FLOAT_PERCISION) && - (fContentWidthLimit - fContentCurRowAvailWidth > + (childSize.x > *fContentCurRowAvailWidth + XFA_LAYOUT_FLOAT_PERCISION) && + (fContentWidthLimit - *fContentCurRowAvailWidth > XFA_LAYOUT_FLOAT_PERCISION)) { return XFA_ItemLayoutProcessorResult::RowFullBreak; } @@ -724,7 +720,7 @@ XFA_ItemLayoutProcessorResult InsertFlowedItem( ? pThis->IsAddNewRowForTrailer(pTrailerLayoutItem) : pProcessor->IsAddNewRowForTrailer(pTrailerLayoutItem); if (bIsAddTrailerHeight) { - fChildHeight += pTrailerLayoutItem->m_sSize.y; + childSize.y += pTrailerLayoutItem->m_sSize.y; bIsAddTrailerHeight = true; } } @@ -732,7 +728,7 @@ XFA_ItemLayoutProcessorResult InsertFlowedItem( } if (!bTakeSpace || - fContentCurRowY + fChildHeight <= + *fContentCurRowY + childSize.y <= fAvailHeight + XFA_LAYOUT_FLOAT_PERCISION || (!bContainerHeightAutoSize && pThis->m_fUsedSize + fAvailHeight + XFA_LAYOUT_FLOAT_PERCISION >= @@ -740,7 +736,7 @@ XFA_ItemLayoutProcessorResult InsertFlowedItem( if (!bTakeSpace || eRetValue == XFA_ItemLayoutProcessorResult::Done) { if (pProcessor->m_bUseInheriated) { if (pTrailerLayoutItem) - AddTrailerBeforeSplit(pProcessor, fChildHeight, pTrailerLayoutItem, + AddTrailerBeforeSplit(pProcessor, childSize.y, pTrailerLayoutItem, false); if (pProcessor->JudgeLeaderOrTrailerForOccur(pOverflowLeaderNode)) AddPendingNode(pProcessor, pOverflowLeaderNode, false); @@ -748,7 +744,7 @@ XFA_ItemLayoutProcessorResult InsertFlowedItem( pProcessor->m_bUseInheriated = false; } else { if (bIsAddTrailerHeight) - fChildHeight -= pTrailerLayoutItem->m_sSize.y; + childSize.y -= pTrailerLayoutItem->m_sSize.y; pProcessor->ProcessUnUseOverFlow(pOverflowLeaderNode, pOverflowTrailerNode, @@ -759,16 +755,15 @@ XFA_ItemLayoutProcessorResult InsertFlowedItem( pProcessor->ExtractLayoutItem(); if (ExistContainerKeep(pProcessor->m_pFormNode, false) && pProcessor->m_pFormNode->GetIntact() == XFA_ATTRIBUTEENUM_None) { - pThis->m_arrayKeepItems.Add(pChildLayoutItem); + pThis->m_arrayKeepItems.push_back(pChildLayoutItem); } else { - pThis->m_arrayKeepItems.RemoveAll(); + pThis->m_arrayKeepItems.clear(); } rgCurLineLayoutItems[uHAlign].Add(pChildLayoutItem); - bAddedItemInRow = true; + *bAddedItemInRow = true; if (bTakeSpace) { - fContentCurRowAvailWidth -= fChildWidth; - if (fContentCurRowHeight < fChildHeight) - fContentCurRowHeight = fChildHeight; + *fContentCurRowAvailWidth -= childSize.x; + *fContentCurRowHeight = std::max(*fContentCurRowHeight, childSize.y); } return XFA_ItemLayoutProcessorResult::Done; } @@ -776,7 +771,7 @@ XFA_ItemLayoutProcessorResult InsertFlowedItem( if (eRetValue == XFA_ItemLayoutProcessorResult::PageFullBreak) { if (pProcessor->m_bUseInheriated) { if (pTrailerLayoutItem) { - AddTrailerBeforeSplit(pProcessor, fChildHeight, pTrailerLayoutItem, + AddTrailerBeforeSplit(pProcessor, childSize.y, pTrailerLayoutItem, false); } if (pProcessor->JudgeLeaderOrTrailerForOccur(pOverflowLeaderNode)) @@ -785,7 +780,7 @@ XFA_ItemLayoutProcessorResult InsertFlowedItem( pProcessor->m_bUseInheriated = false; } else { if (bIsAddTrailerHeight) - fChildHeight -= pTrailerLayoutItem->m_sSize.y; + childSize.y -= pTrailerLayoutItem->m_sSize.y; pProcessor->ProcessUnUseOverFlow(pOverflowLeaderNode, pOverflowTrailerNode, @@ -793,24 +788,23 @@ XFA_ItemLayoutProcessorResult InsertFlowedItem( } } rgCurLineLayoutItems[uHAlign].Add(pProcessor->ExtractLayoutItem()); - bAddedItemInRow = true; - fContentCurRowAvailWidth -= fChildWidth; - if (fContentCurRowHeight < fChildHeight) - fContentCurRowHeight = fChildHeight; - + *bAddedItemInRow = true; + *fContentCurRowAvailWidth -= childSize.x; + *fContentCurRowHeight = std::max(*fContentCurRowHeight, childSize.y); return eRetValue; } XFA_ItemLayoutProcessorResult eResult; - if (pThis->ProcessKeepForSplite( - pThis, pProcessor, eRetValue, rgCurLineLayoutItems[uHAlign], + if (pThis->ProcessKeepForSplit( + pThis, pProcessor, eRetValue, &rgCurLineLayoutItems[uHAlign], fContentCurRowAvailWidth, fContentCurRowHeight, fContentCurRowY, - bAddedItemInRow, bForceEndPage, eResult)) { + bAddedItemInRow, bForceEndPage, &eResult)) { return eResult; } - bForceEndPage = true; - FX_FLOAT fSplitPos = pProcessor->FindSplitPos(fAvailHeight - fContentCurRowY); + *bForceEndPage = true; + FX_FLOAT fSplitPos = + pProcessor->FindSplitPos(fAvailHeight - *fContentCurRowY); if (fSplitPos > XFA_LAYOUT_FLOAT_PERCISION) { XFA_ATTRIBUTEENUM eLayout = pProcessor->m_pFormNode->GetEnum(XFA_ATTRIBUTE_Layout); @@ -820,11 +814,10 @@ XFA_ItemLayoutProcessorResult InsertFlowedItem( pOverflowTrailerNode, pTrailerLayoutItem, pFormNode); rgCurLineLayoutItems[uHAlign].Add(pProcessor->ExtractLayoutItem()); - bAddedItemInRow = true; + *bAddedItemInRow = true; if (bTakeSpace) { - fContentCurRowAvailWidth -= fChildWidth; - if (fContentCurRowHeight < fChildHeight) - fContentCurRowHeight = fChildHeight; + *fContentCurRowAvailWidth -= childSize.x; + *fContentCurRowHeight = std::max(*fContentCurRowHeight, childSize.y); } return XFA_ItemLayoutProcessorResult::PageFullBreak; } @@ -862,21 +855,20 @@ XFA_ItemLayoutProcessorResult InsertFlowedItem( } if (pProcessor->m_pLayoutItem->m_pNextSibling) { - pProcessor->GetCurrentComponentSize(fChildWidth, fChildHeight); + childSize = pProcessor->GetCurrentComponentSize(); rgCurLineLayoutItems[uHAlign].Add(pProcessor->ExtractLayoutItem()); - bAddedItemInRow = true; + *bAddedItemInRow = true; if (bTakeSpace) { - fContentCurRowAvailWidth -= fChildWidth; - if (fContentCurRowHeight < fChildHeight) - fContentCurRowHeight = fChildHeight; + *fContentCurRowAvailWidth -= childSize.x; + *fContentCurRowHeight = std::max(*fContentCurRowHeight, childSize.y); } } return XFA_ItemLayoutProcessorResult::PageFullBreak; } - if (fContentCurRowY <= XFA_LAYOUT_FLOAT_PERCISION) { - pProcessor->GetCurrentComponentSize(fChildWidth, fChildHeight); - if (pProcessor->m_pPageMgr->GetNextAvailContentHeight(fChildHeight)) { + if (*fContentCurRowY <= XFA_LAYOUT_FLOAT_PERCISION) { + childSize = pProcessor->GetCurrentComponentSize(); + if (pProcessor->m_pPageMgr->GetNextAvailContentHeight(childSize.y)) { CXFA_Node* pTempLeaderNode = nullptr; CXFA_Node* pTempTrailerNode = nullptr; if (pThis->m_pPageMgr) { @@ -896,14 +888,13 @@ XFA_ItemLayoutProcessorResult InsertFlowedItem( } rgCurLineLayoutItems[uHAlign].Add(pProcessor->ExtractLayoutItem()); - bAddedItemInRow = true; + *bAddedItemInRow = true; if (bTakeSpace) { - fContentCurRowAvailWidth -= fChildWidth; - if (fContentCurRowHeight < fChildHeight) - fContentCurRowHeight = fChildHeight; + *fContentCurRowAvailWidth -= childSize.x; + *fContentCurRowHeight = std::max(*fContentCurRowHeight, childSize.y); } if (eRetValue == XFA_ItemLayoutProcessorResult::Done) - bForceEndPage = false; + *bForceEndPage = false; return eRetValue; } @@ -943,92 +934,88 @@ XFA_ItemLayoutProcessorResult InsertFlowedItem( bool FindLayoutItemSplitPos(CXFA_ContentLayoutItem* pLayoutItem, FX_FLOAT fCurVerticalOffset, - FX_FLOAT& fProposedSplitPos, - bool& bAppChange, + FX_FLOAT* fProposedSplitPos, + bool* bAppChange, bool bCalculateMargin) { CXFA_Node* pFormNode = pLayoutItem->m_pFormNode; - if (fProposedSplitPos > fCurVerticalOffset + XFA_LAYOUT_FLOAT_PERCISION && - fProposedSplitPos <= fCurVerticalOffset + pLayoutItem->m_sSize.y - + if (*fProposedSplitPos <= fCurVerticalOffset + XFA_LAYOUT_FLOAT_PERCISION || + *fProposedSplitPos > fCurVerticalOffset + pLayoutItem->m_sSize.y - XFA_LAYOUT_FLOAT_PERCISION) { - switch (pFormNode->GetIntact()) { - case XFA_ATTRIBUTEENUM_None: { - bool bAnyChanged = false; - CXFA_Document* pDocument = pFormNode->GetDocument(); - CXFA_FFNotify* pNotify = pDocument->GetNotify(); - FX_FLOAT fCurTopMargin = 0, fCurBottomMargin = 0; - CXFA_Node* pMarginNode = - pFormNode->GetFirstChildByClass(XFA_Element::Margin); - if (pMarginNode && bCalculateMargin) { - fCurTopMargin = pMarginNode->GetMeasure(XFA_ATTRIBUTE_TopInset) - .ToUnit(XFA_UNIT_Pt); - fCurBottomMargin = pMarginNode->GetMeasure(XFA_ATTRIBUTE_BottomInset) - .ToUnit(XFA_UNIT_Pt); - } - bool bChanged = true; - while (bChanged) { - bChanged = false; - { - FX_FLOAT fRelSplitPos = fProposedSplitPos - fCurVerticalOffset; - if (pNotify->FindSplitPos(pFormNode, pLayoutItem->GetIndex(), - fRelSplitPos)) { - bAnyChanged = true; - bChanged = true; - fProposedSplitPos = fCurVerticalOffset + fRelSplitPos; - bAppChange = true; - if (fProposedSplitPos <= - fCurVerticalOffset + XFA_LAYOUT_FLOAT_PERCISION) { - return true; - } + return false; + } + + switch (pFormNode->GetIntact()) { + case XFA_ATTRIBUTEENUM_None: { + bool bAnyChanged = false; + CXFA_Document* pDocument = pFormNode->GetDocument(); + CXFA_FFNotify* pNotify = pDocument->GetNotify(); + FX_FLOAT fCurTopMargin = 0, fCurBottomMargin = 0; + CXFA_Node* pMarginNode = + pFormNode->GetFirstChildByClass(XFA_Element::Margin); + if (pMarginNode && bCalculateMargin) { + fCurTopMargin = + pMarginNode->GetMeasure(XFA_ATTRIBUTE_TopInset).ToUnit(XFA_UNIT_Pt); + fCurBottomMargin = pMarginNode->GetMeasure(XFA_ATTRIBUTE_BottomInset) + .ToUnit(XFA_UNIT_Pt); + } + bool bChanged = true; + while (bChanged) { + bChanged = false; + { + FX_FLOAT fRelSplitPos = *fProposedSplitPos - fCurVerticalOffset; + if (pNotify->FindSplitPos(pFormNode, pLayoutItem->GetIndex(), + fRelSplitPos)) { + bAnyChanged = true; + bChanged = true; + *fProposedSplitPos = fCurVerticalOffset + fRelSplitPos; + *bAppChange = true; + if (*fProposedSplitPos <= + fCurVerticalOffset + XFA_LAYOUT_FLOAT_PERCISION) { + return true; } } - FX_FLOAT fRelSplitPos = fProposedSplitPos - fCurBottomMargin; - for (CXFA_ContentLayoutItem* pChildItem = - (CXFA_ContentLayoutItem*)pLayoutItem->m_pFirstChild; - pChildItem; - pChildItem = - (CXFA_ContentLayoutItem*)pChildItem->m_pNextSibling) { - FX_FLOAT fChildOffset = - fCurVerticalOffset + fCurTopMargin + pChildItem->m_sPos.y; - bool bChange = false; - if (FindLayoutItemSplitPos(pChildItem, fChildOffset, fRelSplitPos, - bChange, bCalculateMargin)) { - if (fRelSplitPos - fChildOffset < XFA_LAYOUT_FLOAT_PERCISION && - bChange) { - fProposedSplitPos = fRelSplitPos - fCurTopMargin; - } else { - fProposedSplitPos = fRelSplitPos + fCurBottomMargin; - } - bAnyChanged = true; - bChanged = true; - if (fProposedSplitPos <= - fCurVerticalOffset + XFA_LAYOUT_FLOAT_PERCISION) { - return true; - } - if (bAnyChanged) { - break; - } + } + FX_FLOAT fRelSplitPos = *fProposedSplitPos - fCurBottomMargin; + for (CXFA_ContentLayoutItem* pChildItem = + (CXFA_ContentLayoutItem*)pLayoutItem->m_pFirstChild; + pChildItem; + pChildItem = (CXFA_ContentLayoutItem*)pChildItem->m_pNextSibling) { + FX_FLOAT fChildOffset = + fCurVerticalOffset + fCurTopMargin + pChildItem->m_sPos.y; + bool bChange = false; + if (FindLayoutItemSplitPos(pChildItem, fChildOffset, &fRelSplitPos, + &bChange, bCalculateMargin)) { + if (fRelSplitPos - fChildOffset < XFA_LAYOUT_FLOAT_PERCISION && + bChange) { + *fProposedSplitPos = fRelSplitPos - fCurTopMargin; + } else { + *fProposedSplitPos = fRelSplitPos + fCurBottomMargin; + } + bAnyChanged = true; + bChanged = true; + if (*fProposedSplitPos <= + fCurVerticalOffset + XFA_LAYOUT_FLOAT_PERCISION) { + return true; } + if (bAnyChanged) + break; } } - return bAnyChanged; - } break; - case XFA_ATTRIBUTEENUM_ContentArea: - case XFA_ATTRIBUTEENUM_PageArea: { - fProposedSplitPos = fCurVerticalOffset; - return true; } - default: - return false; + return bAnyChanged; } + case XFA_ATTRIBUTEENUM_ContentArea: + case XFA_ATTRIBUTEENUM_PageArea: { + *fProposedSplitPos = fCurVerticalOffset; + return true; + } + default: + return false; } - return false; } -void CalculatePositionedContainerPos(CXFA_Node* pNode, - FX_FLOAT fWidth, - FX_FLOAT fHeight, - FX_FLOAT& fAbsoluteX, - FX_FLOAT& fAbsoluteY) { +CFX_PointF CalculatePositionedContainerPos(CXFA_Node* pNode, + const CFX_SizeF& size) { XFA_ATTRIBUTEENUM eAnchorType = pNode->GetEnum(XFA_ATTRIBUTE_AnchorType); int32_t nAnchorType = 0; switch (eAnchorType) { @@ -1067,34 +1054,33 @@ void CalculatePositionedContainerPos(CXFA_Node* pNode, {8, 7, 6, 5, 4, 3, 2, 1, 0}, {2, 5, 8, 1, 4, 7, 0, 3, 6}}; - FX_FLOAT fAnchorX = pNode->GetMeasure(XFA_ATTRIBUTE_X).ToUnit(XFA_UNIT_Pt); - FX_FLOAT fAnchorY = pNode->GetMeasure(XFA_ATTRIBUTE_Y).ToUnit(XFA_UNIT_Pt); + CFX_PointF pos(pNode->GetMeasure(XFA_ATTRIBUTE_X).ToUnit(XFA_UNIT_Pt), + pNode->GetMeasure(XFA_ATTRIBUTE_Y).ToUnit(XFA_UNIT_Pt)); int32_t nRotate = FXSYS_round(pNode->GetMeasure(XFA_ATTRIBUTE_Rotate).GetValue()); nRotate = XFA_MapRotation(nRotate) / 90; int32_t nAbsoluteAnchorType = nNextPos[nRotate][nAnchorType]; - fAbsoluteX = fAnchorX; - fAbsoluteY = fAnchorY; switch (nAbsoluteAnchorType / 3) { case 1: - fAbsoluteY -= fHeight / 2; + pos.y -= size.y / 2; break; case 2: - fAbsoluteY -= fHeight; + pos.y -= size.y; break; default: break; } switch (nAbsoluteAnchorType % 3) { case 1: - fAbsoluteX -= fWidth / 2; + pos.x -= size.x / 2; break; case 2: - fAbsoluteX -= fWidth; + pos.x -= size.x; break; default: break; } + return pos; } } // namespace @@ -1162,8 +1148,8 @@ FX_FLOAT CXFA_ItemLayoutProcessor::FindSplitPos(FX_FLOAT fProposedSplitPos) { bool bCalculateMargin = eLayout != XFA_ATTRIBUTEENUM_Position; while (fProposedSplitPos > XFA_LAYOUT_FLOAT_PERCISION) { bool bAppChange = false; - if (!FindLayoutItemSplitPos(m_pLayoutItem, 0, fProposedSplitPos, bAppChange, - bCalculateMargin)) { + if (!FindLayoutItemSplitPos(m_pLayoutItem, 0, &fProposedSplitPos, + &bAppChange, bCalculateMargin)) { break; } } @@ -1355,7 +1341,7 @@ void CXFA_ItemLayoutProcessor::GotoNextContainerNode( CXFA_Node* pBreakAfterNode = pChildContainer->GetNodeItem(XFA_NODEITEM_FirstChild); if (!m_bKeepBreakFinish && - FindBreakNode(pBreakAfterNode, pCurActionNode, nCurStage, false)) { + FindBreakNode(pBreakAfterNode, pCurActionNode, &nCurStage, false)) { return; } goto CheckNextChildContainer; @@ -1387,7 +1373,7 @@ void CXFA_ItemLayoutProcessor::GotoNextContainerNode( CXFA_Node* pBreakBeforeNode = pCurActionNode->GetNodeItem(XFA_NODEITEM_NextSibling); if (!m_bKeepBreakFinish && - FindBreakNode(pBreakBeforeNode, pCurActionNode, nCurStage, + FindBreakNode(pBreakBeforeNode, pCurActionNode, &nCurStage, true)) { return; } @@ -1411,14 +1397,14 @@ void CXFA_ItemLayoutProcessor::GotoNextContainerNode( CXFA_Node* pBreakAfterNode = pChildContainer->GetNodeItem(XFA_NODEITEM_FirstChild); if (!m_bKeepBreakFinish && - FindBreakNode(pBreakAfterNode, pCurActionNode, nCurStage, + FindBreakNode(pBreakAfterNode, pCurActionNode, &nCurStage, false)) { return; } } else { CXFA_Node* pBreakAfterNode = pCurActionNode->GetNodeItem(XFA_NODEITEM_NextSibling); - if (FindBreakNode(pBreakAfterNode, pCurActionNode, nCurStage, + if (FindBreakNode(pBreakAfterNode, pCurActionNode, &nCurStage, false)) { return; } @@ -1453,7 +1439,7 @@ void CXFA_ItemLayoutProcessor::GotoNextContainerNode( if (!m_bKeepBreakFinish && !bLastKeep && FindBreakNode( pNextChildContainer->GetNodeItem(XFA_NODEITEM_FirstChild), - pCurActionNode, nCurStage, true)) { + pCurActionNode, &nCurStage, true)) { return; } pCurActionNode = pNextChildContainer; @@ -1512,7 +1498,7 @@ bool CXFA_ItemLayoutProcessor::ProcessKeepNodesForCheckNext( m_pKeepTailNode = pNextContainer; if (!m_bKeepBreakFinish && FindBreakNode(pNextContainer->GetNodeItem(XFA_NODEITEM_FirstChild), - pCurActionNode, nCurStage, true)) { + pCurActionNode, &nCurStage, true)) { return true; } @@ -1546,7 +1532,7 @@ bool CXFA_ItemLayoutProcessor::ProcessKeepNodesForBreakBefore( CXFA_Node* pBreakAfterNode = pContainerNode->GetNodeItem(XFA_NODEITEM_FirstChild); - return FindBreakNode(pBreakAfterNode, pCurActionNode, nCurStage, false); + return FindBreakNode(pBreakAfterNode, pCurActionNode, &nCurStage, false); } bool XFA_ItemLayoutProcessor_IsTakingSpace(CXFA_Node* pNode) { @@ -1584,15 +1570,8 @@ void CXFA_ItemLayoutProcessor::DoLayoutPageArea( if (!pProcessor->HasLayoutItem()) continue; - FX_FLOAT fWidth; - FX_FLOAT fHeight; - pProcessor->GetCurrentComponentSize(fWidth, fHeight); - - FX_FLOAT fAbsoluteX = 0; - FX_FLOAT fAbsoluteY = 0; - CalculatePositionedContainerPos(pCurChildNode, fWidth, fHeight, fAbsoluteX, - fAbsoluteY); - pProcessor->SetCurrentComponentPos(fAbsoluteX, fAbsoluteY); + pProcessor->SetCurrentComponentPos(CalculatePositionedContainerPos( + pCurChildNode, pProcessor->GetCurrentComponentSize())); CXFA_LayoutItem* pProcessItem = pProcessor->ExtractLayoutItem(); if (!pBeforeItem) pPageAreaLayoutItem->AddHeadChild(pProcessItem); @@ -1633,13 +1612,10 @@ void CXFA_ItemLayoutProcessor::DoLayoutPositionedContainer( m_pLayoutItem = CreateContentLayoutItem(m_pFormNode); bool bIgnoreXY = (m_pFormNode->GetEnum(XFA_ATTRIBUTE_Layout) != XFA_ATTRIBUTEENUM_Position); - FX_FLOAT fContainerWidth = 0; - FX_FLOAT fContainerHeight = 0; bool bContainerWidthAutoSize = true; bool bContainerHeightAutoSize = true; - CalculateContainerSpecfiedSize(m_pFormNode, fContainerWidth, fContainerHeight, - bContainerWidthAutoSize, - bContainerHeightAutoSize); + CFX_SizeF containerSize = CalculateContainerSpecifiedSize( + m_pFormNode, &bContainerWidthAutoSize, &bContainerHeightAutoSize); FX_FLOAT fContentCalculatedWidth = 0; FX_FLOAT fContentCalculatedHeight = 0; @@ -1684,23 +1660,18 @@ void CXFA_ItemLayoutProcessor::DoLayoutPositionedContainer( if (!pProcessor->HasLayoutItem()) continue; - FX_FLOAT fWidth; - FX_FLOAT fHeight; - pProcessor->GetCurrentComponentSize(fWidth, fHeight); + CFX_SizeF size = pProcessor->GetCurrentComponentSize(); bool bChangeParentSize = false; if (XFA_ItemLayoutProcessor_IsTakingSpace(m_pCurChildNode)) bChangeParentSize = true; - FX_FLOAT fAbsoluteX = 0; - FX_FLOAT fAbsoluteY = 0; - if (!bIgnoreXY) { - CalculatePositionedContainerPos(m_pCurChildNode, fWidth, fHeight, - fAbsoluteX, fAbsoluteY); - } + CFX_PointF absolutePos; + if (!bIgnoreXY) + absolutePos = CalculatePositionedContainerPos(m_pCurChildNode, size); - pProcessor->SetCurrentComponentPos(fAbsoluteX, fAbsoluteY); + pProcessor->SetCurrentComponentPos(absolutePos); if (bContainerWidthAutoSize) { - FX_FLOAT fChildSuppliedWidth = fAbsoluteX + fWidth; + FX_FLOAT fChildSuppliedWidth = absolutePos.x + size.x; if (bChangeParentSize) { fContentCalculatedWidth = std::max(fContentCalculatedWidth, fChildSuppliedWidth); @@ -1713,7 +1684,7 @@ void CXFA_ItemLayoutProcessor::DoLayoutPositionedContainer( } if (bContainerHeightAutoSize) { - FX_FLOAT fChildSuppliedHeight = fAbsoluteY + fHeight; + FX_FLOAT fChildSuppliedHeight = absolutePos.y + size.y; if (bChangeParentSize) { fContentCalculatedHeight = std::max(fContentCalculatedHeight, fChildSuppliedHeight); @@ -1733,11 +1704,10 @@ void CXFA_ItemLayoutProcessor::DoLayoutPositionedContainer( if (fContentCalculatedHeight == 0 && eVersion < XFA_VERSION_207) fContentCalculatedHeight = fHiddenContentCalculatedHeight; - CalculateContainerComponentSizeFromContentSize( + containerSize = CalculateContainerComponentSizeFromContentSize( m_pFormNode, bContainerWidthAutoSize, fContentCalculatedWidth, - fContainerWidth, bContainerHeightAutoSize, fContentCalculatedHeight, - fContainerHeight); - SetCurrentComponentSize(fContainerWidth, fContainerHeight); + bContainerHeightAutoSize, fContentCalculatedHeight, containerSize); + SetCurrentComponentSize(containerSize); } void CXFA_ItemLayoutProcessor::DoLayoutTableContainer(CXFA_Node* pLayoutNode) { @@ -1749,13 +1719,10 @@ void CXFA_ItemLayoutProcessor::DoLayoutTableContainer(CXFA_Node* pLayoutNode) { ASSERT(m_pCurChildNode == XFA_LAYOUT_INVALIDNODE); m_pLayoutItem = CreateContentLayoutItem(m_pFormNode); - FX_FLOAT fContainerWidth = 0; - FX_FLOAT fContainerHeight = 0; bool bContainerWidthAutoSize = true; bool bContainerHeightAutoSize = true; - CalculateContainerSpecfiedSize(m_pFormNode, fContainerWidth, fContainerHeight, - bContainerWidthAutoSize, - bContainerHeightAutoSize); + CFX_SizeF containerSize = CalculateContainerSpecifiedSize( + m_pFormNode, &bContainerWidthAutoSize, &bContainerHeightAutoSize); FX_FLOAT fContentCalculatedWidth = 0; FX_FLOAT fContentCalculatedHeight = 0; CXFA_Node* pMarginNode = @@ -1771,22 +1738,18 @@ void CXFA_ItemLayoutProcessor::DoLayoutTableContainer(CXFA_Node* pLayoutNode) { FX_FLOAT fContentWidthLimit = bContainerWidthAutoSize ? FLT_MAX - : fContainerWidth - fLeftInset - fRightInset; + : containerSize.x - fLeftInset - fRightInset; CFX_WideStringC wsColumnWidths; if (pLayoutNode->TryCData(XFA_ATTRIBUTE_ColumnWidths, wsColumnWidths)) { - std::vector widths; - if (SeparateStringW(wsColumnWidths.c_str(), wsColumnWidths.GetLength(), - L' ', widths) > 0) { - int32_t iCols = pdfium::CollectionSize(widths); - CFX_WideString wsWidth; - for (int32_t i = 0; i < iCols; i++) { - wsWidth = widths[i]; - wsWidth.TrimLeft(L' '); - if (!wsWidth.IsEmpty()) { - CXFA_Measurement measure(wsWidth.AsStringC()); - m_rgSpecifiedColumnWidths.Add(measure.ToUnit(XFA_UNIT_Pt)); - } - } + auto widths = SeparateStringW(wsColumnWidths.c_str(), + wsColumnWidths.GetLength(), L' '); + for (auto& width : widths) { + width.TrimLeft(L' '); + if (width.IsEmpty()) + continue; + + CXFA_Measurement measure(width.AsStringC()); + m_rgSpecifiedColumnWidths.Add(measure.ToUnit(XFA_UNIT_Pt)); } } @@ -1960,11 +1923,10 @@ void CXFA_ItemLayoutProcessor::DoLayoutTableContainer(CXFA_Node* pLayoutNode) { if (bContainerHeightAutoSize) fContentCalculatedHeight = std::max(fContentCalculatedHeight, fCurrentRowY); - CalculateContainerComponentSizeFromContentSize( + containerSize = CalculateContainerComponentSizeFromContentSize( m_pFormNode, bContainerWidthAutoSize, fContentCalculatedWidth, - fContainerWidth, bContainerHeightAutoSize, fContentCalculatedHeight, - fContainerHeight); - SetCurrentComponentSize(fContainerWidth, fContainerHeight); + bContainerHeightAutoSize, fContentCalculatedHeight, containerSize); + SetCurrentComponentSize(containerSize); } bool CXFA_ItemLayoutProcessor::IsAddNewRowForTrailer( @@ -1978,7 +1940,7 @@ bool CXFA_ItemLayoutProcessor::IsAddNewRowForTrailer( } FX_FLOAT CXFA_ItemLayoutProcessor::InsertKeepLayoutItems() { - if (m_arrayKeepItems.GetSize() == 0) + if (m_arrayKeepItems.empty()) return 0; if (!m_pLayoutItem) { @@ -1987,25 +1949,27 @@ FX_FLOAT CXFA_ItemLayoutProcessor::InsertKeepLayoutItems() { } FX_FLOAT fTotalHeight = 0; - for (int32_t iIndex = m_arrayKeepItems.GetSize() - 1; iIndex >= 0; iIndex--) { - AddLeaderAfterSplit(this, m_arrayKeepItems[iIndex]); - fTotalHeight += m_arrayKeepItems[iIndex]->m_sSize.y; + for (auto iter = m_arrayKeepItems.rbegin(); iter != m_arrayKeepItems.rend(); + iter++) { + AddLeaderAfterSplit(this, *iter); + fTotalHeight += (*iter)->m_sSize.y; } - m_arrayKeepItems.RemoveAll(); + m_arrayKeepItems.clear(); + return fTotalHeight; } -bool CXFA_ItemLayoutProcessor::ProcessKeepForSplite( +bool CXFA_ItemLayoutProcessor::ProcessKeepForSplit( CXFA_ItemLayoutProcessor* pParentProcessor, CXFA_ItemLayoutProcessor* pChildProcessor, XFA_ItemLayoutProcessorResult eRetValue, - CFX_ArrayTemplate& rgCurLineLayoutItem, - FX_FLOAT& fContentCurRowAvailWidth, - FX_FLOAT& fContentCurRowHeight, - FX_FLOAT& fContentCurRowY, - bool& bAddedItemInRow, - bool& bForceEndPage, - XFA_ItemLayoutProcessorResult& result) { + CFX_ArrayTemplate* rgCurLineLayoutItem, + FX_FLOAT* fContentCurRowAvailWidth, + FX_FLOAT* fContentCurRowHeight, + FX_FLOAT* fContentCurRowY, + bool* bAddedItemInRow, + bool* bForceEndPage, + XFA_ItemLayoutProcessorResult* result) { if (!pParentProcessor || !pChildProcessor) return false; @@ -2017,39 +1981,36 @@ bool CXFA_ItemLayoutProcessor::ProcessKeepForSplite( if (!ExistContainerKeep(pParentProcessor->m_pCurChildNode, true)) return false; - FX_FLOAT fChildWidth; - FX_FLOAT fChildHeight; - pChildProcessor->GetCurrentComponentSize(fChildWidth, fChildHeight); - CFX_ArrayTemplate keepLayoutItems; + CFX_SizeF childSize = pChildProcessor->GetCurrentComponentSize(); + std::vector keepLayoutItems; if (pParentProcessor->JudgePutNextPage(pParentProcessor->m_pLayoutItem, - fChildHeight, keepLayoutItems)) { - m_arrayKeepItems.RemoveAll(); - for (int32_t iIndex = 0; iIndex < keepLayoutItems.GetSize(); iIndex++) { - CXFA_ContentLayoutItem* pItem = keepLayoutItems.GetAt(iIndex); - pParentProcessor->m_pLayoutItem->RemoveChild(pItem); - fContentCurRowY -= pItem->m_sSize.y; - m_arrayKeepItems.Add(pItem); - } - bAddedItemInRow = true; - bForceEndPage = true; - result = XFA_ItemLayoutProcessorResult::PageFullBreak; + childSize.y, &keepLayoutItems)) { + m_arrayKeepItems.clear(); + + for (auto item : keepLayoutItems) { + pParentProcessor->m_pLayoutItem->RemoveChild(item); + *fContentCurRowY -= item->m_sSize.y; + m_arrayKeepItems.push_back(item); + } + *bAddedItemInRow = true; + *bForceEndPage = true; + *result = XFA_ItemLayoutProcessorResult::PageFullBreak; return true; } - rgCurLineLayoutItem.Add(pChildProcessor->ExtractLayoutItem()); - bAddedItemInRow = true; - fContentCurRowAvailWidth -= fChildWidth; - if (fContentCurRowHeight < fChildHeight) - fContentCurRowHeight = fChildHeight; + rgCurLineLayoutItem->Add(pChildProcessor->ExtractLayoutItem()); + *bAddedItemInRow = true; + *fContentCurRowAvailWidth -= childSize.x; + *fContentCurRowHeight = std::max(*fContentCurRowHeight, childSize.y); + *result = eRetValue; - result = eRetValue; return true; } bool CXFA_ItemLayoutProcessor::JudgePutNextPage( CXFA_ContentLayoutItem* pParentLayoutItem, FX_FLOAT fChildHeight, - CFX_ArrayTemplate& pKeepItems) { + std::vector* pKeepItems) { if (!pParentLayoutItem) return false; @@ -2060,10 +2021,10 @@ bool CXFA_ItemLayoutProcessor::JudgePutNextPage( pChildLayoutItem = (CXFA_ContentLayoutItem*)pChildLayoutItem->m_pNextSibling) { if (ExistContainerKeep(pChildLayoutItem->m_pFormNode, false)) { - pKeepItems.Add(pChildLayoutItem); + pKeepItems->push_back(pChildLayoutItem); fItemsHeight += pChildLayoutItem->m_sSize.y; } else { - pKeepItems.RemoveAll(); + pKeepItems->clear(); fItemsHeight = 0; } } @@ -2120,8 +2081,6 @@ XFA_ItemLayoutProcessorResult CXFA_ItemLayoutProcessor::DoLayoutFlowedContainer( CXFA_LayoutContext* pContext, bool bRootForceTb) { m_bHasAvailHeight = true; - FX_FLOAT fContainerWidth = 0; - FX_FLOAT fContainerHeight = 0; bool bBreakDone = false; bool bContainerWidthAutoSize = true; bool bContainerHeightAutoSize = true; @@ -2132,27 +2091,26 @@ XFA_ItemLayoutProcessorResult CXFA_ItemLayoutProcessor::DoLayoutFlowedContainer( XFA_ItemLayoutProcessorResult::Done; } - CalculateContainerSpecfiedSize(m_pFormNode, fContainerWidth, fContainerHeight, - bContainerWidthAutoSize, - bContainerHeightAutoSize); + CFX_SizeF containerSize = CalculateContainerSpecifiedSize( + m_pFormNode, &bContainerWidthAutoSize, &bContainerHeightAutoSize); if (pContext && pContext->m_bCurColumnWidthAvaiable) { bContainerWidthAutoSize = false; - fContainerWidth = pContext->m_fCurColumnWidth; + containerSize.x = pContext->m_fCurColumnWidth; } if (!bContainerHeightAutoSize) - fContainerHeight -= m_fUsedSize; + containerSize.y -= m_fUsedSize; if (!bContainerHeightAutoSize) { CXFA_Node* pParentNode = m_pFormNode->GetNodeItem(XFA_NODEITEM_Parent); bool bFocrTb = false; if (pParentNode && - GetLayout(pParentNode, bFocrTb) == XFA_ATTRIBUTEENUM_Row) { + GetLayout(pParentNode, &bFocrTb) == XFA_ATTRIBUTEENUM_Row) { CXFA_Node* pChildContainer = m_pFormNode->GetNodeItem( XFA_NODEITEM_FirstChild, XFA_ObjectType::ContainerNode); if (pChildContainer && pChildContainer->GetNodeItem(XFA_NODEITEM_NextSibling, XFA_ObjectType::ContainerNode)) { - fContainerHeight = 0; + containerSize.y = 0; bContainerHeightAutoSize = true; } } @@ -2173,7 +2131,7 @@ XFA_ItemLayoutProcessorResult CXFA_ItemLayoutProcessor::DoLayoutFlowedContainer( } FX_FLOAT fContentWidthLimit = bContainerWidthAutoSize ? FLT_MAX - : fContainerWidth - fLeftInset - fRightInset; + : containerSize.x - fLeftInset - fRightInset; FX_FLOAT fContentCalculatedWidth = 0; FX_FLOAT fContentCalculatedHeight = 0; FX_FLOAT fAvailHeight = fHeightLimit - fTopInset - fBottomInset; @@ -2302,12 +2260,11 @@ XFA_ItemLayoutProcessorResult CXFA_ItemLayoutProcessor::DoLayoutFlowedContainer( case XFA_ItemLayoutProcessorStages::None: break; case XFA_ItemLayoutProcessorStages::BreakBefore: { - for (int32_t iIndex = 0; iIndex < m_arrayKeepItems.GetSize(); - iIndex++) { - CXFA_ContentLayoutItem* pItem = m_arrayKeepItems.GetAt(iIndex); - m_pLayoutItem->RemoveChild(pItem); - fContentCalculatedHeight -= pItem->m_sSize.y; + for (auto item : m_arrayKeepItems) { + m_pLayoutItem->RemoveChild(item); + fContentCalculatedHeight -= item->m_sSize.y; } + CXFA_Node* pLeaderNode = nullptr; CXFA_Node* pTrailerNode = nullptr; bool bCreatePage = false; @@ -2334,11 +2291,11 @@ XFA_ItemLayoutProcessorResult CXFA_ItemLayoutProcessor::DoLayoutFlowedContainer( nullptr); InsertFlowedItem( this, pTempProcessor.get(), bContainerWidthAutoSize, - bContainerHeightAutoSize, fContainerHeight, eFlowStrategy, - uCurHAlignState, rgCurLineLayoutItems, false, FLT_MAX, - FLT_MAX, fContentCurRowY, fContentWidthLimit, - fContentCurRowAvailWidth, fContentCurRowHeight, - bAddedItemInRow, bForceEndPage, pContext, false); + bContainerHeightAutoSize, containerSize.y, eFlowStrategy, + &uCurHAlignState, rgCurLineLayoutItems, false, FLT_MAX, + FLT_MAX, fContentWidthLimit, &fContentCurRowY, + &fContentCurRowAvailWidth, &fContentCurRowHeight, + &bAddedItemInRow, &bForceEndPage, pContext, false); } } GotoNextContainerNode(m_pCurChildNode, m_nCurChildNodeStage, @@ -2364,18 +2321,18 @@ XFA_ItemLayoutProcessorResult CXFA_ItemLayoutProcessor::DoLayoutFlowedContainer( pTrailerNode, nullptr); InsertFlowedItem(this, pTempProcessor.get(), bContainerWidthAutoSize, bContainerHeightAutoSize, - fContainerHeight, eFlowStrategy, uCurHAlignState, + containerSize.y, eFlowStrategy, &uCurHAlignState, rgCurLineLayoutItems, false, FLT_MAX, FLT_MAX, - fContentCurRowY, fContentWidthLimit, - fContentCurRowAvailWidth, fContentCurRowHeight, - bAddedItemInRow, bForceEndPage, pContext, false); + fContentWidthLimit, &fContentCurRowY, + &fContentCurRowAvailWidth, &fContentCurRowHeight, + &bAddedItemInRow, &bForceEndPage, pContext, false); } if (!bCreatePage) { if (JudgeLeaderOrTrailerForOccur(pLeaderNode)) { CalculateRowChildPosition( rgCurLineLayoutItems, eFlowStrategy, bContainerHeightAutoSize, - bContainerWidthAutoSize, fContentCalculatedWidth, - fContentCalculatedHeight, fContentCurRowY, + bContainerWidthAutoSize, &fContentCalculatedWidth, + &fContentCalculatedHeight, &fContentCurRowY, fContentCurRowHeight, fContentWidthLimit, false); rgCurLineLayoutItems->RemoveAll(); auto pTempProcessor = @@ -2383,11 +2340,11 @@ XFA_ItemLayoutProcessorResult CXFA_ItemLayoutProcessor::DoLayoutFlowedContainer( nullptr); InsertFlowedItem( this, pTempProcessor.get(), bContainerWidthAutoSize, - bContainerHeightAutoSize, fContainerHeight, eFlowStrategy, - uCurHAlignState, rgCurLineLayoutItems, false, FLT_MAX, - FLT_MAX, fContentCurRowY, fContentWidthLimit, - fContentCurRowAvailWidth, fContentCurRowHeight, - bAddedItemInRow, bForceEndPage, pContext, false); + bContainerHeightAutoSize, containerSize.y, eFlowStrategy, + &uCurHAlignState, rgCurLineLayoutItems, false, FLT_MAX, + FLT_MAX, fContentWidthLimit, &fContentCurRowY, + &fContentCurRowAvailWidth, &fContentCurRowHeight, + &bAddedItemInRow, &bForceEndPage, pContext, false); } } else { if (JudgeLeaderOrTrailerForOccur(pLeaderNode)) @@ -2419,11 +2376,11 @@ XFA_ItemLayoutProcessorResult CXFA_ItemLayoutProcessor::DoLayoutFlowedContainer( if (pProcessor) { if (InsertFlowedItem( this, pProcessor.get(), bContainerWidthAutoSize, - bContainerHeightAutoSize, fContainerHeight, eFlowStrategy, - uCurHAlignState, rgCurLineLayoutItems, bUseBreakControl, - fAvailHeight, fRealHeight, fContentCurRowY, - fContentWidthLimit, fContentCurRowAvailWidth, - fContentCurRowHeight, bAddedItemInRow, bForceEndPage, + bContainerHeightAutoSize, containerSize.y, eFlowStrategy, + &uCurHAlignState, rgCurLineLayoutItems, bUseBreakControl, + fAvailHeight, fRealHeight, fContentWidthLimit, + &fContentCurRowY, &fContentCurRowAvailWidth, + &fContentCurRowHeight, &bAddedItemInRow, &bForceEndPage, pContext, false) != XFA_ItemLayoutProcessorResult::Done) { goto SuspendAndCreateNewRow; } else { @@ -2446,11 +2403,11 @@ XFA_ItemLayoutProcessorResult CXFA_ItemLayoutProcessor::DoLayoutFlowedContainer( if (pProcessor) { if (InsertFlowedItem( this, pProcessor.get(), bContainerWidthAutoSize, - bContainerHeightAutoSize, fContainerHeight, eFlowStrategy, - uCurHAlignState, rgCurLineLayoutItems, bUseBreakControl, - fAvailHeight, fRealHeight, fContentCurRowY, - fContentWidthLimit, fContentCurRowAvailWidth, - fContentCurRowHeight, bAddedItemInRow, bForceEndPage, + bContainerHeightAutoSize, containerSize.y, eFlowStrategy, + &uCurHAlignState, rgCurLineLayoutItems, bUseBreakControl, + fAvailHeight, fRealHeight, fContentWidthLimit, + &fContentCurRowY, &fContentCurRowAvailWidth, + &fContentCurRowHeight, &bAddedItemInRow, &bForceEndPage, pContext, false) != XFA_ItemLayoutProcessorResult::Done) { goto SuspendAndCreateNewRow; } else { @@ -2484,11 +2441,11 @@ XFA_ItemLayoutProcessorResult CXFA_ItemLayoutProcessor::DoLayoutFlowedContainer( InsertPendingItems(pProcessor.get(), m_pCurChildNode); XFA_ItemLayoutProcessorResult rs = InsertFlowedItem( this, pProcessor.get(), bContainerWidthAutoSize, - bContainerHeightAutoSize, fContainerHeight, eFlowStrategy, - uCurHAlignState, rgCurLineLayoutItems, bUseBreakControl, - fAvailHeight, fRealHeight, fContentCurRowY, fContentWidthLimit, - fContentCurRowAvailWidth, fContentCurRowHeight, bAddedItemInRow, - bForceEndPage, pContext, bNewRow); + bContainerHeightAutoSize, containerSize.y, eFlowStrategy, + &uCurHAlignState, rgCurLineLayoutItems, bUseBreakControl, + fAvailHeight, fRealHeight, fContentWidthLimit, &fContentCurRowY, + &fContentCurRowAvailWidth, &fContentCurRowHeight, + &bAddedItemInRow, &bForceEndPage, pContext, bNewRow); switch (rs) { case XFA_ItemLayoutProcessorResult::ManualBreak: bIsManualBreak = true; @@ -2521,11 +2478,11 @@ XFA_ItemLayoutProcessorResult CXFA_ItemLayoutProcessor::DoLayoutFlowedContainer( break; } - CalculateRowChildPosition(rgCurLineLayoutItems, eFlowStrategy, - bContainerHeightAutoSize, bContainerWidthAutoSize, - fContentCalculatedWidth, fContentCalculatedHeight, - fContentCurRowY, fContentCurRowHeight, - fContentWidthLimit, bRootForceTb); + CalculateRowChildPosition( + rgCurLineLayoutItems, eFlowStrategy, bContainerHeightAutoSize, + bContainerWidthAutoSize, &fContentCalculatedWidth, + &fContentCalculatedHeight, &fContentCurRowY, fContentCurRowHeight, + fContentWidthLimit, bRootForceTb); m_fWidthLimite = fContentCurRowAvailWidth; if (bForceEndPage) break; @@ -2537,19 +2494,17 @@ XFA_ItemLayoutProcessorResult CXFA_ItemLayoutProcessor::DoLayoutFlowedContainer( if (bBreakDone) bRetValue = false; - CalculateContainerComponentSizeFromContentSize( + containerSize = CalculateContainerComponentSizeFromContentSize( m_pFormNode, bContainerWidthAutoSize, fContentCalculatedWidth, - fContainerWidth, bContainerHeightAutoSize, fContentCalculatedHeight, - fContainerHeight); + bContainerHeightAutoSize, fContentCalculatedHeight, containerSize); - if (fContainerHeight >= XFA_LAYOUT_FLOAT_PERCISION || m_pLayoutItem || + if (containerSize.y >= XFA_LAYOUT_FLOAT_PERCISION || m_pLayoutItem || bRetValue) { if (!m_pLayoutItem) m_pLayoutItem = CreateContentLayoutItem(m_pFormNode); - if (fContainerHeight < 0) - fContainerHeight = 0; + containerSize.y = std::max(containerSize.y, 0.f); - SetCurrentComponentSize(fContainerWidth, fContainerHeight); + SetCurrentComponentSize(containerSize); if (bForceEndPage) m_fUsedSize = 0; else @@ -2567,9 +2522,9 @@ bool CXFA_ItemLayoutProcessor::CalculateRowChildPosition( XFA_ATTRIBUTEENUM eFlowStrategy, bool bContainerHeightAutoSize, bool bContainerWidthAutoSize, - FX_FLOAT& fContentCalculatedWidth, - FX_FLOAT& fContentCalculatedHeight, - FX_FLOAT& fContentCurRowY, + FX_FLOAT* fContentCalculatedWidth, + FX_FLOAT* fContentCalculatedHeight, + FX_FLOAT* fContentCurRowY, FX_FLOAT fContentCurRowHeight, FX_FLOAT fContentWidthLimit, bool bRootForceTb) { @@ -2589,9 +2544,8 @@ bool CXFA_ItemLayoutProcessor::CalculateRowChildPosition( if (!nTotalLength) { if (bContainerHeightAutoSize) { - FX_FLOAT fNewHeight = fContentCurRowY; - if (fContentCalculatedHeight > fNewHeight) - fContentCalculatedHeight = fNewHeight; + *fContentCalculatedHeight = + std::min(*fContentCalculatedHeight, *fContentCurRowY); } return false; } @@ -2604,15 +2558,12 @@ bool CXFA_ItemLayoutProcessor::CalculateRowChildPosition( fCurPos = 0; for (int32_t c = nGroupLengths[0], j = 0; j < c; j++) { if (bRootForceTb) { - FX_FLOAT fAbsoluteX, fAbsoluteY; - CalculatePositionedContainerPos(rgCurLineLayoutItems[0][j]->m_pFormNode, - rgCurLineLayoutItems[0][j]->m_sSize.x, - rgCurLineLayoutItems[0][j]->m_sSize.y, - fAbsoluteX, fAbsoluteY); - rgCurLineLayoutItems[0][j]->m_sPos = CFX_PointF(fAbsoluteX, fAbsoluteY); + rgCurLineLayoutItems[0][j]->m_sPos = CalculatePositionedContainerPos( + rgCurLineLayoutItems[0][j]->m_pFormNode, + rgCurLineLayoutItems[0][j]->m_sSize); } else { rgCurLineLayoutItems[0][j]->m_sPos = - CFX_PointF(fCurPos, fContentCurRowY); + CFX_PointF(fCurPos, *fContentCurRowY); if (XFA_ItemLayoutProcessor_IsTakingSpace( rgCurLineLayoutItems[0][j]->m_pFormNode)) { fCurPos += rgCurLineLayoutItems[0][j]->m_sSize.x; @@ -2626,15 +2577,12 @@ bool CXFA_ItemLayoutProcessor::CalculateRowChildPosition( 2; for (int32_t c = nGroupLengths[1], j = 0; j < c; j++) { if (bRootForceTb) { - FX_FLOAT fAbsoluteX, fAbsoluteY; - CalculatePositionedContainerPos(rgCurLineLayoutItems[1][j]->m_pFormNode, - rgCurLineLayoutItems[1][j]->m_sSize.x, - rgCurLineLayoutItems[1][j]->m_sSize.y, - fAbsoluteX, fAbsoluteY); - rgCurLineLayoutItems[1][j]->m_sPos = CFX_PointF(fAbsoluteX, fAbsoluteY); + rgCurLineLayoutItems[1][j]->m_sPos = CalculatePositionedContainerPos( + rgCurLineLayoutItems[1][j]->m_pFormNode, + rgCurLineLayoutItems[1][j]->m_sSize); } else { rgCurLineLayoutItems[1][j]->m_sPos = - CFX_PointF(fCurPos, fContentCurRowY); + CFX_PointF(fCurPos, *fContentCurRowY); if (XFA_ItemLayoutProcessor_IsTakingSpace( rgCurLineLayoutItems[1][j]->m_pFormNode)) { fCurPos += rgCurLineLayoutItems[1][j]->m_sSize.x; @@ -2646,15 +2594,12 @@ bool CXFA_ItemLayoutProcessor::CalculateRowChildPosition( fCurPos = fContentWidthLimit - fGroupWidths[2]; for (int32_t c = nGroupLengths[2], j = 0; j < c; j++) { if (bRootForceTb) { - FX_FLOAT fAbsoluteX, fAbsoluteY; - CalculatePositionedContainerPos(rgCurLineLayoutItems[2][j]->m_pFormNode, - rgCurLineLayoutItems[2][j]->m_sSize.x, - rgCurLineLayoutItems[2][j]->m_sSize.y, - fAbsoluteX, fAbsoluteY); - rgCurLineLayoutItems[2][j]->m_sPos = CFX_PointF(fAbsoluteX, fAbsoluteY); + rgCurLineLayoutItems[2][j]->m_sPos = CalculatePositionedContainerPos( + rgCurLineLayoutItems[2][j]->m_pFormNode, + rgCurLineLayoutItems[2][j]->m_sSize); } else { rgCurLineLayoutItems[2][j]->m_sPos = - CFX_PointF(fCurPos, fContentCurRowY); + CFX_PointF(fCurPos, *fContentCurRowY); if (XFA_ItemLayoutProcessor_IsTakingSpace( rgCurLineLayoutItems[2][j]->m_pFormNode)) { fCurPos += rgCurLineLayoutItems[2][j]->m_sSize.x; @@ -2671,7 +2616,8 @@ bool CXFA_ItemLayoutProcessor::CalculateRowChildPosition( rgCurLineLayoutItems[0][j]->m_pFormNode)) { fCurPos -= rgCurLineLayoutItems[0][j]->m_sSize.x; } - rgCurLineLayoutItems[0][j]->m_sPos = CFX_PointF(fCurPos, fContentCurRowY); + rgCurLineLayoutItems[0][j]->m_sPos = + CFX_PointF(fCurPos, *fContentCurRowY); m_pLayoutItem->AddChild(rgCurLineLayoutItems[0][j]); m_fLastRowWidth = fCurPos; } @@ -2683,7 +2629,8 @@ bool CXFA_ItemLayoutProcessor::CalculateRowChildPosition( rgCurLineLayoutItems[1][j]->m_pFormNode)) { fCurPos -= rgCurLineLayoutItems[1][j]->m_sSize.x; } - rgCurLineLayoutItems[1][j]->m_sPos = CFX_PointF(fCurPos, fContentCurRowY); + rgCurLineLayoutItems[1][j]->m_sPos = + CFX_PointF(fCurPos, *fContentCurRowY); m_pLayoutItem->AddChild(rgCurLineLayoutItems[1][j]); m_fLastRowWidth = fCurPos; } @@ -2693,25 +2640,26 @@ bool CXFA_ItemLayoutProcessor::CalculateRowChildPosition( rgCurLineLayoutItems[2][j]->m_pFormNode)) { fCurPos -= rgCurLineLayoutItems[2][j]->m_sSize.x; } - rgCurLineLayoutItems[2][j]->m_sPos = CFX_PointF(fCurPos, fContentCurRowY); + rgCurLineLayoutItems[2][j]->m_sPos = + CFX_PointF(fCurPos, *fContentCurRowY); m_pLayoutItem->AddChild(rgCurLineLayoutItems[2][j]); m_fLastRowWidth = fCurPos; } } - m_fLastRowY = fContentCurRowY; - fContentCurRowY += fContentCurRowHeight; + m_fLastRowY = *fContentCurRowY; + *fContentCurRowY += fContentCurRowHeight; if (bContainerWidthAutoSize) { FX_FLOAT fChildSuppliedWidth = fGroupWidths[0]; if (fContentWidthLimit < FLT_MAX && fContentWidthLimit > fChildSuppliedWidth) { fChildSuppliedWidth = fContentWidthLimit; } - fContentCalculatedWidth = - std::max(fContentCalculatedWidth, fChildSuppliedWidth); + *fContentCalculatedWidth = + std::max(*fContentCalculatedWidth, fChildSuppliedWidth); } if (bContainerHeightAutoSize) { - fContentCalculatedHeight = - std::max(fContentCalculatedHeight, fContentCurRowY); + *fContentCalculatedHeight = + std::max(*fContentCalculatedHeight, *fContentCurRowY); } return true; } @@ -2740,19 +2688,16 @@ void CXFA_ItemLayoutProcessor::DoLayoutField() { CXFA_Document* pDocument = m_pFormNode->GetDocument(); CXFA_FFNotify* pNotify = pDocument->GetNotify(); - FX_FLOAT fHeight = -1; - FX_FLOAT fWidth = -1; - pNotify->StartFieldDrawLayout(m_pFormNode, fWidth, fHeight); + CFX_SizeF size(-1, -1); + pNotify->StartFieldDrawLayout(m_pFormNode, size.x, size.y); int32_t nRotate = FXSYS_round(m_pFormNode->GetMeasure(XFA_ATTRIBUTE_Rotate).GetValue()); nRotate = XFA_MapRotation(nRotate); - if (nRotate == 90 || nRotate == 270) { - FX_FLOAT fTmp = fWidth; - fWidth = fHeight; - fHeight = fTmp; - } - SetCurrentComponentSize(fWidth, fHeight); + if (nRotate == 90 || nRotate == 270) + std::swap(size.x, size.y); + + SetCurrentComponentSize(size); } XFA_ItemLayoutProcessorResult CXFA_ItemLayoutProcessor::DoLayout( @@ -2767,7 +2712,7 @@ XFA_ItemLayoutProcessorResult CXFA_ItemLayoutProcessor::DoLayout( case XFA_Element::SubformSet: { bool bRootForceTb = false; CXFA_Node* pLayoutNode = GetSubformSetParent(m_pFormNode); - XFA_ATTRIBUTEENUM eLayoutStrategy = GetLayout(pLayoutNode, bRootForceTb); + XFA_ATTRIBUTEENUM eLayoutStrategy = GetLayout(pLayoutNode, &bRootForceTb); switch (eLayoutStrategy) { case XFA_ATTRIBUTEENUM_Tb: case XFA_ATTRIBUTEENUM_Lr_tb: @@ -2800,21 +2745,17 @@ XFA_ItemLayoutProcessorResult CXFA_ItemLayoutProcessor::DoLayout( } } -void CXFA_ItemLayoutProcessor::GetCurrentComponentSize(FX_FLOAT& fWidth, - FX_FLOAT& fHeight) { +CFX_SizeF CXFA_ItemLayoutProcessor::GetCurrentComponentSize() { ASSERT(m_pLayoutItem); - fWidth = m_pLayoutItem->m_sSize.x; - fHeight = m_pLayoutItem->m_sSize.y; + return CFX_SizeF(m_pLayoutItem->m_sSize.x, m_pLayoutItem->m_sSize.y); } -void CXFA_ItemLayoutProcessor::SetCurrentComponentPos(FX_FLOAT fAbsoluteX, - FX_FLOAT fAbsoluteY) { - m_pLayoutItem->m_sPos = CFX_PointF(fAbsoluteX, fAbsoluteY); +void CXFA_ItemLayoutProcessor::SetCurrentComponentPos(const CFX_PointF& pos) { + m_pLayoutItem->m_sPos = pos; } -void CXFA_ItemLayoutProcessor::SetCurrentComponentSize(FX_FLOAT fWidth, - FX_FLOAT fHeight) { - m_pLayoutItem->m_sSize = CFX_SizeF(fWidth, fHeight); +void CXFA_ItemLayoutProcessor::SetCurrentComponentSize(const CFX_SizeF& size) { + m_pLayoutItem->m_sSize = size; } bool CXFA_ItemLayoutProcessor::JudgeLeaderOrTrailerForOccur( diff --git a/xfa/fxfa/parser/xfa_layout_itemlayout.h b/xfa/fxfa/parser/xfa_layout_itemlayout.h index b7b35122df..d411bf0e9f 100644 --- a/xfa/fxfa/parser/xfa_layout_itemlayout.h +++ b/xfa/fxfa/parser/xfa_layout_itemlayout.h @@ -11,8 +11,11 @@ #include #include +#include +#include #include "core/fxcrt/fx_basic.h" +#include "core/fxcrt/fx_coordinates.h" #include "xfa/fxfa/fxfa_basic.h" #define XFA_LAYOUT_INVALIDNODE ((CXFA_Node*)(intptr_t)-1) @@ -77,26 +80,25 @@ class CXFA_ItemLayoutProcessor { CXFA_LayoutContext* pContext); void DoLayoutPageArea(CXFA_ContainerLayoutItem* pPageAreaLayoutItem); - void GetCurrentComponentSize(FX_FLOAT& fWidth, FX_FLOAT& fHeight); - + CFX_SizeF GetCurrentComponentSize(); CXFA_Node* GetFormNode() { return m_pFormNode; } - bool HasLayoutItem() { return !!m_pLayoutItem; } + bool HasLayoutItem() const { return !!m_pLayoutItem; } CXFA_ContentLayoutItem* ExtractLayoutItem(); void SplitLayoutItem(FX_FLOAT fSplitPos); FX_FLOAT FindSplitPos(FX_FLOAT fProposedSplitPos); - bool ProcessKeepForSplite( + bool ProcessKeepForSplit( CXFA_ItemLayoutProcessor* pParentProcessor, CXFA_ItemLayoutProcessor* pChildProcessor, XFA_ItemLayoutProcessorResult eRetValue, - CFX_ArrayTemplate& rgCurLineLayoutItem, - FX_FLOAT& fContentCurRowAvailWidth, - FX_FLOAT& fContentCurRowHeight, - FX_FLOAT& fContentCurRowY, - bool& bAddedItemInRow, - bool& bForceEndPage, - XFA_ItemLayoutProcessorResult& result); + CFX_ArrayTemplate* rgCurLineLayoutItem, + FX_FLOAT* fContentCurRowAvailWidth, + FX_FLOAT* fContentCurRowHeight, + FX_FLOAT* fContentCurRowY, + bool* bAddedItemInRow, + bool* bForceEndPage, + XFA_ItemLayoutProcessorResult* result); void ProcessUnUseOverFlow(CXFA_Node* pLeaderNode, CXFA_Node* pTrailerNode, CXFA_ContentLayoutItem* pTrailerItem, @@ -114,15 +116,15 @@ class CXFA_ItemLayoutProcessor { std::list m_PendingNodes; bool m_bBreakPending; CFX_ArrayTemplate m_rgSpecifiedColumnWidths; - CFX_ArrayTemplate m_arrayKeepItems; + std::vector m_arrayKeepItems; FX_FLOAT m_fLastRowWidth; FX_FLOAT m_fLastRowY; bool m_bUseInheriated; XFA_ItemLayoutProcessorResult m_ePreProcessRs; private: - void SetCurrentComponentPos(FX_FLOAT fAbsoluteX, FX_FLOAT fAbsoluteY); - void SetCurrentComponentSize(FX_FLOAT fWidth, FX_FLOAT fHeight); + void SetCurrentComponentPos(const CFX_PointF& pos); + void SetCurrentComponentSize(const CFX_SizeF& size); void SplitLayoutItem(CXFA_ContentLayoutItem* pLayoutItem, CXFA_ContentLayoutItem* pSecondParent, @@ -133,16 +135,16 @@ class CXFA_ItemLayoutProcessor { XFA_ATTRIBUTEENUM eFlowStrategy, bool bContainerHeightAutoSize, bool bContainerWidthAutoSize, - FX_FLOAT& fContentCalculatedWidth, - FX_FLOAT& fContentCalculatedHeight, - FX_FLOAT& fContentCurRowY, + FX_FLOAT* fContentCalculatedWidth, + FX_FLOAT* fContentCalculatedHeight, + FX_FLOAT* fContentCurRowY, FX_FLOAT fContentCurRowHeight, FX_FLOAT fContentWidthLimit, bool bRootForceTb); void ProcessUnUseBinds(CXFA_Node* pFormNode); bool JudgePutNextPage(CXFA_ContentLayoutItem* pParentLayoutItem, FX_FLOAT fChildHeight, - CFX_ArrayTemplate& pKeepItems); + std::vector* pKeepItems); void DoLayoutPositionedContainer(CXFA_LayoutContext* pContext); void DoLayoutTableContainer(CXFA_Node* pLayoutNode); diff --git a/xfa/fxfa/xfa_ffwidget.h b/xfa/fxfa/xfa_ffwidget.h index e370de22aa..8f16dc2521 100644 --- a/xfa/fxfa/xfa_ffwidget.h +++ b/xfa/fxfa/xfa_ffwidget.h @@ -105,7 +105,7 @@ class CXFA_FFWidget : public CXFA_ContentLayoutItem { CXFA_FFPageView* GetPageView() const { return m_pPageView; } void SetPageView(CXFA_FFPageView* pPageView) { m_pPageView = pPageView; } void GetWidgetRect(CFX_RectF& rtWidget); - CFX_RectF ReCacheWidgetRect(); + CFX_RectF RecacheWidgetRect(); uint32_t GetStatus(); void ModifyStatus(uint32_t dwAdded, uint32_t dwRemoved); -- cgit v1.2.3