diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2022-11-22 17:40:26 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2022-11-22 21:45:36 +0100 |
commit | d19816350dba8daffa2deb495d4e697062579456 (patch) | |
tree | b82fccd1158fa2e46f1fd978ceeb7229e55e74eb /sfx2 | |
parent | 8cc4e6c8f572d84dc004d97fa25d17fe85505dc6 (diff) |
lok: draw Math in-place widget in sd
Change-Id: If874c0227ec724fa5b1517080db252e64f9597c5
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143121
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'sfx2')
-rw-r--r-- | sfx2/source/view/lokstarmathhelper.cxx | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/sfx2/source/view/lokstarmathhelper.cxx b/sfx2/source/view/lokstarmathhelper.cxx index 5586068d88b7..9b2df19ecdec 100644 --- a/sfx2/source/view/lokstarmathhelper.cxx +++ b/sfx2/source/view/lokstarmathhelper.cxx @@ -15,10 +15,12 @@ #include <sfx2/objsh.hxx> #include <comphelper/dispatchcommand.hxx> +#include <comphelper/lok.hxx> #include <toolkit/helper/vclunohelper.hxx> #include <tools/fract.hxx> #include <tools/UnitConversion.hxx> #include <vcl/layout.hxx> +#include <vcl/virdev.hxx> #include <vcl/window.hxx> #include <com/sun/star/embed/XEmbeddedObject.hpp> @@ -185,4 +187,61 @@ bool LokStarMathHelper::postMouseEvent(int nType, int nX, int nY, int nCount, in return false; } +void LokStarMathHelper::PaintTile(VirtualDevice& rDevice, const tools::Rectangle& rTileRect) +{ + const tools::Rectangle aMathRect = GetBoundingBox(); + if (rTileRect.GetIntersection(aMathRect).IsEmpty()) + return; + + vcl::Window* pWidgetWindow = GetWidgetWindow(); + if (!pWidgetWindow) + return; + + Point aOffset(aMathRect.Left() - rTileRect.Left(), aMathRect.Top() - rTileRect.Top()); + + MapMode newMode = rDevice.GetMapMode(); + newMode.SetOrigin(aOffset); + rDevice.SetMapMode(newMode); // Push/Pop is done in PaintAllInPlaceOnTile + + pWidgetWindow->Paint(rDevice, {}); // SmGraphicWidget::Paint does not use the passed rectangle +} + +void LokStarMathHelper::PaintAllInPlaceOnTile(VirtualDevice& rDevice, int nOutputWidth, + int nOutputHeight, int nTilePosX, int nTilePosY, + tools::Long nTileWidth, tools::Long nTileHeight) +{ + if (comphelper::LibreOfficeKit::isTiledAnnotations()) + return; + + SfxViewShell* pCurView = SfxViewShell::Current(); + if (!pCurView) + return; + const ViewShellDocId nDocId = pCurView->GetDocId(); + const int nPartForCurView = pCurView->getPart(); + + // Resizes the virtual device to contain the entries context + rDevice.SetOutputSizePixel({ nOutputWidth, nOutputHeight }); + + rDevice.Push(vcl::PushFlags::MAPMODE); + MapMode aMapMode(rDevice.GetMapMode()); + + // Scaling. Must convert from pixels to twips. We know that VirtualDevices use a DPI of 96. + const Fraction scale = conversionFract(o3tl::Length::px, o3tl::Length::twip); + const Fraction scaleX = Fraction(nOutputWidth, nTileWidth) * scale; + const Fraction scaleY = Fraction(nOutputHeight, nTileHeight) * scale; + aMapMode.SetScaleX(scaleX); + aMapMode.SetScaleY(scaleY); + aMapMode.SetMapUnit(MapUnit::MapTwip); + rDevice.SetMapMode(aMapMode); + + const tools::Rectangle aTileRect(Point(nTilePosX, nTilePosY), Size(nTileWidth, nTileHeight)); + + for (SfxViewShell* pViewShell = SfxViewShell::GetFirst(); pViewShell; + pViewShell = SfxViewShell::GetNext(*pViewShell)) + if (pViewShell->GetDocId() == nDocId && pViewShell->getPart() == nPartForCurView) + LokStarMathHelper(pViewShell).PaintTile(rDevice, aTileRect); + + rDevice.Pop(); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |