sw/source/core/text/porrst.cxx |   22 ++++++++++++++++++++++
 sw/source/core/text/porrst.hxx |    5 +++++
 2 files changed, 27 insertions(+)

New commits:
commit 604bb64047a243a856ac42ea47786800901378ff
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Mon Mar 7 09:34:45 2022 +0100
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Mon Mar 7 11:41:15 2022 +0100

    sw clearing breaks: fix rendering of the line break char itself
    
    The larger height is needed for the break portion, so the next line
    "jumps down", below the largest fly frame. But this has the side effect,
    that the line break character now has an unexpected vertical position,
    as it's vertically centered.
    
    Fix the problem by going back to the text height while painting.
    
    No test for this, SwBreakPortion::Paint() is a NOP unless rendering on a
    window, so the metafile-based rendering used for testing won't detect
    the difference.
    
    Change-Id: Ifd780c79488b149ff41d8e61585ee99c96a40128
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131093
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Tested-by: Jenkins

diff --git a/sw/source/core/text/porrst.cxx b/sw/source/core/text/porrst.cxx
index 002b2f5f56e9..82467d110aa6 100644
--- a/sw/source/core/text/porrst.cxx
+++ b/sw/source/core/text/porrst.cxx
@@ -23,6 +23,8 @@
 #include <editeng/lrspitem.hxx>
 #include <editeng/pgrditem.hxx>
 #include <vcl/svapp.hxx>
+#include <comphelper/scopeguard.hxx>
+
 #include <viewsh.hxx>
 #include <viewopt.hxx>
 #include <ndtxt.hxx>
@@ -106,6 +108,7 @@ SwBreakPortion::SwBreakPortion( const SwLinePortion 
&rPortion, const SwTextAttr*
     {
         m_eClear = pAttr->GetLineBreak().GetValue();
     }
+    m_nTextHeight = 0;
 }
 
 TextFrameIndex SwBreakPortion::GetModelPositionForViewPoint(const sal_uInt16) 
const
@@ -124,6 +127,13 @@ void SwBreakPortion::Paint( const SwTextPaintInfo &rInf ) 
const
     if( !(rInf.OnWin() && rInf.GetOpt().IsLineBreak()) )
         return;
 
+    // Reduce height to text height for the duration of the print, so the 
vertical height will look
+    // correct for the line break character, even for clearing breaks.
+    SwTwips nHeight = Height();
+    auto pPortion = const_cast<SwBreakPortion*>(this);
+    pPortion->Height(m_nTextHeight, false);
+    comphelper::ScopeGuard g([pPortion, nHeight] { pPortion->Height(nHeight, 
false); });
+
     rInf.DrawLineBreak( *this );
 
     // paint redlining
@@ -163,6 +173,7 @@ bool SwBreakPortion::Format( SwTextFormatInfo &rInf )
     const SwLinePortion *pRoot = rInf.GetRoot();
     Width( 0 );
     Height( pRoot->Height() );
+    m_nTextHeight = Height();
 
     // See if this is a clearing break. If so, calculate how much we need to 
"jump down" so the next
     // line can again use the full text width.
@@ -190,6 +201,17 @@ void SwBreakPortion::HandlePortion( SwPortionHandler& rPH 
) const
     rPH.Text( GetLen(), GetWhichPor() );
 }
 
+void SwBreakPortion::dumpAsXml(xmlTextWriterPtr pWriter) const
+{
+    (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SwBreakPortion"));
+    (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("text-height"),
+                                      
BAD_CAST(OString::number(m_nTextHeight).getStr()));
+
+    SwLinePortion::dumpAsXml(pWriter);
+
+    (void)xmlTextWriterEndElement(pWriter);
+}
+
 SwLineBreakClear SwBreakPortion::GetClear() const { return m_eClear; }
 
 SwKernPortion::SwKernPortion( SwLinePortion &rPortion, short nKrn,
diff --git a/sw/source/core/text/porrst.hxx b/sw/source/core/text/porrst.hxx
index 362a16dec0b4..db4c974f25de 100644
--- a/sw/source/core/text/porrst.hxx
+++ b/sw/source/core/text/porrst.hxx
@@ -62,6 +62,9 @@ class SwBreakPortion : public SwLinePortion
     /// Tracks the type of the breaking clear from SwTextLineBreak, if there 
is one.
     SwLineBreakClear m_eClear;
 
+    /// Height of the line-break character itself, without spacing added for 
clearing.
+    SwTwips m_nTextHeight;
+
 public:
     explicit SwBreakPortion(const SwLinePortion& rPortion, const SwTextAttr* 
pAttr);
     // Returns 0 if we have no usable data
@@ -74,6 +77,8 @@ public:
     // Accessibility: pass information about this portion to the PortionHandler
     virtual void HandlePortion( SwPortionHandler& rPH ) const override;
 
+    void dumpAsXml(xmlTextWriterPtr pWriter) const override;
+
     static constexpr OUStringLiteral S_NOBREAK_FOR_REDLINE = u"\u00A0";
     void SetRedline( const RedlineType eRedline ) { m_eRedline = eRedline; }
 

Reply via email to