Kaydet (Commit) ba602040 authored tarafından Miklos Vajna's avatar Miklos Vajna

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/65850Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
üst 9ec128f8
......@@ -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);
......
......@@ -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);
......
......@@ -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 );
}
......
......@@ -33,6 +33,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sw_unowriter, \
unotest \
vcl \
tl \
tk \
utl \
))
......
......@@ -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: */
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment