sw/source/core/text/guess.cxx | 39 +++++++++++++++++++-------------------- sw/source/core/text/guess.hxx | 7 ++++++- 2 files changed, 25 insertions(+), 21 deletions(-)
New commits: commit 81fa857d0939e648705383d774829d94ce7f589a Author: Caolán McNamara <caolan.mcnam...@collabora.com> AuthorDate: Tue Jun 11 11:29:44 2024 +0100 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Thu Jun 13 10:36:58 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/+/168681 Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com> Tested-by: Jenkins (cherry picked from commit e75a1eb21834fa872864df2cc5811c6463aceb78) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168713 Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> diff --git a/sw/source/core/text/guess.cxx b/sw/source/core/text/guess.cxx index f49f6fccd3d2..661c349f5d70 100644 --- a/sw/source/core/text/guess.cxx +++ b/sw/source/core/text/guess.cxx @@ -72,17 +72,17 @@ 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, SwTwips& rBreakWidth, - SwTwips& rExtraBlankWidth, tools::Long& rMaxSizeDiff, - SwTwips& rExtraAscent, SwTwips& rExtraDescent, - const SwTextFormatInfo& rInf, const SwScriptInfo& rSI, - sal_uInt16 maxComp, - std::optional<SwLinePortionLayoutContext> nLayoutContext) +bool SwTextGuess::maybeAdjustPositionsForBlockAdjust(tools::Long& rMaxSizeDiff, + SwTwips& rExtraAscent, SwTwips& rExtraDescent, + const SwTextFormatInfo& rInf, const SwScriptInfo& rSI, + sal_uInt16 maxComp, + std::optional<SwLinePortionLayoutContext> nLayoutContext) { const auto& adjObj = rInf.GetTextFrame()->GetTextNodeForParaProps()->GetSwAttrSet().GetAdjust(); const SvxAdjust& adjust = adjObj.GetAdjust(); @@ -101,7 +101,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) { @@ -126,7 +126,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 @@ -138,21 +138,21 @@ 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(), nLayoutContext, maxComp, - rBreakWidth, rMaxSizeDiff, rExtraAscent, rExtraDescent, + m_nBreakWidth, rMaxSizeDiff, rExtraAscent, rExtraDescent, rInf.GetCachedVclData().get()); - rInf.GetTextSize(&rSI, breakPos, rBreakStart - breakPos, nLayoutContext, maxComp, - rExtraBlankWidth, rMaxSizeDiff, rExtraAscent, rExtraDescent, + rInf.GetTextSize(&rSI, breakPos, m_nBreakStart - breakPos, nLayoutContext, maxComp, + m_nExtraBlankWidth, rMaxSizeDiff, rExtraAscent, rExtraDescent, 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 @@ -262,8 +262,7 @@ bool SwTextGuess::Guess( const SwTextPortion& rPor, SwTextFormatInfo &rInf, m_nCutPos = rInf.GetIdx() + nMaxLen; bool bRet = rPor.InFieldGrp() || maybeAdjustPositionsForBlockAdjust( - m_nCutPos, m_nBreakPos, m_nBreakStart, m_nBreakWidth, - m_nExtraBlankWidth, nMaxSizeDiff, nExtraAscent, nExtraDescent, rInf, + nMaxSizeDiff, nExtraAscent, nExtraDescent, rInf, rSI, nMaxComp, rInf.GetLayoutContext()); if( nItalic && (m_nCutPos >= TextFrameIndex(rInf.GetText().getLength()) || @@ -449,8 +448,7 @@ bool SwTextGuess::Guess( const SwTextPortion& rPor, SwTextFormatInfo &rInf, { bool bRet = rPor.InFieldGrp() || maybeAdjustPositionsForBlockAdjust( - m_nCutPos, m_nBreakPos, m_nBreakStart, m_nBreakWidth, - m_nExtraBlankWidth, nMaxSizeDiff, nExtraAscent, nExtraDescent, rInf, + nMaxSizeDiff, nExtraAscent, nExtraDescent, rInf, rSI, nMaxComp, rInf.GetLayoutContext()); if (nItalic && (m_nBreakPos + TextFrameIndex(1)) >= TextFrameIndex(rInf.GetText().getLength())) @@ -485,6 +483,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 309e86221aa4..a480e860b3e7 100644 --- a/sw/source/core/text/guess.hxx +++ b/sw/source/core/text/guess.hxx @@ -59,7 +59,12 @@ public: TextFrameIndex FieldDiff() const {return m_nFieldDiff; } const css::uno::Reference< css::linguistic2::XHyphenatedWord >& HyphWord() const { return m_xHyphWord; } +private: + bool maybeAdjustPositionsForBlockAdjust(tools::Long& rMaxSizeDiff, + SwTwips& rExtraAscent, SwTwips& rExtraDescent, + const SwTextFormatInfo& rInf, const SwScriptInfo& rSI, + sal_uInt16 maxComp, + std::optional<SwLinePortionLayoutContext> nLayoutContext); }; - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */