editeng/inc/editdoc.hxx | 24 ++++++++++++ editeng/source/editeng/impedit3.cxx | 69 ++++++++++++++++++------------------ 2 files changed, 59 insertions(+), 34 deletions(-)
New commits: commit 190cd40e01bd36e99b265ef5da36a382199f18b9 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Tue Oct 18 21:14:41 2022 +0200 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Mon Oct 31 13:31:12 2022 +0100 editeng: don't use GetSize to set the size Change-Id: I80a2701d7c125dbe6c80f8c32b125c7b176a8bb4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142062 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/editeng/inc/editdoc.hxx b/editeng/inc/editdoc.hxx index 4b92a9be258f..e5c3abbef0cf 100644 --- a/editeng/inc/editdoc.hxx +++ b/editeng/inc/editdoc.hxx @@ -409,7 +409,29 @@ public: sal_Int32 GetLen() const { return nLen; } void SetLen( sal_Int32 nL ) { nLen = nL; } - Size& GetSize() { return aOutSz; } + void setWidth(tools::Long nWidth) + { + aOutSz.setWidth(nWidth); + } + + void setHeight(tools::Long nHeight) + { + aOutSz.setHeight(nHeight); + } + + void adjustSize(tools::Long nDeltaX, tools::Long nDeltaY) + { + if (nDeltaX != 0) + aOutSz.AdjustWidth(nDeltaX); + if (nDeltaY != 0) + aOutSz.AdjustHeight(nDeltaY); + } + + void SetSize(const Size& rSize) + { + aOutSz = rSize; + } + const Size& GetSize() const { return aOutSz; } void SetKind(PortionKind n) { nKind = n; } diff --git a/editeng/source/editeng/impedit3.cxx b/editeng/source/editeng/impedit3.cxx index d98ea6e4188e..ed560fb0e138 100644 --- a/editeng/source/editeng/impedit3.cxx +++ b/editeng/source/editeng/impedit3.cxx @@ -1016,7 +1016,7 @@ bool ImpEditEngine::CreateLines( sal_Int32 nPara, sal_uInt32 nStartPosY ) nTmpWidth -= rPrev.GetSize().Width(); nTmpPos = nTmpPos - rPrev.GetLen(); rPrev.SetLen(rPrev.GetLen() + nTmpLen); - rPrev.GetSize().setWidth( -1 ); + rPrev.setWidth(-1); } assert( nTmpPortion < pParaPortion->GetTextPortions().Count() && "No more Portions left!" ); @@ -1079,11 +1079,11 @@ bool ImpEditEngine::CreateLines( sal_Int32 nPara, sal_uInt32 nStartPosY ) pPortion->SetKind(PortionKind::TAB); pPortion->SetExtraValue( aCurrentTab.aTabStop.GetFill() ); - pPortion->GetSize().setWidth( aCurrentTab.nTabPos - (nTmpWidth+nStartX) ); + pPortion->setWidth( aCurrentTab.nTabPos - (nTmpWidth+nStartX) ); // Height needed... SeekCursor( pNode, nTmpPos+1, aTmpFont ); - pPortion->GetSize().setHeight( GetRefDevice()->GetTextHeight() ); + pPortion->setHeight( GetRefDevice()->GetTextHeight() ); DBG_ASSERT( pPortion->GetSize().Width() >= 0, "Tab incorrectly calculated!" ); @@ -1095,7 +1095,7 @@ bool ImpEditEngine::CreateLines( sal_Int32 nPara, sal_uInt32 nStartPosY ) { // What now? // make the tab fitting - pPortion->GetSize().setWidth( nXWidth-nOldTmpWidth ); + pPortion->setWidth( nXWidth-nOldTmpWidth ); nTmpWidth = nXWidth-1; bEOL = true; bBrokenLine = true; @@ -1109,7 +1109,7 @@ bool ImpEditEngine::CreateLines( sal_Int32 nPara, sal_uInt32 nStartPosY ) case EE_FEATURE_LINEBR: { assert( pPortion ); - pPortion->GetSize().setWidth( 0 ); + pPortion->setWidth(0); bEOL = true; bLineBreak = true; pPortion->SetKind( PortionKind::LINEBREAK ); @@ -1128,8 +1128,8 @@ bool ImpEditEngine::CreateLines( sal_Int32 nPara, sal_uInt32 nStartPosY ) OUString aFieldValue = static_cast<const EditCharAttribField*>(pNextFeature)->GetFieldValue(); // get size, but also DXArray to allow length information in line breaking below std::vector<sal_Int32> aTmpDXArray; - pPortion->GetSize() = aTmpFont.QuickGetTextSize(GetRefDevice(), - aFieldValue, 0, aFieldValue.getLength(), &aTmpDXArray); + pPortion->SetSize(aTmpFont.QuickGetTextSize(GetRefDevice(), + aFieldValue, 0, aFieldValue.getLength(), &aTmpDXArray)); // So no scrolling for oversized fields if ( pPortion->GetSize().Width() > nXWidth ) @@ -1235,21 +1235,23 @@ bool ImpEditEngine::CreateLines( sal_Int32 nPara, sal_uInt32 nStartPosY ) { Size aSize( aTmpFont.QuickGetTextSize( GetRefDevice(), pParaPortion->GetNode()->GetString(), nTmpPos, nPortionLen, &aBuf )); - pPortion->GetSize().AdjustWidth(aSize.Width() ); + pPortion->adjustSize(aSize.Width(), 0); if (pPortion->GetSize().Height() < aSize.Height()) - pPortion->GetSize().setHeight( aSize.Height() ); + pPortion->setHeight(aSize.Height()); } else { - pPortion->GetSize() = aTmpFont.QuickGetTextSize( GetRefDevice(), - pParaPortion->GetNode()->GetString(), nTmpPos, nPortionLen, &aBuf ); + auto aSize = aTmpFont.QuickGetTextSize(GetRefDevice(), pParaPortion->GetNode()->GetString(), nTmpPos, nPortionLen, &aBuf); + pPortion->SetSize(aSize); } // #i9050# Do Kerning also behind portions... if ( ( aTmpFont.GetFixKerning() > 0 ) && ( ( nTmpPos + nPortionLen ) < pNode->Len() ) ) - pPortion->GetSize().AdjustWidth(aTmpFont.GetFixKerning() ); + pPortion->adjustSize(aTmpFont.GetFixKerning(), 0); if ( IsFixedCellHeight() ) - pPortion->GetSize().setHeight( ImplCalculateFontIndependentLineSpacing( aTmpFont.GetFontHeight() ) ); + { + pPortion->setHeight( ImplCalculateFontIndependentLineSpacing( aTmpFont.GetFontHeight() ) ); + } // The array is generally flattened at the beginning // => Always simply quick inserts. size_t nPos = nTmpPos - pLine->GetStart(); @@ -1280,7 +1282,7 @@ bool ImpEditEngine::CreateLines( sal_Int32 nPara, sal_uInt32 nStartPosY ) { tools::Long nExtraSpace = pPortion->GetSize().Height()/5; nExtraSpace = GetXValue( nExtraSpace ); - pPortion->GetSize().AdjustWidth(nExtraSpace ); + pPortion->adjustSize(nExtraSpace, 0); nTmpWidth += nExtraSpace; } } @@ -1326,7 +1328,7 @@ bool ImpEditEngine::CreateLines( sal_Int32 nPara, sal_uInt32 nStartPosY ) aCurrentTab.bValid = false; } TextPortion& rTabPortion = pParaPortion->GetTextPortions()[aCurrentTab.nTabPortion]; - rTabPortion.GetSize().setWidth( aCurrentTab.nTabPos - aCurrentTab.nStartPosX - nW - nStartX ); + rTabPortion.setWidth( aCurrentTab.nTabPos - aCurrentTab.nStartPosX - nW - nStartX ); nTmpWidth = aCurrentTab.nStartPosX + rTabPortion.GetSize().Width() + nWidthAfterTab; } @@ -1578,7 +1580,7 @@ bool ImpEditEngine::CreateLines( sal_Int32 nPara, sal_uInt32 nStartPosY ) { pLine->GetCharPosArray()[ nPosInArray ] = nNewValue; } - rTP.GetSize().AdjustWidth(n ); + rTP.adjustSize(n, 0); } pLine->SetTextWidth( aTextSize.Width() ); @@ -1803,9 +1805,9 @@ void ImpEditEngine::CreateAndInsertEmptyLine( ParaPortion* pParaPortion ) aTmpFont.SetPhysFont(*pRefDev); TextPortion* pDummyPortion = new TextPortion( 0 ); - pDummyPortion->GetSize() = aTmpFont.GetPhysTxtSize( pRefDev ); + pDummyPortion->SetSize(aTmpFont.GetPhysTxtSize(pRefDev)); if ( IsFixedCellHeight() ) - pDummyPortion->GetSize().setHeight( ImplCalculateFontIndependentLineSpacing( aTmpFont.GetFontHeight() ) ); + pDummyPortion->setHeight( ImplCalculateFontIndependentLineSpacing( aTmpFont.GetFontHeight() ) ); pParaPortion->GetTextPortions().Append(pDummyPortion); FormatterFontMetric aFormatterMetrics; RecalcFormatterFontMetrics( aFormatterMetrics, aTmpFont ); @@ -2140,7 +2142,7 @@ void ImpEditEngine::ImpBreakLine( ParaPortion* pParaPortion, EditLine* pLine, Te DBG_ASSERT( rTP.GetKind() == PortionKind::TEXT, "BlankRubber: No TextPortion!" ); DBG_ASSERT( nBreakPos > pLine->GetStart(), "SplitTextPortion at the beginning of the line?" ); sal_Int32 nPosInArray = nBreakPos - 1 - pLine->GetStart(); - rTP.GetSize().setWidth( ( nPosInArray && ( rTP.GetLen() > 1 ) ) ? pLine->GetCharPosArray()[ nPosInArray-1 ] : 0 ); + rTP.setWidth( ( nPosInArray && ( rTP.GetLen() > 1 ) ) ? pLine->GetCharPosArray()[ nPosInArray-1 ] : 0 ); if (o3tl::make_unsigned(nPosInArray) < pLine->GetCharPosArray().size()) { pLine->GetCharPosArray()[ nPosInArray ] = rTP.GetSize().Width(); @@ -2159,7 +2161,7 @@ void ImpEditEngine::ImpBreakLine( ParaPortion* pParaPortion, EditLine* pLine, Te pHyphPortion->SetLen( nAltDelChar ); if (cAlternateReplChar && !bAltFullLeft) pHyphPortion->SetExtraValue( cAlternateReplChar ); // Correct width of the portion above: - rPrev.GetSize().setWidth( + rPrev.setWidth( pLine->GetCharPosArray()[ nBreakPos-1 - pLine->GetStart() - nAltDelChar ] ); } @@ -2167,8 +2169,7 @@ void ImpEditEngine::ImpBreakLine( ParaPortion* pParaPortion, EditLine* pLine, Te SvxFont aFont; SeekCursor( pParaPortion->GetNode(), nBreakPos, aFont ); aFont.SetPhysFont(*GetRefDevice()); - pHyphPortion->GetSize().setHeight( GetRefDevice()->GetTextHeight() ); - pHyphPortion->GetSize().setWidth( GetRefDevice()->GetTextWidth( CH_HYPH ) ); + pHyphPortion->SetSize(Size(GetRefDevice()->GetTextHeight(), GetRefDevice()->GetTextWidth(CH_HYPH))); pParaPortion->GetTextPortions().Insert(++nEndPortion, pHyphPortion); } @@ -2251,7 +2252,7 @@ void ImpEditEngine::ImpAdjustBlocks( ParaPortion* pParaPortion, EditLine* pLine, // For the last character the portion must stop behind the blank // => Simplify correction: DBG_ASSERT( ( nPortionStart + rLastPortion.GetLen() ) == ( nLastChar+1 ), "Blank actually not at the end of the portion!?"); - rLastPortion.GetSize().AdjustWidth( -nBlankWidth ); + rLastPortion.adjustSize(-nBlankWidth, 0); nRemainingSpace += nBlankWidth; } pLine->GetCharPosArray()[nLastChar-nFirstChar] -= nBlankWidth; @@ -2288,9 +2289,11 @@ void ImpEditEngine::ImpAdjustBlocks( ParaPortion* pParaPortion, EditLine* pLine, TextPortion& rLastPortion = pParaPortion->GetTextPortions()[ nPortion ]; // The width of the portion: - rLastPortion.GetSize().AdjustWidth(nMore4Everyone ); - if ( nSomeExtraSpace ) - rLastPortion.GetSize().AdjustWidth( 1 ); + rLastPortion.adjustSize(nMore4Everyone, 0); + if (nSomeExtraSpace) + { + rLastPortion.adjustSize(1, 0); + } // Correct positions in array sal_Int32 nPortionEnd = nPortionStart + rLastPortion.GetLen(); @@ -2546,7 +2549,7 @@ sal_Int32 ImpEditEngine::SplitTextPortion( ParaPortion* pPortion, sal_Int32 nPos { // No new GetTextSize, instead use values from the Array: assert( nPos > pCurLine->GetStart() && "SplitTextPortion at the beginning of the line?" ); - pTextPortion->GetSize().setWidth( pCurLine->GetCharPosArray()[ nPos-pCurLine->GetStart()-1 ] ); + pTextPortion->setWidth(pCurLine->GetCharPosArray()[nPos - pCurLine->GetStart() - 1]); if ( pTextPortion->GetExtraInfos() && pTextPortion->GetExtraInfos()->bCompressed ) { @@ -2564,7 +2567,7 @@ sal_Int32 ImpEditEngine::SplitTextPortion( ParaPortion* pPortion, sal_Int32 nPos } } else - pTextPortion->GetSize().setWidth( -1 ); + pTextPortion->setWidth(-1); return nSplitPortion; } @@ -2702,7 +2705,7 @@ void ImpEditEngine::RecalcTextPortion( ParaPortion* pParaPortion, sal_Int32 nSta FindPortion( nStartPos, nPortionStart ); TextPortion& rTP = pParaPortion->GetTextPortions()[ nTP ]; rTP.SetLen( rTP.GetLen() + nNewChars ); - rTP.GetSize().setWidth( -1 ); + rTP.setWidth(-1); } } else @@ -2768,7 +2771,7 @@ void ImpEditEngine::RecalcTextPortion( ParaPortion* pParaPortion, sal_Int32 nSta TextPortion& rPrev = pParaPortion->GetTextPortions()[nLastPortion - 1]; DBG_ASSERT( rPrev.GetKind() == PortionKind::TEXT, "Portion?!" ); rPrev.SetLen( rPrev.GetLen() + pTP->GetLen() ); - rPrev.GetSize().setWidth( -1 ); + rPrev.setWidth(-1); } pParaPortion->GetTextPortions().Remove( nLastPortion ); } @@ -4743,7 +4746,7 @@ bool ImpEditEngine::ImplCalcAsianCompression(ContentNode* pNode, if ( bCompressed && ( n100thPercentFromMax == 10000 ) ) pTextPortion->GetExtraInfos()->nWidthFullCompression = nNewPortionWidth; - pTextPortion->GetSize().setWidth( nNewPortionWidth ); + pTextPortion->setWidth(nNewPortionWidth); if ( pTextPortion->GetExtraInfos() && ( n100thPercentFromMax != 10000 ) ) { @@ -4753,7 +4756,7 @@ bool ImpEditEngine::ImplCalcAsianCompression(ContentNode* pNode, nShrink /= 10000; tools::Long nNewWidth = pTextPortion->GetExtraInfos()->nOrgWidth - nShrink; if ( nNewWidth < pTextPortion->GetSize().Width() ) - pTextPortion->GetSize().setWidth( nNewWidth ); + pTextPortion->setWidth(nNewWidth); } } return bCompressed; @@ -4795,7 +4798,7 @@ void ImpEditEngine::ImplExpandCompressedPortions( EditLine* pLine, ParaPortion* { pTP = pTP2; pTP->GetExtraInfos()->bCompressed = false; - pTP->GetSize().setWidth( pTP->GetExtraInfos()->nOrgWidth ); + pTP->setWidth(pTP->GetExtraInfos()->nOrgWidth); if ( nCompressPercent ) { sal_Int32 nTxtPortion = pParaPortion->GetTextPortions().GetPos( pTP );