[Libreoffice-commits] core.git: sw/qa sw/source

Miklos Vajna vmiklos at collabora.co.uk
Fri May 11 07:03:44 UTC 2018


 sw/qa/extras/layout/data/tdf117245.odt |binary
 sw/qa/extras/layout/layout.cxx         |   14 ++++++++++++++
 sw/source/core/text/guess.cxx          |    2 +-
 sw/source/core/text/inftxt.cxx         |   23 +++++++++++++++++++++++
 sw/source/core/text/inftxt.hxx         |    6 ++++++
 sw/source/core/text/itrform2.cxx       |    2 +-
 6 files changed, 45 insertions(+), 2 deletions(-)

New commits:
commit 7758d6609da2c1df978818823f6f9856b99dcefc
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Thu May 10 15:53:16 2018 +0200

    tdf#117245 sw layout: extend TabOverMargin compat mode
    
    This layout compatibility flag is supposed to mimic Word behavior, but
    in both cases we failed to lay out the text as Word does.
    
    Change-Id: Ic6fb2eb16ce3670d23aeb9f17bd7043f55164883
    Reviewed-on: https://gerrit.libreoffice.org/54087
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>

diff --git a/sw/qa/extras/layout/data/tdf117245.odt b/sw/qa/extras/layout/data/tdf117245.odt
new file mode 100644
index 000000000000..7008c325bace
Binary files /dev/null and b/sw/qa/extras/layout/data/tdf117245.odt differ
diff --git a/sw/qa/extras/layout/layout.cxx b/sw/qa/extras/layout/layout.cxx
index aa2146354fc0..4d05162a7d74 100644
--- a/sw/qa/extras/layout/layout.cxx
+++ b/sw/qa/extras/layout/layout.cxx
@@ -20,12 +20,14 @@ public:
     void testTdf116925();
     void testTdf117028();
     void testTdf116848();
+    void testTdf117245();
 
     CPPUNIT_TEST_SUITE(SwLayoutWriter);
     CPPUNIT_TEST(testTdf116830);
     CPPUNIT_TEST(testTdf116925);
     CPPUNIT_TEST(testTdf117028);
     CPPUNIT_TEST(testTdf116848);
+    CPPUNIT_TEST(testTdf117245);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -117,6 +119,18 @@ void SwLayoutWriter::testTdf116848()
     pDoc->getIDocumentLayoutAccess().GetCurrentViewShell()->CalcLayout();
 }
 
+void SwLayoutWriter::testTdf117245()
+{
+    createDoc("tdf117245.odt");
+    xmlDocPtr pXmlDoc = parseLayoutDump();
+    // This was 2, TabOverMargin did not use a single line when there was
+    // enough space for the text.
+    assertXPath(pXmlDoc, "/root/page/body/txt[1]/LineBreak", 1);
+
+    // This was 2, same problem elsewhere due to code duplication.
+    assertXPath(pXmlDoc, "/root/page/body/txt[2]/LineBreak", 1);
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(SwLayoutWriter);
 CPPUNIT_PLUGIN_IMPLEMENT();
 
diff --git a/sw/source/core/text/guess.cxx b/sw/source/core/text/guess.cxx
index 5ddf80485522..b3cb3b02d472 100644
--- a/sw/source/core/text/guess.cxx
+++ b/sw/source/core/text/guess.cxx
@@ -70,7 +70,7 @@ bool SwTextGuess::Guess( const SwTextPortion& rPor, SwTextFormatInfo &rInf,
                         10000 :
                             0 ;
 
-    SwTwips nLineWidth = rInf.Width() - rInf.X();
+    SwTwips nLineWidth = rInf.GetLineWidth();
     sal_Int32 nMaxLen = rInf.GetText().getLength() - rInf.GetIdx();
 
     const SvxAdjust& rAdjust = rInf.GetTextFrame()->GetTextNode()->GetSwAttrSet().GetAdjust().GetAdjust();
diff --git a/sw/source/core/text/inftxt.cxx b/sw/source/core/text/inftxt.cxx
index 65e25af2ee58..d66f946a04ed 100644
--- a/sw/source/core/text/inftxt.cxx
+++ b/sw/source/core/text/inftxt.cxx
@@ -57,6 +57,7 @@
 #include "porftn.hxx"
 #include "porrst.hxx"
 #include "itratr.hxx"
+#include "portab.hxx"
 #include <accessibilityoptions.hxx>
 #include <wrong.hxx>
 #include <doc.hxx>
@@ -1688,6 +1689,28 @@ bool SwTextFormatInfo::LastKernPortion()
     return false;
 }
 
+SwTwips SwTextFormatInfo::GetLineWidth()
+{
+    SwTwips nLineWidth = Width() - X();
+
+    const bool bTabOverMargin = GetTextFrame()->GetTextNode()->getIDocumentSettingAccess()->get(
+        DocumentSettingId::TAB_OVER_MARGIN);
+    if (!bTabOverMargin)
+        return nLineWidth;
+
+    SwTabPortion* pLastTab = GetLastTab();
+    if (!pLastTab)
+        return nLineWidth;
+
+    if (pLastTab->GetTabPos() <= Width())
+        return nLineWidth;
+
+    // Consider tab portions over the printing bounds of the text frame.
+    nLineWidth = pLastTab->GetTabPos() - X();
+
+    return nLineWidth;
+}
+
 SwTextSlot::SwTextSlot(
     const SwTextSizeInfo *pNew,
     const SwLinePortion *pPor,
diff --git a/sw/source/core/text/inftxt.hxx b/sw/source/core/text/inftxt.hxx
index 91f7ef655fb0..ac85d3da4281 100644
--- a/sw/source/core/text/inftxt.hxx
+++ b/sw/source/core/text/inftxt.hxx
@@ -540,6 +540,12 @@ public:
     void Width( const sal_uInt16 nNew ) { m_nWidth = nNew; }
            void Init();
 
+    /**
+     * Returns the distance between the current horizontal position and the end
+     * of the line.
+     */
+    SwTwips GetLineWidth();
+
     // Returns the first changed position of the paragraph
     inline sal_Int32 GetReformatStart() const;
 
diff --git a/sw/source/core/text/itrform2.cxx b/sw/source/core/text/itrform2.cxx
index 39f68943cb91..f8b8b16c679b 100755
--- a/sw/source/core/text/itrform2.cxx
+++ b/sw/source/core/text/itrform2.cxx
@@ -979,7 +979,7 @@ SwTextPortion *SwTextFormatter::NewTextPortion( SwTextFormatInfo &rInf )
                              sal_Int32( pPor->GetAscent() ) ) / 8;
     if ( !nExpect )
         nExpect = 1;
-    nExpect = rInf.GetIdx() + ((rInf.Width() - rInf.X()) / nExpect);
+    nExpect = rInf.GetIdx() + (rInf.GetLineWidth() / nExpect);
     if( nExpect > rInf.GetIdx() && nNextChg > nExpect )
         nNextChg = std::min( nExpect, rInf.GetText().getLength() );
 


More information about the Libreoffice-commits mailing list