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

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Mon Oct 8 10:09:25 UTC 2018


 sw/qa/extras/layout/data/tdf120287c.fodt |   46 +++++++++++++++++++++++++++++++
 sw/qa/extras/layout/layout.cxx           |   11 +++++++
 sw/source/core/text/inftxt.cxx           |   20 ++++++++++++-
 sw/source/core/text/inftxt.hxx           |    3 ++
 sw/source/core/text/itrform2.cxx         |    1 
 5 files changed, 79 insertions(+), 2 deletions(-)

New commits:
commit cb9ba1c2d0202b1932b637d83a9458879a1f2e6a
Author:     Miklos Vajna <vmiklos at collabora.co.uk>
AuthorDate: Mon Oct 8 10:48:36 2018 +0200
Commit:     Miklos Vajna <vmiklos at collabora.co.uk>
CommitDate: Mon Oct 8 12:09:02 2018 +0200

    Related: tdf#120287 sw layout, TabOverMargin: fix left margin handling
    
    The old code only worked when left and first margin was 0; feed the
    relevant margin to SwTextFormatInfo, so SwTextFormatInfo::GetLineWidth()
    can compare against the right rectangle.
    
    This way TabOverMargin compat flag results in layout that matches the
    Word behavior for all 3 bugdocs from the bugreport.
    
    Change-Id: I6f81ad33b14e95ba4213c8956b3a9790ba6eee84
    Reviewed-on: https://gerrit.libreoffice.org/61518
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins

diff --git a/sw/qa/extras/layout/data/tdf120287c.fodt b/sw/qa/extras/layout/data/tdf120287c.fodt
new file mode 100644
index 000000000000..f367336d79ec
--- /dev/null
+++ b/sw/qa/extras/layout/data/tdf120287c.fodt
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<office:document xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:config="urn:oas
 is:names:tc:opendocument:xmlns:config:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:rpt="http://openoffice.org/2005/report" xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:grddl="http://www.w3.org/2003/g/data-view#" xmlns:officeooo="http://openoffice.org/2009/office" xmlns:tableooo="http://openoffice.org/2009/table" xmlns:drawooo="http://openoffice.org/2010/draw" xmlns:calcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0" xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0" xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0" xmlns:formx="urn:openoffice:names:
 experimental:ooxml-odf-interop:xmlns:form:1.0" xmlns:css3t="http://www.w3.org/TR/css3-text/" office:version="1.2" office:mimetype="application/vnd.oasis.opendocument.text">
+  <office:settings>
+    <config:config-item-set config:name="ooo:configuration-settings">
+      <config:config-item config:name="TabOverMargin" config:type="boolean">true</config:config-item>
+      <config:config-item config:name="PrinterIndependentLayout" config:type="string">high-resolution</config:config-item>
+      <config:config-item config:name="TabOverflow" config:type="boolean">false</config:config-item>
+    </config:config-item-set>
+  </office:settings>
+  <office:font-face-decls>
+    <style:font-face style:name="Liberation Serif" svg:font-family="'Liberation Serif'" style:font-family-generic="roman" style:font-pitch="variable"/>
+  </office:font-face-decls>
+  <office:styles>
+    <style:default-style style:family="paragraph">
+      <style:paragraph-properties fo:hyphenation-ladder-count="no-limit" style:text-autospace="ideograph-alpha" style:punctuation-wrap="hanging" style:line-break="strict" style:tab-stop-distance="1.251cm" style:writing-mode="page"/>
+      <style:text-properties style:use-window-font-color="true" style:font-name="Liberation Serif" fo:font-size="16pt" style:font-size-asian="12pt" style:language-asian="none" style:country-asian="none" style:font-size-complex="12pt"/>
+    </style:default-style>
+    <style:style style:name="Standard" style:family="paragraph" style:class="text">
+      <style:paragraph-properties fo:margin-top="0cm" fo:margin-bottom="0.141cm" loext:contextual-spacing="false" fo:line-height="0.388cm"></style:paragraph-properties>
+      <style:text-properties style:use-window-font-color="true" style:font-name="Liberation Serif" style:font-family-generic="roman" style:font-pitch="variable" fo:font-size="10pt"/>
+    </style:style>
+    <style:style style:name="Para" style:family="paragraph" style:parent-style-name="Standard">
+      <style:paragraph-properties fo:margin-left="1.251cm" fo:margin-right="0cm" fo:margin-top="0cm" fo:margin-bottom="0.141cm" fo:line-height="0.388cm" fo:text-align="start" fo:text-indent="-1.251cm">
+        <style:tab-stops>
+          <style:tab-stop style:position="9.751cm" style:type="right"/>
+        </style:tab-stops>
+      </style:paragraph-properties>
+    </style:style>
+  </office:styles>
+  <office:automatic-styles>
+    <style:style style:name="P1" style:family="paragraph" style:parent-style-name="Para" style:master-page-name="Page">
+      <style:paragraph-properties fo:margin-left="1.251cm" fo:margin-right="2.499cm" fo:text-align="start" fo:text-indent="-1.251cm" style:auto-text-indent="false"/>
+    </style:style>
+    <style:page-layout style:name="pm2" style:page-usage="mirrored">
+      <style:page-layout-properties fo:page-width="14.801cm" fo:page-height="21.001cm" style:num-format="1" style:print-orientation="portrait" fo:margin-top="1.101cm" fo:margin-bottom="1cm" fo:margin-left="1.9cm" fo:margin-right="1.9cm"/>
+    </style:page-layout>
+  </office:automatic-styles>
+  <office:master-styles>
+    <style:master-page style:name="Page" style:page-layout-name="pm2"/>
+  </office:master-styles>
+  <office:body>
+    <office:text>
+      <text:p text:style-name="P1">b) x x x Lorem ipsum dolor sit amet, consetetur sadips test Lorem ipsum dolor sit amet, consetetur sadips<text:tab/>1 2 3 4 5 6 7 8 9 a b sed diam</text:p>
+    </office:text>
+  </office:body>
+</office:document>
diff --git a/sw/qa/extras/layout/layout.cxx b/sw/qa/extras/layout/layout.cxx
index fbef817cd8fd..083c2f16302b 100644
--- a/sw/qa/extras/layout/layout.cxx
+++ b/sw/qa/extras/layout/layout.cxx
@@ -59,6 +59,7 @@ public:
     void testTdf119875();
     void testTdf120287();
     void testTdf120287b();
