[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.0' - include/svtools sfx2/source svtools/source sw/CppunitTest_sw_unowriter.mk sw/qa sw/source

Miklos Vajna (via logerrit) logerrit at kemper.freedesktop.org
Wed Mar 27 20:39:50 UTC 2019


 include/svtools/DocumentToGraphicRenderer.hxx            |    2 
 sfx2/source/doc/objserv.cxx                              |    4 
 svtools/source/filter/DocumentToGraphicRenderer.cxx      |   13 +
 sw/CppunitTest_sw_unowriter.mk                           |   75 ++++++++
 sw/qa/extras/unowriter/data/renderable-page-position.odt |binary
 sw/qa/extras/unowriter/unowriter.cxx                     |  128 +++++++++++++++
 sw/source/uibase/uno/unotxdoc.cxx                        |    9 -
 7 files changed, 226 insertions(+), 5 deletions(-)

New commits:
commit 5ceee417fef834cd6b033603d72eaf4708970a1d
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Fri Jan 4 11:04:05 2019 +0100
Commit:     Andras Timar <andras.timar at collabora.com>
CommitDate: Wed Mar 27 21:39:20 2019 +0100

    svtools: expose document position in DocumentToGraphicRenderer
    
    Writer pages always have an offset inside the root frame, and this is
    visible in the generated metafile as well. The offset is minimal for a
    small window and a single page, but the vertical offset increases with
    every page. Make this information visible, so sfx2 can compensate this.
    
    This is somewhat similar to what SfxObjectShell::DoDraw_Impl() does, but
    that works for the first page only (use case is thumbnail generation),
    while this is 0 offset for Calc/Impress and a proper offset for all
    Writer pages.
    
    Change-Id: I1075c98faf74f9e77c916572b4d63d40fbd80ab1
    Reviewed-on: https://gerrit.libreoffice.org/65850
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
    Tested-by: Jenkins
    Reviewed-on: https://gerrit.libreoffice.org/69758
    Reviewed-by: Andras Timar <andras.timar at collabora.com>
    Tested-by: Andras Timar <andras.timar at collabora.com>

diff --git a/include/svtools/DocumentToGraphicRenderer.hxx b/include/svtools/DocumentToGraphicRenderer.hxx
index 5ed6f2ce4434..af0ce6e8086f 100644
--- a/include/svtools/DocumentToGraphicRenderer.hxx
+++ b/include/svtools/DocumentToGraphicRenderer.hxx
@@ -69,7 +69,7 @@ public:
 
     Size getDocumentSizeInPixels( sal_Int32 nCurrentPage );
 
-    Size getDocumentSizeIn100mm( sal_Int32 nCurrentPage );
+    Size getDocumentSizeIn100mm(sal_Int32 nCurrentPage, Point* pDocumentPosition = nullptr);
 
     Graphic renderToGraphic( sal_Int32 nCurrentPage, Size aDocumentSizePixel,
                             Size aTargetSizePixel, Color aPageColor);
diff --git a/sfx2/source/doc/objserv.cxx b/sfx2/source/doc/objserv.cxx
index 689dc36b42e7..4102bebe3435 100644
--- a/sfx2/source/doc/objserv.cxx
+++ b/sfx2/source/doc/objserv.cxx
@@ -549,7 +549,8 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq)
             sal_Int16 nPage = 1;
 
             ::Size aDocumentSizePixel = aRenderer.getDocumentSizeInPixels(nPage);
-            ::Size aLogic = aRenderer.getDocumentSizeIn100mm(nPage);
+            ::Point aLogicPos;
+            ::Size aLogic = aRenderer.getDocumentSizeIn100mm(nPage, &aLogicPos);
             // FIXME: This is a temporary hack. Need to figure out a proper way to derive this scale factor.
             ::Size aTargetSize(aDocumentSizePixel.Width() * 1.23, aDocumentSizePixel.Height() * 1.23);
 
@@ -560,6 +561,7 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq)
             // will be correct in MM.
             MapMode aMapMode;
             aMapMode.SetMapUnit(MapUnit::Map100thMM);
