sw/source/core/text/guess.cxx |   34 +++++++++++++++-------------------
 sw/source/core/text/guess.hxx |    4 +++-
 2 files changed, 18 insertions(+), 20 deletions(-)

New commits:
commit f55d30a8baae5413769674ca86f9c91bc592ee5a
Author:     Caolán McNamara <caolan.mcnam...@collabora.com>
AuthorDate: Tue Jun 11 11:29:44 2024 +0100
Commit:     Andras Timar <andras.ti...@collabora.com>
CommitDate: Tue Jun 11 23:23:28 2024 +0200

    more stale hyphenation data after skipping blanks
    
    m_xHyphWord is stale if m_nBreakStart changes
    
    turn maybeAdjustPositionsForBlockAdjust into a member
    to make it easier to discard m_xHyphWord on change
    to m_nBreakStart
    
    Change-Id: I6ca37371bf6b8362ebd16a08594afcff3222fa12
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168666
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>

diff --git a/sw/source/core/text/guess.cxx b/sw/source/core/text/guess.cxx
index c199bbfcfa97..c4f74de7cef7 100644
--- a/sw/source/core/text/guess.cxx
+++ b/sw/source/core/text/guess.cxx
@@ -71,15 +71,14 @@ bool hasBlanksInLine(const SwTextFormatInfo& rInf, 
TextFrameIndex end)
     return false;
 }
 
+}
+
 // Called for the last text run in a line; if it is block-adjusted, or center 
/ right-adjusted
 // with Word compatibility option set, and it has trailing spaces, then the 
function sets the
 // values, and returns 'false' value that SwTextGuess::Guess should return, to 
create a
 // trailing SwHolePortion.
