[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.2' - include/svtools sfx2/source svtools/source sw/CppunitTest_sw_unowriter.mk sw/qa sw/source
Miklos Vajna (via logerrit)
logerrit at kemper.freedesktop.org
Mon Jun 17 17:26:10 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 | 47 +++++++++++++++
sw/source/uibase/uno/unotxdoc.cxx | 9 ++
7 files changed, 71 insertions(+), 5 deletions(-)
New commits:
commit ff7de7476e0492cbfcc43c076fc2a24370dcb0ac
Author: Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Fri Jan 4 11:04:05 2019 +0100
Commit: Muhammet Kara <muhammet.kara at collabora.com>
CommitDate: Mon Jun 17 19:25:26 2019 +0200
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/74188
Reviewed-by: Muhammet Kara <muhammet.kara at collabora.com>
Tested-by: Muhammet Kara <muhammet.kara at collabora.com>
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 f2ca4cbdebcc..24432b3daab0 100644
--- a/sfx2/source/doc/objserv.cxx
+++ b/sfx2/source/doc/objserv.cxx
@@ -562,7 +562,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);
@@ -573,6 +574,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 1c11438473ea..771ca36152b0 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
index b4b27bd402a4..b17e61d55042 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 933e17b928bb..3bdd466073d7 100644
--- a/sw/qa/extras/unowriter/unowriter.cxx
+++ b/sw/qa/extras/unowriter/unowriter.cxx
@@ -15,6 +15,12 @@
#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 <ndtxt.hxx>
+
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::text;
@@ -320,6 +326,47 @@ DECLARE_UNOAPI_TEST(testXURI)
lang::IllegalArgumentException);
}
+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 f8b476133672..10720bf3b334 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -2768,6 +2768,7 @@ uno::Sequence< beans::PropertyValue > SAL_CALL SwXTextDocument::getRenderer(
}
awt::Size aPageSize;
+ awt::Point aPagePos;
awt::Size aPreferredPageSize;
Size aTmpSize;
if (bIsSwSrcView || bPrintProspect)
@@ -2824,14 +2825,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