[Libreoffice-commits] core.git: Branch 'libreoffice-7-1' - 2 commits - sw/qa sw/source

Attila Bakos (NISZ) (via logerrit) logerrit at kemper.freedesktop.org
Fri Jan 15 09:03:58 UTC 2021


 sw/qa/core/layout/data/keepwithnext-fullheight.fodt |   42 ++++++++++++++
 sw/qa/core/layout/layout.cxx                        |   18 ++++++
 sw/qa/extras/ooxmlexport/data/tdf138739.docx        |binary
 sw/qa/extras/ooxmlexport/ooxmlexport15.cxx          |    7 ++
 sw/source/core/doc/textboxhelper.cxx                |    7 --
 sw/source/core/layout/flowfrm.cxx                   |   58 +++++++++++++++++++-
 6 files changed, 125 insertions(+), 7 deletions(-)

New commits:
commit 1d1bd898e21bd56fff467b785d7c2c801064ed83
Author:     Attila Bakos (NISZ) <bakos.attilakaroly at nisz.hu>
AuthorDate: Tue Dec 22 15:20:23 2020 +0100
Commit:     Xisco Fauli <xiscofauli at libreoffice.org>
CommitDate: Fri Jan 15 10:03:34 2021 +0100

    tdf#138739 sw: fix regression of first paragraph
    
    First paragraph of the document lost its formatting
    from commit 056933bc55608d0ca061539ae124d7b9386cdb62.
    (tdf#137802 sw: fix crash on deleting last paragraph).
    
    This reverts commit 056933bc55608d0ca061539ae124d7b9386cdb62.
    
    Note: last take went wrong so this is a follow up for
    commit 25ca25ee25278536c56a2ac4a63af91100ce4d2e
    (tdf#138739 sw: fix regression of first paragraph).
    Hopefuly it will be fine.
    
    Change-Id: Id8a19c47f172b25cd5559f5823f19b3faf38cfd2
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108196
    Tested-by: László Németh <nemeth at numbertext.org>
    Reviewed-by: László Németh <nemeth at numbertext.org>
    (cherry picked from commit 7957123a144bfe66a99aa0d30a47900b6b621a70)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109010
    Tested-by: Jenkins
    Reviewed-by: Xisco Fauli <xiscofauli at libreoffice.org>

diff --git a/sw/qa/extras/ooxmlexport/data/tdf138739.docx b/sw/qa/extras/ooxmlexport/data/tdf138739.docx
new file mode 100755
index 000000000000..7b5bb302bfa1
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf138739.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx
index 7dd4feae324a..c875d560e592 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx
@@ -240,6 +240,13 @@ DECLARE_OOXMLEXPORT_TEST(testTdf136404, "tdf136404.fodt")
     CPPUNIT_ASSERT_EQUAL(OUString("8"), xEnumerationAccess7->getPresentation(false).trim());
 }
 
+DECLARE_OOXMLEXPORT_TEST(testTdf138739, "tdf138739.docx")
+{
+    uno::Reference<beans::XPropertySet> xParaProps(getParagraph(1), uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("Font type name does not match!", OUString("Comic Sans MS"),
+                                 xParaProps->getPropertyValue("CharFontName").get<OUString>());
+}
+
 DECLARE_OOXMLEXPORT_TEST(testTdf123390, "tdf123390.fodt")
 {
     uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY);
diff --git a/sw/source/core/doc/textboxhelper.cxx b/sw/source/core/doc/textboxhelper.cxx
index 5457b8b5d317..4d44d1c35ff8 100644
--- a/sw/source/core/doc/textboxhelper.cxx
+++ b/sw/source/core/doc/textboxhelper.cxx
@@ -92,12 +92,7 @@ void SwTextBoxHelper::create(SwFrameFormat* pShape, bool bCopyText)
     }
     catch (uno::Exception&)
     {
-        // Before the textframe was appended now it is inserted to the begin of the doc in order
-        // to prevent crash when someone removes the para where the textframe anchored:
-        uno::Reference<text::XTextCursor> xCursor = xTextDocument->getText()->createTextCursor();
-        xCursor->gotoStart(false);
-        xTextContentAppend->insertTextContentWithProperties(
-            xTextFrame, uno::Sequence<beans::PropertyValue>(), xCursor->getStart());
+        xTextContentAppend->appendTextContent(xTextFrame, uno::Sequence<beans::PropertyValue>());
     }
     // Link FLY and DRAW formats, so it becomes a text box (needed for syncProperty calls).
     uno::Reference<text::XTextFrame> xRealTextFrame(xTextFrame, uno::UNO_QUERY);
commit a5c68eaa1ef94653bc2f62a55ec6fed68de61c78
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Mon Dec 21 17:55:02 2020 +0100
Commit:     Xisco Fauli <xiscofauli at libreoffice.org>
CommitDate: Fri Jan 15 10:03:24 2021 +0100

    sw: fix layout loop due to a keep-with-next vs 100% image height conflict
    
    The document in question has a landscape page, the last paragraph has an
    image where the width is 100% and the height is set to keep the ratio
    (which 1:1). This means that SwFlyFreeFrame::CheckClip() will scale the
    image down, so the image fits the page (and give up that 100% width was
    requested).
    
    The next problem is that this image has a wrap type set to none, so not
    only the total height of the page is taken, but also no content is
    allowed on the left/right side, effectively taking the entire body
    frame. Combine this with a previous paragraph, which is a heading, so
    keep-with-next is set for it. Layout loops because keep-with-next and
    take-the-entire-page are conflicting requirements and we used to have no
    explicit code to relax one of them when both are present:
    
    SwFlowFrame::MoveBwd: frame is 4, old upper is 10, new upper is 2
    SwFlowFrame::MoveFwd: frame is 4, old upper is 2, new upper is 10
    SwFlowFrame::MoveBwd: frame is 4, old upper is 10, new upper is 2
    SwFlowFrame::MoveFwd: frame is 4, old upper is 2, new upper is 10
    SwFlowFrame::MoveBwd: loop control, frame is 4, old upper is 10, new upper would be 2, but not moving there
    
    Fix the problem by giving up keep-with-next to stop the loop, mostly
    because we have to give up one of the requirements and Word resolves the
    conflict this way.
    
    Change-Id: I7da1ebcff9302cd144887f63efb94e0b2b2be8fd
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108119
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
    Tested-by: Jenkins
    (cherry picked from commit 160db4bf0fc391b2ded635d0bd998d5352541742)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108011
    Reviewed-by: Xisco Fauli <xiscofauli at libreoffice.org>

diff --git a/sw/qa/core/layout/data/keepwithnext-fullheight.fodt b/sw/qa/core/layout/data/keepwithnext-fullheight.fodt
new file mode 100644
index 000000000000..b33dd80e719e
--- /dev/null
+++ b/sw/qa/core/layout/data/keepwithnext-fullheight.fodt
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<office:document xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" office:mimetype="application/vnd.oasis.opendocument.text" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0">
+  <office:styles>
+    <style:style style:name="OLE" style:family="graphic">
+      <style:graphic-properties text:anchor-type="paragraph" svg:x="0cm" svg:y="0cm" style:wrap="none" style:horizontal-pos="center" style:horizontal-rel="paragraph" style:flow-with-text="false"/>
+    </style:style>
+  </office:styles>
+  <office:automatic-styles>
+    <style:style style:name="P1" style:family="paragraph" style:master-page-name="Landscape"/>
+    <style:style style:name="fr1" style:family="graphic" style:parent-style-name="OLE">
+      <style:graphic-properties style:vertical-pos="top" style:vertical-rel="paragraph" draw:ole-draw-aspect="1"/>
+    </style:style>
+    <style:page-layout style:name="pm1">
+      <style:page-layout-properties fo:page-width="82.652cm" fo:page-height="57.683cm" style:num-format="1" style:print-orientation="landscape" fo:margin-top="2cm" fo:margin-bottom="2cm" fo:margin-left="2cm" fo:margin-right="2cm" style:writing-mode="lr-tb" style:layout-grid-color="#c0c0c0" style:layout-grid-lines="20" style:layout-grid-base-height="0.706cm" style:layout-grid-ruby-height="0.353cm" style:layout-grid-mode="none" style:layout-grid-ruby-below="false" style:layout-grid-print="false" style:layout-grid-display="false" style:footnote-max-height="0cm"/>
+    </style:page-layout>
+  </office:automatic-styles>
+  <office:master-styles>
+    <style:master-page style:name="Landscape" style:page-layout-name="pm1"/>
+  </office:master-styles>
+  <office:body>
+    <office:text>
+      <text:p text:style-name="P1">Landscape page</text:p>
+      <text:h>Heading</text:h>
+      <text:p><draw:frame draw:style-name="fr1" draw:name="Image1" text:anchor-type="paragraph" svg:width="58.644cm" style:rel-width="100%" svg:height="57.683cm" style:rel-height="scale" draw:z-index="0"><draw:image draw:mime-type="image/png"><office:binary-data>iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAQAAAAAYLlVAAAABGdBTUEAALGPC/xhBQAAAAFz
+       UkdCAK7OHOkAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAA
+       AAJiS0dEAACqjSMyAAAACW9GRnMAAAAGAAAAAAAMc1XTAAAACXBIWXMAAA3XAAAN1wFCKJt4
+       AAAACXZwQWcAAABMAAAAQACdMTgbAAABzUlEQVRo3u3ZPU/CQBjA8X+Jxs3ESUDj4iK+LA5+
+       BBfjqBE1cXB2MlFAEqMgxvhNNL4sLsK3UPQL6ObkoAETz+FKW2mxCPRYnucWUu76/OC59C49
+       cGOCKqrD9kHRc6ddPv7oW2WCwMh0nF63Myz7Tm8hPTNu0pgHMER3scepTbgK6enJNND83RLn
+       /878yRaPmgBZFDuMsNLeWB9gmFQHP77MIg9gsYciR50NFKvtjIy10yk84pSZA7DYpwR8scmF
+       QQCMuoQMpzbh0iAARrlnVn90CWHTsZcAiHPPdINQAuqsc2MQAAnKDUKWEhZ10twaBEDSJWQo
+       YlFj7S9CzwEegkXWIbQsRAQASFJhpplwbRAACS+hANRJBxMiAkDcJeQ4sQkBhYgMoJ+Ozlwo
+       2YQ7AJ6CRxyiUGnVy3hVKb0Af9v7hUG2Wy9TEQCUelFTDULB2S+YKYGOMcpM6UIccOQnRA6A
+       cSp6ibfI+wkGADBGpTEd8xz1AaAfTQ7huA8AvUw5hVjuA0D/C5OaMN8XACRZ8F0zCggKAQhA
+       AAIQgAAEIAABCEAAAhCAAAQgAAH4zg3feY4w3Xs44M5+oW0qvCWoGcvaIlM3x/f/ab+O738A
+       hOCNQr34oD4AAAAldEVYdGNyZWF0ZS1kYXRlADIwMTAtMTItMjBUMTc6MDg6MzYrMDE6MDB6
+       5RscAAAAJXRFWHRtb2RpZnktZGF0ZQAyMDEwLTEyLTIwVDE3OjA4OjM3KzAxOjAwgyNmnAAA
+       AABJRU5ErkJggg==
+      </office:binary-data></draw:image></draw:frame></text:p>
+    </office:text>
+  </office:body>
+</office:document>
diff --git a/sw/qa/core/layout/layout.cxx b/sw/qa/core/layout/layout.cxx
index 76445faa4cfe..e9f1d22bd70b 100644
--- a/sw/qa/core/layout/layout.cxx
+++ b/sw/qa/core/layout/layout.cxx
@@ -242,6 +242,24 @@ CPPUNIT_TEST_FIXTURE(SwCoreLayoutTest, testBtlrNestedCell)
     CPPUNIT_ASSERT_GREATEREQUAL(nFrameBottom, aPaintArea.Bottom());
 }
 