+            aMapMode.SetOrigin(::Point(-aLogicPos.getX(), -aLogicPos.getY()));
             rGDIMetaFile.SetPrefMapMode(aMapMode);
             rGDIMetaFile.SetPrefSize(aLogic);
 
diff --git a/svtools/source/filter/DocumentToGraphicRenderer.cxx b/svtools/source/filter/DocumentToGraphicRenderer.cxx
index 812fea51d701..00c27c7c0fd8 100644
--- a/svtools/source/filter/DocumentToGraphicRenderer.cxx
+++ b/svtools/source/filter/DocumentToGraphicRenderer.cxx
@@ -114,7 +114,8 @@ uno::Any DocumentToGraphicRenderer::getSelection() const
     return aSelection;
 }
 
-Size DocumentToGraphicRenderer::getDocumentSizeIn100mm(sal_Int32 nCurrentPage)
+Size DocumentToGraphicRenderer::getDocumentSizeIn100mm(sal_Int32 nCurrentPage,
+                                                       Point* pDocumentPosition)
 {
     Reference< awt::XDevice > xDevice(mxToolkit->createScreenCompatibleDevice( 32, 32 ) );
 
@@ -133,6 +134,7 @@ Size DocumentToGraphicRenderer::getDocumentSizeIn100mm(sal_Int32 nCurrentPage)
     renderProperties[3].Value <<= true;
 
     awt::Size aSize;
+    awt::Point aPos;
 
     sal_Int32 nPages = mxRenderable->getRendererCount( selection, renderProperties );
     if (nPages >= nCurrentPage)
@@ -144,9 +146,18 @@ Size DocumentToGraphicRenderer::getDocumentSizeIn100mm(sal_Int32 nCurrentPage)
             {
                 aResult[ nProperty ].Value >>= aSize;
             }
+            else if (aResult[nProperty].Name == "PagePos")
+            {
+                aResult[nProperty].Value >>= aPos;
+            }
         }
     }
 
+    if (pDocumentPosition)
+    {
+        *pDocumentPosition = Point(aPos.X, aPos.Y);
+    }
+
     return Size( aSize.Width, aSize.Height );
 }
 
