summaryrefslogtreecommitdiff
path: root/sw
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
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')
-rw-r--r--sw/CppunitTest_sw_unowriter.mk1
-rw-r--r--sw/qa/extras/unowriter/data/renderable-page-position.odtbin0 -> 8465 bytes
-rw-r--r--sw/qa/extras/unowriter/unowriter.cxx45
-rw-r--r--sw/source/uibase/uno/unotxdoc.cxx9
4 files changed, 53 insertions, 2 deletions
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
--- /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: */
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;