svx/source/dialog/svxruler.cxx | 72 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 65 insertions(+), 7 deletions(-)
New commits: commit 908334f85ee9ecd1d7aa4825e25c48a59516f804 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Fri May 31 15:01:36 2024 +0900 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Thu Jun 20 04:53:35 2024 +0200 svx: adjust the values for impress/draw ruler to work with LOKit The values in impress/draw don't need to be converted to 100th mm as the vales are already in 100th mm. However the null offset and page size needs to be adjusted, because in impress/draw the actual document doesn't start at 0,0 but there is one document width or 1/2 document height margin to the left, right, up and down of the document. So the null offset returns the number of the document width or 1/2 document height. For LOKit the null offset needs to be subtracted. Similar needs to be done for page width and height. The page width is docuemnt width * 3 and page height is document height * 2. So to get expected numbers for LOKit, the page width needs to be divided by 3 and page height divided by 2. Change-Id: I8d5561d5273b4bbeab475565504fa64c7f882fd2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168276 Reviewed-by: Szymon Kłos <szymon.k...@collabora.com> Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> (cherry picked from commit 54d8c1b8f2934d6196a8b19400879fb6b67c255b) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168986 Tested-by: Jenkins diff --git a/svx/source/dialog/svxruler.cxx b/svx/source/dialog/svxruler.cxx index e0b84b9ad1ba..3f447bf9a1af 100644 --- a/svx/source/dialog/svxruler.cxx +++ b/svx/source/dialog/svxruler.cxx @@ -50,8 +50,13 @@ #include <tools/UnitConversion.hxx> #include <comphelper/lok.hxx> #include "rlrcitem.hxx" +#include <com/sun/star/frame/XFrame.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <sfx2/viewfrm.hxx> #include <memory> +using namespace css; + #define CTRL_ITEM_COUNT 14 #define GAP 10 #define OBJECT_BORDER_COUNT 4 @@ -193,7 +198,6 @@ SvxRuler::SvxRuler( bActive(true), mbCoarseSnapping(false), mbSnapping(true) - { /* Constructor; Initialize data buffer; controller items are created */ @@ -279,7 +283,6 @@ SvxRuler::SvxRuler( ruler_tab_svx.DPIScaleFactor = pParent->GetDPIScaleFactor(); ruler_tab_svx.height *= ruler_tab_svx.DPIScaleFactor; ruler_tab_svx.width *= ruler_tab_svx.DPIScaleFactor; - } SvxRuler::~SvxRuler() @@ -1147,12 +1150,67 @@ void SvxRuler::SetNullOffsetLogic(tools::Long lVal) // Setting of the logic Null void SvxRuler::CreateJsonNotification(tools::JsonWriter& rJsonWriter) { - rJsonWriter.put("margin1", convertTwipToMm100(GetMargin1())); - rJsonWriter.put("margin2", convertTwipToMm100(GetMargin2())); - rJsonWriter.put("leftOffset", convertTwipToMm100(GetNullOffset())); - rJsonWriter.put("pageOffset", convertTwipToMm100(GetPageOffset())); + tools::Long nMargin1 = 0; + tools::Long nMargin2 = 0; + tools::Long nNullOffset = 0; + tools::Long nPageOffset = 0; + tools::Long nPageWidthHeight = 0; + + bool bWriter = false; + + // Determine if we are a Ruler for Writer or not + if (SfxViewFrame* pFrame = SfxViewFrame::Current()) + { + uno::Reference<frame::XFrame> xFrame = pFrame->GetFrame().GetFrameInterface(); + uno::Reference<frame::XModel> xModel = xFrame->getController()->getModel(); + uno::Reference<lang::XServiceInfo> xSI(xModel, uno::UNO_QUERY); + if (xSI.is()) + { + bWriter = xSI->supportsService("com.sun.star.text.TextDocument") + || xSI->supportsService("com.sun.star.text.WebDocument") + || xSI->supportsService("com.sun.star.text.GlobalDocument"); + } + } + + if (bWriter) + { + // In Writer the ruler values need to be converted first from pixel to twips (default logical unit) and then to 100thmm + nMargin1 = convertTwipToMm100(ConvertPosLogic(GetMargin1())); + nMargin2 = convertTwipToMm100(ConvertPosLogic(GetMargin2())); + nNullOffset = convertTwipToMm100(ConvertPosLogic(GetNullOffset())); + nPageOffset = convertTwipToMm100(ConvertPosLogic(GetPageOffset())); + nPageWidthHeight = convertTwipToMm100(GetPageWidth()); + } + else + { + // Only convert from pixel to default logical unit, which is 100thmm for Impress + nMargin1 = ConvertPosLogic(GetMargin1()); + nMargin2 = ConvertPosLogic(GetMargin2()); + nPageOffset = ConvertPosLogic(GetPageOffset()); + + // In LOKit API we expect the ruler 0,0 coordinate is where the document starts. + // In Impress and Draw the ruler 0,0 is where the canvas starts, not where the document starts. + // The margin to the document is 1 document width (on the left and right) and 0.5 document height + // (on the top and bottom). + // So the canvas width = 3 * document width, canvas height = 2 * document height + if (isHorizontal()) + { + nPageWidthHeight = GetPageWidth() / 3; + nNullOffset = ConvertPosLogic(GetNullOffset()) - nPageWidthHeight; + } + else + { + nPageWidthHeight = GetPageWidth() / 2; + nNullOffset = ConvertPosLogic(GetNullOffset()) - (nPageWidthHeight / 2); + } + } + + rJsonWriter.put("margin1", nMargin1); + rJsonWriter.put("margin2", nMargin2); + rJsonWriter.put("leftOffset", nNullOffset); + rJsonWriter.put("pageOffset", nPageOffset); + rJsonWriter.put("pageWidth", nPageWidthHeight); - rJsonWriter.put("pageWidth", convertTwipToMm100(GetPageWidth())); { auto tabsNode = rJsonWriter.startNode("tabs");