diff --git a/sw/CppunitTest_sw_unowriter.mk b/sw/CppunitTest_sw_unowriter.mk
new file mode 100644
index 000000000000..32e7ff06a0d5
--- /dev/null
+++ b/sw/CppunitTest_sw_unowriter.mk
@@ -0,0 +1,75 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#*************************************************************************
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+#*************************************************************************
+
+$(eval $(call gb_CppunitTest_CppunitTest,sw_unowriter))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,sw_unowriter, \
+    sw/qa/extras/unowriter/unowriter \
+))
+
+# note: this links msword only for the reason to have a order dependency,
+# because "make sw.check" will not see the dependency through services.rdb
+$(eval $(call gb_CppunitTest_use_libraries,sw_unowriter, \
+    comphelper \
+    cppu \
+    cppuhelper \
+    editeng \
+    msword \
+    sal \
+    sfx \
+    svl \
+    svt \
+    svxcore \
+    sw \
+    test \
+    unotest \
+    vcl \
+    tl \
+    tk \
+    utl \
+))
+
+$(eval $(call gb_CppunitTest_use_externals,sw_unowriter,\
+    boost_headers \
+    libxml2 \
+))
+
+$(eval $(call gb_CppunitTest_set_include,sw_unowriter,\
+    -I$(SRCDIR)/sw/inc \
+    -I$(SRCDIR)/sw/source/core/inc \
+    -I$(SRCDIR)/sw/source/uibase/inc \
+    -I$(SRCDIR)/sw/qa/extras/inc \
+    $$(INCLUDE) \
+))
+
+$(eval $(call gb_CppunitTest_use_api,sw_unowriter,\
+	udkapi \
+	offapi \
+	oovbaapi \
+))
+
+$(eval $(call gb_CppunitTest_use_ure,sw_unowriter))
+$(eval $(call gb_CppunitTest_use_vcl,sw_unowriter))
+
+$(eval $(call gb_CppunitTest_use_rdb,sw_unowriter,services))
+
+$(eval $(call gb_CppunitTest_use_configuration,sw_unowriter))
+
+$(eval $(call gb_CppunitTest_use_uiconfigs,sw_unowriter, \
+    modules/swriter \
+))
+
+$(call gb_CppunitTest_get_target,sw_unowriter): \
+    $(call gb_Library_get_target,textconv_dict)
+
+$(eval $(call gb_CppunitTest_use_more_fonts,sw_unowriter))
+
+# vim: set noet sw=4 ts=4:
diff --git a/sw/qa/extras/unowriter/data/renderable-page-position.odt b/sw/qa/extras/unowriter/data/renderable-page-position.odt
new file mode 100644
index 000000000000..3baddaf21f03
Binary files /dev/null and b/sw/qa/extras/unowriter/data/renderable-page-position.odt differ
diff --git a/sw/qa/extras/unowriter/unowriter.cxx b/sw/qa/extras/unowriter/unowriter.cxx
new file mode 100644
index 000000000000..3fefa93f4d87
--- /dev/null
+++ b/sw/qa/extras/unowriter/unowriter.cxx
@@ -0,0 +1,128 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <swmodeltestbase.hxx>
+#include <com/sun/star/awt/FontSlant.hpp>
+#include <com/sun/star/text/TextContentAnchorType.hpp>
+#include <com/sun/star/text/AutoTextContainer.hpp>
+#include <com/sun/star/text/XAutoTextGroup.hpp>
+#include <com/sun/star/rdf/URI.hpp>
+#include <com/sun/star/rdf/URIs.hpp>
+#include <com/sun/star/awt/XDevice.hpp>
+#include <com/sun/star/awt/XToolkit.hpp>
+#include <comphelper/propertyvalue.hxx>
+#include <toolkit/helper/vclunohelper.hxx>
+#include <wrtsh.hxx>
+#include <ndtxt.hxx>
+
+using namespace ::com::sun::star;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::text;
+
+namespace
+{
+char const DATA_DIRECTORY[] = "/sw/qa/extras/unowriter/data/";
+}
+
+/// Test to assert UNO API call results of Writer.
+class SwUnoWriter : public SwModelTestBase
+{
+public:
+    SwUnoWriter()
+        : SwModelTestBase(DATA_DIRECTORY, "writer8")
+    {
+    }
+};
+
+/**
+ * Macro to declare a new test with preloaded file
+ * (similar to DECLARE_SW_ROUNDTRIP_TEST)
+ */
+#define DECLARE_UNOAPI_TEST_FILE(TestName, filename)                                               \
+    class TestName : public SwUnoWriter                                                            \
+    {                                                                                              \
+    protected:                                                                                     \
+        virtual OUString getTestName() override { return OUString(#TestName); }                    \
+                                                                                                   \
+    public:                                                                                        \
+        CPPUNIT_TEST_SUITE(TestName);                                                              \
+        CPPUNIT_TEST(loadAndTest);                                                                 \
+        CPPUNIT_TEST_SUITE_END();                                                                  \
+        void loadAndTest()                                                                         \
+        {                                                                                          \
+            load(mpTestDocumentPath, filename);                                                    \
+            runTest();                                                                             \
+        }                                                                                          \
+        void runTest();                                                                            \
+    };                                                                                             \
+    CPPUNIT_TEST_SUITE_REGISTRATION(TestName);                                                     \
+    void TestName::runTest()
+
+/**
+ * Macro to declare a new test without loading any files
+ */
+#define DECLARE_UNOAPI_TEST(TestName)                                                              \
+    class TestName : public SwUnoWriter                                                            \
+    {                                                                                              \
+    protected:                                                                                     \
+        virtual OUString getTestName() override { return OUString(#TestName); }                    \
+                                                                                                   \
+    public:                                                                                        \
+        CPPUNIT_TEST_SUITE(TestName);                                                              \
+        CPPUNIT_TEST(runTest);                                                                     \
+        CPPUNIT_TEST_SUITE_END();                                                                  \
+        void runTest();                                                                            \
+    };                                                                                             \
+    CPPUNIT_TEST_SUITE_REGISTRATION(TestName);                                                     \
+    void TestName::runTest()
+
+DECLARE_UNOAPI_TEST_FILE(testRenderablePagePosition, "renderable-page-position.odt")
+{
+    // Make sure that the document has 2 pages.
+    uno::Reference<view::XRenderable> xRenderable(mxComponent, uno::UNO_QUERY);
+    CPPUNIT_ASSERT(mxComponent.is());
+
+    uno::Any aSelection = uno::makeAny(mxComponent);
+
+    uno::Reference<awt::XToolkit> xToolkit = VCLUnoHelper::CreateToolkit();
+    uno::Reference<awt::XDevice> xDevice(xToolkit->createScreenCompatibleDevice(32, 32));
+
+    uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
+    uno::Reference<frame::XController> xController = xModel->getCurrentController();
+
+    beans::PropertyValues aRenderOptions = {
+        comphelper::makePropertyValue("IsPrinter", true),
+        comphelper::makePropertyValue("RenderDevice", xDevice),
+        comphelper::makePropertyValue("View", xController),
+        comphelper::makePropertyValue("RenderToGraphic", true),
+    };
+
+    sal_Int32 nPages = xRenderable->getRendererCount(aSelection, aRenderOptions);
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), nPages);
+
+    // Make sure that the first page has some offset.
+    comphelper::SequenceAsHashMap aRenderer1(
+        xRenderable->getRenderer(0, aSelection, aRenderOptions));
+    // Without the accompanying fix in place, this test would have failed: i.e.
+    // there was no PagePos key in this map.
+    awt::Point aPosition1 = aRenderer1["PagePos"].get<awt::Point>();
+    CPPUNIT_ASSERT_GREATER(static_cast<sal_Int32>(0), aPosition1.X);
+    CPPUNIT_ASSERT_GREATER(static_cast<sal_Int32>(0), aPosition1.Y);
+
+    // Make sure that the second page is below the first one.
+    comphelper::SequenceAsHashMap aRenderer2(
+        xRenderable->getRenderer(1, aSelection, aRenderOptions));
+    awt::Point aPosition2 = aRenderer2["PagePos"].get<awt::Point>();
+    CPPUNIT_ASSERT_GREATER(static_cast<sal_Int32>(0), aPosition2.X);
+    CPPUNIT_ASSERT_GREATER(aPosition1.Y, aPosition2.Y);
+}
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx
index d58c8ac5e1dc..33a84e3dbaed 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -2763,6 +2763,7 @@ uno::Sequence< beans::PropertyValue > SAL_CALL SwXTextDocument::getRenderer(
         }
 
         awt::Size aPageSize;
+        awt::Point aPagePos;
         awt::Size aPreferredPageSize;
         Size aTmpSize;
         if (bIsSwSrcView || bPrintProspect)
@@ -2819,14 +2820,18 @@ uno::Sequence< beans::PropertyValue > SAL_CALL SwXTextDocument::getRenderer(
             aTmpSize = pVwSh->GetPageSize( nPage, bIsSkipEmptyPages );
             aPageSize = awt::Size ( convertTwipToMm100( aTmpSize.Width() ),
                                     convertTwipToMm100( aTmpSize.Height() ));
+            Point aPoint = pVwSh->GetPagePos(nPage);
+            aPagePos = awt::Point(convertTwipToMm100(aPoint.X()), convertTwipToMm100(aPoint.Y()));
         }
 
-        sal_Int32 nLen = 2;
-        aRenderer.realloc(2);
+        sal_Int32 nLen = 3;
+        aRenderer.realloc(3);
         aRenderer[0].Name  = "PageSize";
         aRenderer[0].Value <<= aPageSize;
         aRenderer[1].Name  = "PageIncludesNonprintableArea";
         aRenderer[1].Value <<= true;
+        aRenderer[2].Name = "PagePos";
+        aRenderer[2].Value <<= aPagePos;
         if (aPreferredPageSize.Width && aPreferredPageSize.Height)
         {
             ++nLen;


More information about the Libreoffice-commits mailing list