+    void testTdf120287c();
 
     CPPUNIT_TEST_SUITE(SwLayoutWriter);
     CPPUNIT_TEST(testRedlineFootnotes);
@@ -90,6 +91,7 @@ public:
     CPPUNIT_TEST(testTdf119875);
     CPPUNIT_TEST(testTdf120287);
     CPPUNIT_TEST(testTdf120287b);
+    CPPUNIT_TEST(testTdf120287c);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -2571,6 +2573,15 @@ void SwLayoutWriter::testTdf120287b()
     assertXPath(pXmlDoc, "/root/page/body/txt[1]/Text[@nType='POR_TABRIGHT']", "nWidth", "17");
 }
 
+void SwLayoutWriter::testTdf120287c()
+{
+    createDoc("tdf120287c.fodt");
+    xmlDocPtr pXmlDoc = parseLayoutDump();
+    // This was 2, the second line was not broken into a 2nd and a 3rd one,
+    // rendering text outside the paragraph frame.
+    assertXPath(pXmlDoc, "/root/page/body/txt[1]/LineBreak", 3);
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(SwLayoutWriter);
 CPPUNIT_PLUGIN_IMPLEMENT();
 
diff --git a/sw/source/core/text/inftxt.cxx b/sw/source/core/text/inftxt.cxx
index 74a046232bcd..da7f5ce7066a 100644
--- a/sw/source/core/text/inftxt.cxx
+++ b/sw/source/core/text/inftxt.cxx
@@ -1706,9 +1706,25 @@ SwTwips SwTextFormatInfo::GetLineWidth()
     if (pLastTab->GetTabPos() <= Width())
         return nLineWidth;
 
+    // Calculate the width that starts at the left (or in case of first line:
+    // first) margin, but ends after the right paragraph margin:
+    //
+    // +--------------------+
+    // |LL|              |RR|
+    // +--------------------+
+    // ^ m_nLeftMargin (absolute)
+    //    ^ nLeftMarginWidth (relative to m_nLeftMargin), X() is relative to this
+    //                   ^ right margin
+    //                      ^ paragraph right
+    // <--------------------> is GetTextFrame()->getFrameArea().Width()
+    //    <-------------->    is Width()
+    //    <-----------------> is what we need to be able to compare to X() (nTextFrameWidth)
+    SwTwips nLeftMarginWidth = m_nLeftMargin - GetTextFrame()->getFrameArea().Left();
+    SwTwips nTextFrameWidth = GetTextFrame()->getFrameArea().Width() - nLeftMarginWidth;
+
     // If there is one such tab portion, then text is allowed to use the full
-    // text frame area (even over the actual tab portion).
-    nLineWidth = GetTextFrame()->getFrameArea().Width() - X();
+    // text frame area to the right (RR above, but not LL).
+    nLineWidth = nTextFrameWidth - X();
 
     return nLineWidth;
 }
diff --git a/sw/source/core/text/inftxt.hxx b/sw/source/core/text/inftxt.hxx
index d7881834cadf..d7a826635dc0 100644
--- a/sw/source/core/text/inftxt.hxx
+++ b/sw/source/core/text/inftxt.hxx
@@ -488,6 +488,8 @@ class SwTextFormatInfo : public SwTextPaintInfo
     SwTwips m_nLeft;              // Left margin
     SwTwips m_nRight;             // Right margin
     SwTwips m_nFirst;             // EZE
+    /// First or left margin, depending on context.
+    SwTwips m_nLeftMargin = 0;
     sal_uInt16 m_nRealWidth;      // "real" line width
     sal_uInt16 m_nWidth;          // "virtual" line width
     sal_uInt16 m_nLineHeight;     // Final height after CalcLine
@@ -555,6 +557,7 @@ public:
     void Right( const SwTwips nNew ) { m_nRight = nNew; }
     SwTwips First() const { return m_nFirst; }
     void First( const SwTwips nNew ) { m_nFirst = nNew; }
+    void LeftMargin( const SwTwips nNew) { m_nLeftMargin = nNew; }
     sal_uInt16 RealWidth() const { return m_nRealWidth; }
     void RealWidth( const sal_uInt16 nNew ) { m_nRealWidth = nNew; }
     sal_uInt16 ForcedLeftMargin() const { return m_nForcedLeftMargin; }
diff --git a/sw/source/core/text/itrform2.cxx b/sw/source/core/text/itrform2.cxx
index 16d35e581131..28933fa55922 100644
--- a/sw/source/core/text/itrform2.cxx
+++ b/sw/source/core/text/itrform2.cxx
@@ -1847,6 +1847,7 @@ void SwTextFormatter::FeedInf( SwTextFormatInfo &rInf ) const
     rInf.Left( Left() );
     rInf.Right( Right() );
     rInf.First( FirstLeft() );
+    rInf.LeftMargin(GetLeftMargin());
 
     rInf.RealWidth( sal_uInt16(rInf.Right() - GetLeftMargin()) );
     rInf.Width( rInf.RealWidth() );


More information about the Libreoffice-commits mailing list