sw/source/core/text/itradj.cxx | 22 +++++----------------- sw/source/core/text/itrform2.cxx | 1 + sw/source/core/text/porlin.hxx | 6 ++++++ sw/source/core/text/portxt.cxx | 8 ++++++++ 4 files changed, 20 insertions(+), 17 deletions(-)
New commits: commit 22eac3145ca62d15b47d95f4df60ce38d4f5aa46 Author: László Németh <nem...@numbertext.org> AuthorDate: Thu Aug 29 17:01:56 2024 +0200 Commit: László Németh <nem...@numbertext.org> CommitDate: Fri Aug 30 00:59:37 2024 +0200 tdf#162220 sw smart justify: fix shrinking for single portion lines Follow-up to commit 6b857398a59d16308d6185d01e003e401439f060 "tdf#162109 sw smart justify: fix overhanging last line". Regression from commit 17eaebee279772b6062ae3448012133897fc71bb "tdf#119908 sw smart justify: fix justification by shrinking". Change-Id: I6e2dbdbf3628bdae765c235d5f29c1aa0b8987ca Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172599 Reviewed-by: László Németh <nem...@numbertext.org> Tested-by: Jenkins diff --git a/sw/source/core/text/itradj.cxx b/sw/source/core/text/itradj.cxx index 7d0011682b39..277359ff25d1 100644 --- a/sw/source/core/text/itradj.cxx +++ b/sw/source/core/text/itradj.cxx @@ -45,25 +45,10 @@ void SwTextAdjuster::FormatBlock( ) const SwLinePortion *pFly = nullptr; bool bSkip = !IsLastBlock() && + // don't skip, if the last paragraph line needs space shrinking + m_pCurr->ExtraShrunkWidth() <= m_pCurr->Width() && m_nStart + m_pCurr->GetLen() >= TextFrameIndex(GetInfo().GetText().getLength()); - // tdf#162109 if the last line is longer, than the paragraph width, - // it contains shrinking spaces: don't skip block format here - if( bSkip ) - { - // sum width of the text portions to calculate the line width without shrinking - tools::Long nBreakWidth = 0; - const SwLinePortion *pPos = m_pCurr->GetNextPortion(); - while( pPos && bSkip ) - { - if( !pPos->InGlueGrp() ) - nBreakWidth += pPos->Width(); - if( nBreakWidth > m_pCurr->Width() ) - bSkip = false; - pPos = pPos->GetNextPortion(); - } - } - // Multi-line fields are tricky, because we need to check whether there are // any other text portions in the paragraph. if( bSkip ) @@ -408,6 +393,9 @@ void SwTextAdjuster::CalcNewBlock( SwLineLayout *pCurrent, if( nGluePortion ) { tools::Long nSpaceAdd = nGluePortionWidth / sal_Int32(nGluePortion); + // shrink, if not shrunk line width exceed the set line width + if ( pCurrent->ExtraShrunkWidth() > 0 ) + nBreakWidth = pCurrent->ExtraShrunkWidth(); // shrink, if portions exceed the line width tools::Long nSpaceSub = ( nBreakWidth > pCurrent->Width() ) ? (nBreakWidth - pCurrent->Width()) * SPACING_PRECISION_FACTOR / diff --git a/sw/source/core/text/itrform2.cxx b/sw/source/core/text/itrform2.cxx index 32cb08474db2..89a2744d0bd9 100644 --- a/sw/source/core/text/itrform2.cxx +++ b/sw/source/core/text/itrform2.cxx @@ -2135,6 +2135,7 @@ TextFrameIndex SwTextFormatter::FormatLine(TextFrameIndex const nStartPos) m_pCurr->SetLen(TextFrameIndex(0)); m_pCurr->Width(0); + m_pCurr->ExtraShrunkWidth(0); m_pCurr->Truncate(); } } diff --git a/sw/source/core/text/porlin.hxx b/sw/source/core/text/porlin.hxx index 1b4b50ba44b8..9c9891101b23 100644 --- a/sw/source/core/text/porlin.hxx +++ b/sw/source/core/text/porlin.hxx @@ -49,6 +49,8 @@ private: bool m_bJoinBorderWithPrev; bool m_bJoinBorderWithNext; SwTwips m_nExtraBlankWidth = 0; // width of spaces after the break + SwTwips m_nExtraShrunkWidth = 0; // width of not shrunk line + std::optional<SwLinePortionLayoutContext> m_nLayoutContext; void Truncate_(); @@ -72,6 +74,8 @@ public: void SubPrtWidth( const SwTwips nNew ) { Width( Width() - nNew ); } SwTwips ExtraBlankWidth() const { return m_nExtraBlankWidth; } void ExtraBlankWidth(const SwTwips nNew) { m_nExtraBlankWidth = nNew; } + SwTwips ExtraShrunkWidth() const { return m_nExtraShrunkWidth; } + void ExtraShrunkWidth(const SwTwips nNew) { m_nExtraShrunkWidth = nNew; } SwTwips GetHangingBaseline() const { return mnHangingBaseline; } void SetHangingBaseline( const SwTwips nNewBaseline ) { mnHangingBaseline = nNewBaseline; } std::optional<SwLinePortionLayoutContext> GetLayoutContext() const { return m_nLayoutContext; } @@ -185,6 +189,7 @@ inline SwLinePortion &SwLinePortion::operator=(const SwLinePortion &rPortion) m_bJoinBorderWithPrev = rPortion.m_bJoinBorderWithPrev; m_bJoinBorderWithNext = rPortion.m_bJoinBorderWithNext; m_nExtraBlankWidth = rPortion.m_nExtraBlankWidth; + m_nExtraShrunkWidth = rPortion.m_nExtraShrunkWidth; m_nLayoutContext = rPortion.m_nLayoutContext; return *this; } @@ -199,6 +204,7 @@ inline SwLinePortion::SwLinePortion(const SwLinePortion &rPortion) : m_bJoinBorderWithPrev( rPortion.m_bJoinBorderWithPrev ), m_bJoinBorderWithNext( rPortion.m_bJoinBorderWithNext ), m_nExtraBlankWidth(rPortion.m_nExtraBlankWidth), + m_nExtraShrunkWidth(rPortion.m_nExtraShrunkWidth), m_nLayoutContext(rPortion.m_nLayoutContext) { } diff --git a/sw/source/core/text/portxt.cxx b/sw/source/core/text/portxt.cxx index 0cc54de42606..bd64b6336a15 100644 --- a/sw/source/core/text/portxt.cxx +++ b/sw/source/core/text/portxt.cxx @@ -258,6 +258,7 @@ void SwTextPortion::BreakCut( SwTextFormatInfo &rInf, const SwTextGuess &rGuess { SetLen( TextFrameIndex(0) ); Width( 0 ); + ExtraShrunkWidth( 0 ); } } @@ -266,6 +267,7 @@ void SwTextPortion::BreakUnderflow( SwTextFormatInfo &rInf ) Truncate(); Height( 0 ); Width( 0 ); + ExtraShrunkWidth( 0 ); SetLen( TextFrameIndex(0) ); SetAscent( 0 ); rInf.SetUnderflow( this ); @@ -301,6 +303,7 @@ bool SwTextPortion::Format_( SwTextFormatInfo &rInf ) return bFull; } + ExtraShrunkWidth( 0 ); std::unique_ptr<SwTextGuess> pGuess(new SwTextGuess()); bool bFull = !pGuess->Guess( *this, rInf, Height() ); @@ -339,8 +342,12 @@ bool SwTextPortion::Format_( SwTextFormatInfo &rInf ) if ( nSpacesInLine > 0 ) { + SwTwips nOldWidth = pGuess->BreakWidth(); pGuess.reset(new SwTextGuess()); bFull = !pGuess->Guess( *this, rInf, Height(), nSpacesInLine ); + + if ( pGuess->BreakWidth() > nOldWidth ) + ExtraShrunkWidth( pGuess->BreakWidth() ); } } @@ -492,6 +499,7 @@ bool SwTextPortion::Format( SwTextFormatInfo &rInf ) { Height( 0 ); Width( 0 ); + ExtraShrunkWidth( 0 ); SetLen( TextFrameIndex(0) ); SetAscent( 0 ); SetNextPortion( nullptr ); // ????