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

New commits:
commit e1d8260158c1cb2f930087883e441bf23209589f
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: Fri Feb 16 18:11:04 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/+/163467
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Marco Cecchetti <marco.cecche...@collabora.com>

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 7dc38facfa8e..1b6cf11d4211 100644
--- a/sc/qa/unit/tiledrendering/tiledrendering.cxx
+++ b/sc/qa/unit/tiledrendering/tiledrendering.cxx
@@ -178,6 +178,7 @@ public:
     void testCellInvalidationDocWithExistingZoom();
     void testOptimalRowHeight();
     void testExtendedAreasDontOverlap();
+    void testEditShapeText();
 
     CPPUNIT_TEST_SUITE(ScTiledRenderingTest);
     CPPUNIT_TEST(testRowColumnHeaders);
@@ -257,6 +258,7 @@ public:
     CPPUNIT_TEST(testCellInvalidationDocWithExistingZoom);
     CPPUNIT_TEST(testOptimalRowHeight);
     CPPUNIT_TEST(testExtendedAreasDontOverlap);
+    CPPUNIT_TEST(testEditShapeText);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -3941,6 +3943,60 @@ void ScTiledRenderingTest::testExtendedAreasDontOverlap()
                          aView1.m_aInvalidations[1].Top());
 }
 
+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> pDevice(DeviceFormat::DEFAULT);
+    pDevice->SetBackground(Wallpaper(COL_TRANSPARENT));
+    pDevice->SetOutputSizePixelScaleOffsetAndLOKBuffer(Size(nCanvasSize, 
nCanvasSize),
+            Fraction(1.0), Point(), aPixmap.data());
+    pModelObj->paintTile(*pDevice, nCanvasSize, nCanvasSize, nTilePosX, 
nTilePosY, nTileWidth, nTileHeight);
+    pDevice->EnableMapMode(false);
+    return pDevice->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
+void 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_TEST_SUITE_REGISTRATION(ScTiledRenderingTest);
diff --git a/sc/source/ui/view/gridwin4.cxx b/sc/source/ui/view/gridwin4.cxx
index 0243b92a0a53..97b382d50349 100644
--- a/sc/source/ui/view/gridwin4.cxx
+++ b/sc/source/ui/view/gridwin4.cxx
@@ -1060,8 +1060,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