tdf#162220 sw smart justify: fix shrinking for single portion lines
Follow-up to commit6b857398a5
"tdf#162109 sw smart justify: fix overhanging last line". Regression from commit17eaebee27
"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 <nemeth@numbertext.org> Tested-by: Jenkins
This commit is contained in:
@@ -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 /
|
||||
|
@@ -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();
|
||||
}
|
||||
}
|
||||
|
@@ -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)
|
||||
{
|
||||
}
|
||||
|
@@ -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 ); // ????
|
||||
|
Reference in New Issue
Block a user