-bool maybeAdjustPositionsForBlockAdjust(TextFrameIndex& rCutPos, 
TextFrameIndex& rBreakPos,
-                                        TextFrameIndex& rBreakStart, 
sal_uInt16& rBreakWidth,
-                                        sal_uInt16& rExtraBlankWidth, 
sal_uInt16& rMaxSizeDiff,
-                                        const SwTextFormatInfo& rInf, const 
SwScriptInfo& rSI,
-                                        sal_uInt16 maxComp)
+bool SwTextGuess::maybeAdjustPositionsForBlockAdjust(sal_uInt16& rMaxSizeDiff, 
const SwTextFormatInfo& rInf,
+                                                     const SwScriptInfo& rSI, 
sal_uInt16 maxComp)
 {
     const auto& adjObj = 
rInf.GetTextFrame()->GetTextNodeForParaProps()->GetSwAttrSet().GetAdjust();
     const SvxAdjust& adjust = adjObj.GetAdjust();
@@ -98,7 +97,7 @@ bool maybeAdjustPositionsForBlockAdjust(TextFrameIndex& 
rCutPos, TextFrameIndex&
         if (rInf.GetTextFrame()->IsRightToLeft())
             return true;
     }
-    if (auto ch = rInf.GetChar(rCutPos); !ch) // end of paragraph - last line
+    if (auto ch = rInf.GetChar(m_nCutPos); !ch) // end of paragraph - last line
     {
         if (adjust == SvxAdjust::Block)
         {
@@ -123,7 +122,7 @@ bool maybeAdjustPositionsForBlockAdjust(TextFrameIndex& 
rCutPos, TextFrameIndex&
     // tdf#57187: block-adjusted line shorter than full width, terminated by 
manual
     // line break, must not use trailing spaces for adjustment
     TextFrameIndex breakPos;
-    TextFrameIndex newCutPos = AdjustCutPos(rCutPos, breakPos, rInf);
+    TextFrameIndex newCutPos = AdjustCutPos(m_nCutPos, breakPos, rInf);
 
     if (auto ch = rInf.GetChar(newCutPos); ch && ch != CH_BREAK)
         return true; // next is neither line break nor paragraph end
@@ -135,19 +134,19 @@ bool maybeAdjustPositionsForBlockAdjust(TextFrameIndex& 
rCutPos, TextFrameIndex&
 
     // Some trailing spaces actually found, and in case of block adjustment, 
the text portion
     // itself has spaces to be able to block-adjust, or single word is allowed 
to adjust
-    rBreakStart = rCutPos = newCutPos;
-    rBreakPos = breakPos;
+    m_nBreakStart = m_nCutPos = newCutPos;
+    m_nBreakPos = breakPos;
+    // throw away old m_xHyphWord because the current break pos is now between 
words
+    m_xHyphWord = nullptr;
 
-    rInf.GetTextSize(&rSI, rInf.GetIdx(), breakPos - rInf.GetIdx(), maxComp, 
rBreakWidth,
+    rInf.GetTextSize(&rSI, rInf.GetIdx(), breakPos - rInf.GetIdx(), maxComp, 
m_nBreakWidth,
                      rMaxSizeDiff, rInf.GetCachedVclData().get());
-    rInf.GetTextSize(&rSI, breakPos, rBreakStart - breakPos, maxComp, 
rExtraBlankWidth,
+    rInf.GetTextSize(&rSI, breakPos, m_nBreakStart - breakPos, maxComp, 
m_nExtraBlankWidth,
                      rMaxSizeDiff, rInf.GetCachedVclData().get());
 
     return false; // require SwHolePortion creation
 }
 
-}
-
 // provides information for line break calculation
 // returns true if no line break has to be performed
 // otherwise possible break or hyphenation position is determined
@@ -254,9 +253,7 @@ bool SwTextGuess::Guess( const SwTextPortion& rPor, 
SwTextFormatInfo &rInf,
             // portion fits to line
             m_nCutPos = rInf.GetIdx() + nMaxLen;
             bool bRet = rPor.InFieldGrp()
-                        || maybeAdjustPositionsForBlockAdjust(m_nCutPos, 
m_nBreakPos, m_nBreakStart,
-                                                              m_nBreakWidth, 
m_nExtraBlankWidth,
-                                                              nMaxSizeDiff, 
rInf, rSI, nMaxComp);
+                        || maybeAdjustPositionsForBlockAdjust(nMaxSizeDiff, 
rInf, rSI, nMaxComp);
             if( nItalic &&
                 (m_nCutPos >= TextFrameIndex(rInf.GetText().getLength()) ||
                   // #i48035# Needed for CalcFitToContent
@@ -410,9 +407,7 @@ bool SwTextGuess::Guess( const SwTextPortion& rPor, 
SwTextFormatInfo &rInf,
         if ( m_nBreakWidth <= nLineWidth )
         {
             bool bRet = rPor.InFieldGrp()
-                        || maybeAdjustPositionsForBlockAdjust(m_nCutPos, 
m_nBreakPos, m_nBreakStart,
-                                                              m_nBreakWidth, 
m_nExtraBlankWidth,
-                                                              nMaxSizeDiff, 
rInf, rSI, nMaxComp);
+                        || maybeAdjustPositionsForBlockAdjust(nMaxSizeDiff, 
rInf, rSI, nMaxComp);
 
             if (nItalic && (m_nBreakPos + TextFrameIndex(1)) >= 
TextFrameIndex(rInf.GetText().getLength()))
                 m_nBreakWidth += nItalic;
@@ -443,6 +438,7 @@ bool SwTextGuess::Guess( const SwTextPortion& rPor, 
SwTextFormatInfo &rInf,
     {
         m_nCutPos = m_nBreakStart = AdjustCutPos(m_nCutPos, m_nBreakPos, rInf);
         nPorLen = m_nBreakPos - rInf.GetIdx();
+        // throw away old m_xHyphWord when m_nBreakStart changes
         m_xHyphWord = nullptr;
     }
     else
diff --git a/sw/source/core/text/guess.hxx b/sw/source/core/text/guess.hxx
index 5a7a9ac1cfa2..4bc122960389 100644
--- a/sw/source/core/text/guess.hxx
+++ b/sw/source/core/text/guess.hxx
@@ -59,7 +59,9 @@ public:
     TextFrameIndex FieldDiff() const {return m_nFieldDiff; }
     const css::uno::Reference< css::linguistic2::XHyphenatedWord >& HyphWord() 
const
         { return m_xHyphWord; }
+private:
+    bool maybeAdjustPositionsForBlockAdjust(sal_uInt16& rMaxSizeDiff, const 
SwTextFormatInfo& rInf,
+                                            const SwScriptInfo& rSI, 
sal_uInt16 maxComp);
 };
 
-
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Reply via email to