+CPPUNIT_TEST_FIXTURE(SwCoreLayoutTest, testKeepwithnextFullheight)
+{
+    // The document has a heading (keep with next) and a full-page image in the next paragraph, i.e.
+    // conflicting requirements.
+    // Without the accompanying fix in place, this test would have failed with a layout loop in
+    // SwEditShell::CalcLayout().
+    load(DATA_DIRECTORY, "keepwithnext-fullheight.fodt");
+
+    xmlDocUniquePtr pXmlDoc = parseLayoutDump();
+    CPPUNIT_ASSERT(pXmlDoc);
+    // Make sure the document has 2 pages.
+    assertXPath(pXmlDoc, "//page", 2);
+    // Heading stays on page 1 to avoid a layout loop.
+    assertXPathContent(pXmlDoc, "//page[1]/body/txt[2]", "Heading");
+    // Image stays on page 2.
+    assertXPath(pXmlDoc, "//page[2]/body/txt/anchored/fly", 1);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/layout/flowfrm.cxx b/sw/source/core/layout/flowfrm.cxx
index 7b91a1bc74cc..aeeb9df158cf 100644
--- a/sw/source/core/layout/flowfrm.cxx
+++ b/sw/source/core/layout/flowfrm.cxx
@@ -176,6 +176,61 @@ void SwFlowFrame::CheckKeep()
         pPre->InvalidatePos();
 }
 
