[Libreoffice-commits] core.git: include/svtools sfx2/source svtools/source sw/CppunitTest_sw_unowriter.mk sw/qa sw/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Fri Jan 4 10:58:42 UTC 2019


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

New commits:
commit ba60204055823bce27a51078d7170e0ff9836636
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Fri Jan 4 11:04:05 2019 +0100
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Fri Jan 4 11:58:19 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

diff --git a/include/svtools/DocumentToGraphicRenderer.hxx b/include/svtools/DocumentToGraphicRenderer.hxx
index d6c322b12601..5d153a2f5c71 100644
--- a/include/svtools/DocumentToGraphicRenderer.hxx
+++ b/include/svtools/DocumentToGraphicRenderer.hxx
@@ -76,7 +76,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, bool bExtOutDevData);
diff --git a/sfx2/source/doc/objserv.cxx b/sfx2/source/doc/objserv.cxx
index 9682c1b3b8cc..0b1a879e7678 100644
--- a/sfx2/source/doc/objserv.cxx
+++ b/sfx2/source/doc/objserv.cxx
@@ -555,7 +555,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);
 
@@ -567,6 +568,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 3dbfcdd5889e..ec4b15966dda 100644
--- a/svtools/source/filter/DocumentToGraphicRenderer.cxx
+++ b/svtools/source/filter/DocumentToGraphicRenderer.cxx
@@ -115,7 +115,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 ) );
 
@@ -134,6 +135,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)
@@ -145,9 +147,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
index 726e364f4238..32e7ff06a0d5 100644
--- a/sw/CppunitTest_sw_unowriter.mk
+++ b/sw/CppunitTest_sw_unowriter.mk
@@ -33,6 +33,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sw_unowriter, \
     unotest \
     vcl \
     tl \
+    tk \
     utl \
 ))
 
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
index 8cba987a7c63..a0e093dc35d5 100644
--- a/sw/qa/extras/unowriter/unowriter.cxx
+++ b/sw/qa/extras/unowriter/unowriter.cxx
@@ -14,6 +14,10 @@
 #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>
 
@@ -418,6 +422,47 @@ DECLARE_UNOAPI_TEST_FILE(testSelectionInTableEnumEnd, "selection-in-table-enum.o
     CPPUNIT_ASSERT(!xEnum->hasMoreElements());
 }
 
+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 b4d47d5e5640..83c78d2988f4 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -2802,6 +2802,7 @@ uno::Sequence< beans::PropertyValue > SAL_CALL SwXTextDocument::getRenderer(
         }
 
         awt::Size aPageSize;
+        awt::Point aPagePos;
         awt::Size aPreferredPageSize;
         Size aTmpSize;
         if (bIsSwSrcView || bPrintProspect)
@@ -2858,14 +2859,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