summaryrefslogtreecommitdiff
path: root/sw/qa/extras/unowriter
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2019-01-04 11:04:05 +0100
committerMiklos Vajna <vmiklos@collabora.com>2019-01-04 11:58:19 +0100
commitba60204055823bce27a51078d7170e0ff9836636 (patch)
tree172fa028845f91908c3f3bcef852ff603098bbee /sw/qa/extras/unowriter
parent9ec128f8377182c0c50a4c5e6f21cd9b061ef016 (diff)
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@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'sw/qa/extras/unowriter')
-rw-r--r--sw/qa/extras/unowriter/data/renderable-page-position.odtbin0 -> 8465 bytes
-rw-r--r--sw/qa/extras/unowriter/unowriter.cxx45
2 files changed, 45 insertions, 0 deletions
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
--- /dev/null
+++ b/sw/qa/extras/unowriter/data/renderable-page-position.odt
Binary files 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: */