+namespace
+{
+/**
+ * Determines if the next content frame after rThis will require the full area of the parent body
+ * frame.
+ */
+bool IsNextContentFullPage(const SwFrame& rThis)
+{
+    const SwFrame* pNext = rThis.FindNextCnt();
+    if (!pNext)
+    {
+        return false;
+    }
+
+    const SwSortedObjs* pNextDrawObjs = pNext->GetDrawObjs();
+    if (!pNextDrawObjs || !pNextDrawObjs->size())
+    {
+        return false;
+    }
+
+    for (const auto& pDrawObj : *pNextDrawObjs)
+    {
+        if (!pDrawObj)
+        {
+            continue;
+        }
+
+        SwTwips nDrawObjHeight = pDrawObj->GetObjRectWithSpaces().Height();
+        const SwPageFrame* pPageFrame = pDrawObj->GetPageFrame();
+        if (!pPageFrame)
+        {
+            continue;
+        }
+
+        SwTwips nBodyHeight = pPageFrame->GetLower()->getFrameArea().Height();
+        if (nDrawObjHeight < nBodyHeight)
+        {
+            continue;
+        }
+
+        const SwFormatSurround& rSurround = pDrawObj->GetFrameFormat().GetSurround();
+        if (rSurround.GetSurround() != text::WrapTextMode_NONE)
+        {
+            continue;
+        }
+
+        // At this point the height of the draw object will use all the vertical available space,
+        // and also no wrapping will be performed, so all horizontal space will be taken as well.
+        return true;
+    }
+
+    return false;
+}
+}
+
 bool SwFlowFrame::IsKeep(SvxFormatKeepItem const& rKeep,
         SvxFormatBreakItem const& rBreak,
         bool const bCheckIfLastRowShouldKeep) const
@@ -186,10 +241,11 @@ bool SwFlowFrame::IsKeep(SvxFormatKeepItem const& rKeep,
     // 3. If bBreakCheck is set to true, this function only checks
     //    if there are any break after attributes set at rAttrs
     //    or break before attributes set for the next content (or next table)
+    // 4. Keep is ignored if the next frame will require its own page.
     bool bKeep = bCheckIfLastRowShouldKeep ||
                  (  !m_rThis.IsInFootnote() &&
                     ( !m_rThis.IsInTab() || m_rThis.IsTabFrame() ) &&
-                    rKeep.GetValue() );
+                    rKeep.GetValue() && !IsNextContentFullPage(m_rThis));
 
     OSL_ENSURE( !bCheckIfLastRowShouldKeep || m_rThis.IsTabFrame(),
             "IsKeep with bCheckIfLastRowShouldKeep should only be used for tabfrms" );


More information about the Libreoffice-commits mailing list