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

Miklos Vajna (via logerrit) logerrit at kemper.freedesktop.org
Wed Aug 7 17:59:23 UTC 2019


 sw/qa/extras/unowriter/data/view-cursor-page-style.fodt |   23 ++++++++++++
 sw/qa/extras/unowriter/unowriter.cxx                    |   29 ++++++++++++++++
 sw/source/core/unocore/unocrsrhelper.cxx                |    5 ++
 3 files changed, 56 insertions(+), 1 deletion(-)

New commits:
commit 9a66b452ede70a25cd6fc8a72772a71b0ee7957a
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Wed Aug 7 17:43:50 2019 +0200
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Wed Aug 7 19:58:38 2019 +0200

    sw: fix ViewCursor.PageStyleName for multi-page paragraphs
    
    In case the text frames of a text node span over multiple pages and the
    first page has a page style which has a follow page style, the page
    style under the cursor depends on not only the text node index, but also
    on the context index.
    
    Without this, the page style under the cursor will expose the first
    page's style name via the API, even if it's already on a follow page.
    
    Change-Id: I922e153750755317bda87441a88e9f53a6f348b7
    Reviewed-on: https://gerrit.libreoffice.org/77128
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
    Tested-by: Jenkins

diff --git a/sw/qa/extras/unowriter/data/view-cursor-page-style.fodt b/sw/qa/extras/unowriter/data/view-cursor-page-style.fodt
new file mode 100644
index 000000000000..c386e72c949e
--- /dev/null
+++ b/sw/qa/extras/unowriter/data/view-cursor-page-style.fodt
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<office:document xmlns:grddl="http://www.w3.org/2003/g/data-view#" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:css3t="http://www.w3.org/TR/css3-text/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:formx="urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0" xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" xmlns:tableooo="http://openoffice.org/2009/table" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.
 0" xmlns:calcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ooo="http://openoffice.org/2004/office" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:officeooo="http://openoffice.org/2009/office" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:drawooo="http://openoffice.org/2010/draw" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d: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:rpt="http://op
 enoffice.org/2005/report" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" office:version="1.2" office:mimetype="application/vnd.oasis.opendocument.text">
+  <office:styles>
+    <style:default-style style:family="paragraph"/>
+    <style:style style:name="Standard" style:family="paragraph" style:class="text"/>
+  </office:styles>
+  <office:automatic-styles>
+    <style:style style:name="P1" style:family="paragraph" style:parent-style-name="Standard" style:master-page-name="First_20_Page"/>
+    <style:page-layout style:name="pm1">
+      <style:page-layout-properties fo:page-width="21.001cm" fo:page-height="9.7cm" style:print-orientation="landscape" fo:margin-top="2cm" fo:margin-bottom="2cm" fo:margin-left="2cm" fo:margin-right="2cm">
+      </style:page-layout-properties>
+    </style:page-layout>
+  </office:automatic-styles>
+  <office:master-styles>
+    <style:master-page style:name="Standard" style:page-layout-name="pm1"/>
+    <style:master-page style:name="First_20_Page" style:display-name="First Page" style:page-layout-name="pm1" style:next-style-name="Standard"/>
+  </office:master-styles>
+  <office:body>
+    <office:text>
+      <text:p text:style-name="P1">01<text:line-break/>02<text:line-break/>03<text:line-break/>04<text:line-break/>05<text:line-break/>06<text:line-break/>07<text:line-break/>08<text:line-break/>09<text:line-break/>10<text:line-break/>11<text:line-break/>12<text:line-break/>13<text:line-break/>14<text:line-break/>15<text:line-break/>16</text:p>
+    </office:text>
+  </office:body>
+</office:document>
diff --git a/sw/qa/extras/unowriter/unowriter.cxx b/sw/qa/extras/unowriter/unowriter.cxx
index f27d40e19839..568ee8d19d75 100644
--- a/sw/qa/extras/unowriter/unowriter.cxx
+++ b/sw/qa/extras/unowriter/unowriter.cxx
@@ -592,6 +592,35 @@ CPPUNIT_TEST_FIXTURE(SwUnoWriter, testImageCommentAtChar)
     }
 }
 
+CPPUNIT_TEST_FIXTURE(SwUnoWriter, testViewCursorPageStyle)
+{
+    // Load a document with 2 pages, but a single paragraph.
+    load(mpTestDocumentPath, "view-cursor-page-style.fodt");
+    uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
+    CPPUNIT_ASSERT(xModel.is());
+    uno::Reference<text::XTextViewCursorSupplier> xController(xModel->getCurrentController(),
+                                                              uno::UNO_QUERY);
+    CPPUNIT_ASSERT(xController.is());
+    uno::Reference<text::XPageCursor> xViewCursor(xController->getViewCursor(), uno::UNO_QUERY);
+    CPPUNIT_ASSERT(xViewCursor.is());
+
+    // Go to the first page, which has an explicit page style.
+    xViewCursor->jumpToPage(1);
+    OUString aActualPageStyleName = getProperty<OUString>(xViewCursor, "PageStyleName");
+    CPPUNIT_ASSERT_EQUAL(OUString("First Page"), aActualPageStyleName);
+
+    // Go to the second page, which is still the first paragraph, but the page style is different,
+    // as the explicit 'First Page' page style has a next style defined (Standard).
+    xViewCursor->jumpToPage(2);
+    aActualPageStyleName = getProperty<OUString>(xViewCursor, "PageStyleName");
+    // Without the accompanying fix in place, this test would have failed with:
+    // - Expected: Standard
+    // - Actual  : First Page
+    // i.e. the cursor position was determined only based on the node index, ignoring the content
+    // index.
+    CPPUNIT_ASSERT_EQUAL(OUString("Standard"), aActualPageStyleName);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/unocore/unocrsrhelper.cxx b/sw/source/core/unocore/unocrsrhelper.cxx
index 473151dc3b4e..d18d9593852e 100644
--- a/sw/source/core/unocore/unocrsrhelper.cxx
+++ b/sw/source/core/unocore/unocrsrhelper.cxx
@@ -918,7 +918,10 @@ void GetCurPageStyle(SwPaM const & rPaM, OUString &rString)
 {
     if (!rPaM.GetContentNode())
         return; // TODO: is there an easy way to get it for tables/sections?
-    SwContentFrame* pFrame = rPaM.GetContentNode()->getLayoutFrame(rPaM.GetDoc()->getIDocumentLayoutAccess().GetCurrentLayout());
+    SwRootFrame* pLayout = rPaM.GetDoc()->getIDocumentLayoutAccess().GetCurrentLayout();
+    // Consider the position inside the content node, since the node may span over multiple pages
+    // with different page styles.
+    SwContentFrame* pFrame = rPaM.GetContentNode()->getLayoutFrame(pLayout, rPaM.GetPoint());
     if(pFrame)
     {
         const SwPageFrame* pPage = pFrame->FindPageFrame();


More information about the Libreoffice-commits mailing list