From 878e8fe7ffeada3d6154fe4750079deb38e1ce94 Mon Sep 17 00:00:00 2001 From: Szymon Kłos Date: Tue, 26 Jan 2021 16:35:10 +0100 Subject: fontwork: insert in the center of LOK view MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Iabde4ee927546b0e396c4fbd6d0099fa82240166 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109968 Tested-by: Jenkins CollaboraOffice Reviewed-by: Jan Holesovsky Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112163 Tested-by: Jenkins Reviewed-by: Szymon Kłos --- svx/source/tbxctrls/fontworkgallery.cxx | 49 ++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 10 deletions(-) (limited to 'svx') diff --git a/svx/source/tbxctrls/fontworkgallery.cxx b/svx/source/tbxctrls/fontworkgallery.cxx index bfcde08d09c8..7acaac50b15c 100644 --- a/svx/source/tbxctrls/fontworkgallery.cxx +++ b/svx/source/tbxctrls/fontworkgallery.cxx @@ -20,16 +20,19 @@ #include +#include + #include #include +#include + #include #include #include #include -#include #include #include #include @@ -38,6 +41,8 @@ #include #include +#include + #include #include @@ -193,17 +198,41 @@ void FontWorkGalleryDialog::insertSelectedFontwork() // pNewObject->SetPage(nullptr); tools::Rectangle aObjRect( pNewObject->GetLogicRect() ); - tools::Rectangle aVisArea = pOutDev->PixelToLogic(tools::Rectangle(Point(0,0), pOutDev->GetOutputSizePixel())); - Point aPagePos = aVisArea.Center(); - bool bIsInsertedObjectSmallerThanVisibleArea = - aVisArea.GetSize().getHeight() > aObjRect.GetSize().getHeight() && - aVisArea.GetSize().getWidth() > aObjRect.GetSize().getWidth(); - if (bIsInsertedObjectSmallerThanVisibleArea) + Point aPagePos; + Size aFontworkSize = aObjRect.GetSize(); + + if (comphelper::LibreOfficeKit::isActive()) { - aPagePos.AdjustX( -(aObjRect.GetWidth() / 2) ); - aPagePos.AdjustY( -(aObjRect.GetHeight() / 2) ); + SfxViewShell* pViewShell = SfxViewShell::Current(); + + aPagePos = pViewShell->getLOKVisibleArea().Center(); + + aPagePos.setX(convertTwipToMm100(aPagePos.X())); + aPagePos.setY(convertTwipToMm100(aPagePos.Y())); + + sal_Int32 nLOKViewWidth = 0.8 * convertTwipToMm100(pViewShell->getLOKVisibleArea().getWidth()); + if (aFontworkSize.getWidth() > nLOKViewWidth) + { + double fScale = static_cast(aFontworkSize.getWidth()) / nLOKViewWidth; + aFontworkSize.setWidth(aFontworkSize.getWidth() / fScale); + aFontworkSize.setHeight(aFontworkSize.getHeight() / fScale); + } } - tools::Rectangle aNewObjectRectangle(aPagePos, aObjRect.GetSize()); + else + { + Size aSize = pOutDev->GetOutputSizePixel(); + tools::Rectangle aPixelVisRect(Point(0,0), aSize); + tools::Rectangle aVisArea = pOutDev->PixelToLogic(aPixelVisRect); + + aPagePos = aVisArea.Center(); + } + + if (aPagePos.getX() > aFontworkSize.getWidth() / 2) + aPagePos.AdjustX( -(aFontworkSize.getWidth() / 2) ); + if (aPagePos.getY() > aFontworkSize.getHeight() / 2) + aPagePos.AdjustY( -(aFontworkSize.getHeight() / 2) ); + + tools::Rectangle aNewObjectRectangle(aPagePos, aFontworkSize); pNewObject->SetLogicRect(aNewObjectRectangle); if (bUseSpecialCalcMode) -- cgit