sc/qa/unit/tiledrendering/data/edit-shape-text.ods |binary
 sc/qa/unit/tiledrendering/tiledrendering.cxx       |   54 +++++++++++++++++++++
 sc/source/ui/view/gridwin4.cxx                     |    7 +-
 3 files changed, 59 insertions(+), 2 deletions(-)

New commits:
commit 021c93bbf36a9d25ad43da0aefd39d5e7bfdad19
Author:     Caolán McNamara <caolan.mcnam...@collabora.com>
AuthorDate: Thu Feb 15 21:41:34 2024 +0000
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Sat Feb 17 20:17:58 2024 +0100

    kit: editing text in shapes outside the topleft tile has misplaced text
    
    keep into account the zoom factor as we do elsewhere
    
    Change-Id: I024ba16c2ef47c01f05ffb8630ec0ae3b2d2e5a3
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163515
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163526
    Tested-by: Jenkins

diff --git a/sc/qa/unit/tiledrendering/data/edit-shape-text.ods 
b/sc/qa/unit/tiledrendering/data/edit-shape-text.ods
new file mode 100644
index 000000000000..95fea6d3f738
Binary files /dev/null and b/sc/qa/unit/tiledrendering/data/edit-shape-text.ods 
differ
diff --git a/sc/qa/unit/tiledrendering/tiledrendering.cxx 
b/sc/qa/unit/tiledrendering/tiledrendering.cxx
index c7d43a141a84..d371d817ffa5 100644
--- a/sc/qa/unit/tiledrendering/tiledrendering.cxx
+++ b/sc/qa/unit/tiledrendering/tiledrendering.cxx
@@ -3712,6 +3712,60 @@ CPPUNIT_TEST_FIXTURE(ScTiledRenderingTest, 
testExtendedAreasDontOverlap)
                          aView1.m_aInvalidations[1].Top());
 }
 
+static Bitmap getTile(ScModelObj* pModelObj, int nTilePosX, int nTilePosY, 
tools::Long nTileWidth, tools::Long nTileHeight)
+{
+    size_t nCanvasSize = 1024;
+    size_t nTileSize = 256;
+    std::vector<unsigned char> aPixmap(nCanvasSize * nCanvasSize * 4, 0);
+    ScopedVclPtrInstance<VirtualDevice> xDevice(DeviceFormat::WITHOUT_ALPHA);
+    xDevice->SetBackground(Wallpaper(COL_TRANSPARENT));
+    xDevice->SetOutputSizePixelScaleOffsetAndLOKBuffer(Size(nCanvasSize, 
nCanvasSize),
+            Fraction(1.0), Point(), aPixmap.data());
+    pModelObj->paintTile(*xDevice, nCanvasSize, nCanvasSize, nTilePosX, 
nTilePosY, nTileWidth, nTileHeight);
+    xDevice->EnableMapMode(false);
+    return xDevice->GetBitmap(Point(0, 0), Size(nTileSize, nTileSize));
+}
+
+// Ensure that editing a shape not in the topleft tile has its text shown 
inside the shape
+// center while editing
+CPPUNIT_TEST_FIXTURE(ScTiledRenderingTest, testEditShapeText)
+{
+    ScModelObj* pModelObj = createDoc("edit-shape-text.ods");
+
+    // Set View to initial 100%
+    pModelObj->setClientVisibleArea(tools::Rectangle(0, 0, 28050, 10605));
+    pModelObj->setClientZoom(256, 256, 1920, 1920);
+
+    ScTabViewShell* pView = 
dynamic_cast<ScTabViewShell*>(SfxViewShell::Current());
+    CPPUNIT_ASSERT(pView);
+
+    const bool bShapeSelected = pView->SelectObject(u"Shape 1");
+    CPPUNIT_ASSERT(bShapeSelected);
+
+    
CPPUNIT_ASSERT(ScDocShell::GetViewData()->GetScDrawView()->AreObjectsMarked());
+
+    Scheduler::ProcessEventsToIdle();
+
+    // Enter editing mode, shape start with no text
+    pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::F2);
+    pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, awt::Key::F2);
+
+    Scheduler::ProcessEventsToIdle();
+
+    // Grab a snapshot of the center of the shape
+    Bitmap aBitmapBefore = getTile(pModelObj, 4096, 3584, 15360, 7680);
+
+    // reuse this to type into the active shape edit
+    lcl_typeCharsInCell("MMMMMMM", 0, 0, pView, pModelObj, true, false);
+
+    // Grab a new snapshot of the center of the shape
+    Bitmap aBitmapAfter = getTile(pModelObj, 4096, 3584, 15360, 7680);
+
+    // Without the fix, the text is not inside this tile and the before and
+    // after are the same.
+    CPPUNIT_ASSERT_MESSAGE("Text is not visible", aBitmapBefore != 
aBitmapAfter);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/view/gridwin4.cxx b/sc/source/ui/view/gridwin4.cxx
index 463b5ac32704..6cd017d271b2 100644
--- a/sc/source/ui/view/gridwin4.cxx
+++ b/sc/source/ui/view/gridwin4.cxx
@@ -1062,8 +1062,11 @@ void ScGridWindow::DrawContent(OutputDevice &rDevice, 
const ScTableInfo& rTableI
 
                 aOrigin.setY(o3tl::convert(aOrigin.getY(), o3tl::Length::twip, 
o3tl::Length::px)
                              + aOutputData.nScrY);
-                aOrigin = Point(aOrigin.getX() * twipFactor,
-                                aOrigin.getY() * twipFactor);
+
+                // keep into account the zoom factor
+                aOrigin = Point((aOrigin.getX() * twipFactor) / 
static_cast<double>(aDrawMode.GetScaleX()),
+                                 (aOrigin.getY() * twipFactor) / 
static_cast<double>(aDrawMode.GetScaleY()));
+
                 MapMode aNew = rDevice.GetMapMode();
                 aNew.SetOrigin(aOrigin);
                 rDevice.SetMapMode(aNew);

Reply via email to