sw/qa/extras/uiwriter/uiwriter6.cxx |   63 ++++++++++++++++++++++++++++++++++++
 sw/source/core/layout/flylay.cxx    |   38 ++++++++++++++++++---
 2 files changed, 96 insertions(+), 5 deletions(-)

New commits:
commit dece7d80c31c3c489859200bc93d9c948a535cbf
Author:     László Németh <nem...@numbertext.org>
AuthorDate: Tue May 21 13:20:24 2024 +0200
Commit:     László Németh <nem...@numbertext.org>
CommitDate: Wed May 29 23:43:47 2024 +0200

    tdf#161261 sw: fix lost size of image resized in fixed-height cell
    
    A fixed-height cell can contain a bigger image, which is cropped by
    cell boundaries. It was not possible to resize this image with a simple 
drag & drop, because its size changed to the cell size immediately.
    Now it's possible, like MSO does.
    
    Follow-up to commit 30de13743f144aced83bc43d310592f82788c910
    "tdf#160836 sw: resize rows at images cropped by row height".
    
    Change-Id: I6b4e911432e784a96d393ee225ce69a1f2986d56
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168186
    Tested-by: Jenkins
    Reviewed-by: László Németh <nem...@numbertext.org>
    Tested-by: László Németh <nem...@numbertext.org>

diff --git a/sw/qa/extras/uiwriter/uiwriter6.cxx 
b/sw/qa/extras/uiwriter/uiwriter6.cxx
index fb3ecb357bcd..6322120748da 100644
--- a/sw/qa/extras/uiwriter/uiwriter6.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter6.cxx
@@ -36,6 +36,7 @@
 #include <sfx2/dispatch.hxx>
 #include <cmdid.h>
 #include <tools/json_writer.hxx>
+#include <tools/UnitConversion.hxx>
 #include <boost/property_tree/json_parser.hpp>
 
 #include <com/sun/star/text/XTextTable.hpp>
@@ -1559,6 +1560,68 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest6, testTdf160836)
     CPPUNIT_ASSERT_EQUAL(tools::Long(1980), pCellA1->getFrameArea().Height());
 }
 
+CPPUNIT_TEST_FIXTURE(SwUiWriterTest6, testTdf161261)
+{
+    createSwDoc("tdf160842.fodt");
+    SwDoc* pDoc = getSwDoc();
+    CPPUNIT_ASSERT(pDoc);
+    SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+    CPPUNIT_ASSERT(pWrtShell);
+    // the cursor is not in the table
+    CPPUNIT_ASSERT(!pWrtShell->IsCursorInTable());
+
+    SwRootFrame* pLayout = pDoc->getIDocumentLayoutAccess().GetCurrentLayout();
+    auto pPage = dynamic_cast<SwPageFrame*>(pLayout->Lower());
+    CPPUNIT_ASSERT(pPage);
+    const SwSortedObjs& rPageObjs = *pPage->GetSortedObjs();
+    CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rPageObjs.size());
+    auto pPageFly = dynamic_cast<SwFlyAtContentFrame*>(rPageObjs[0]);
+    CPPUNIT_ASSERT(pPageFly);
+    auto pTable = dynamic_cast<SwTabFrame*>(pPageFly->GetLower());
+    CPPUNIT_ASSERT(pTable);
+    auto pRow1 = pTable->GetLower();
+    CPPUNIT_ASSERT(pRow1->IsRowFrame());
+    auto pCellA1 = pRow1->GetLower();
+    CPPUNIT_ASSERT(pCellA1);
+    const SwRect& rCellA1Rect = pCellA1->getFrameArea();
+    auto nRowHeight = rCellA1Rect.Height();
+
+    // select image by clicking on it at the center of the upper cell
+    Point ptFrom(rCellA1Rect.Left() + rCellA1Rect.Width() / 2, 
rCellA1Rect.Top() + nRowHeight / 2);
+    vcl::Window& rEditWin = pDoc->GetDocShell()->GetView()->GetEditWin();
+    Point aFrom = rEditWin.LogicToPixel(ptFrom);
+    MouseEvent aClickEvent(aFrom, 1, MouseEventModifiers::SIMPLECLICK, 
MOUSE_LEFT);
+    rEditWin.MouseButtonDown(aClickEvent);
+    rEditWin.MouseButtonUp(aClickEvent);
+
+    // Then make sure that the image is selected:
+    SelectionType eType = pWrtShell->GetSelectionType();
+    CPPUNIT_ASSERT_EQUAL(SelectionType::Graphic, eType);
+
+    uno::Reference<drawing::XShape> xShape = getShape(2);
+    CPPUNIT_ASSERT(xShape.is());
+
+    // zoom image by drag & drop using right bottom handle of the image
+    const SwRect& rSelRect = pWrtShell->GetAnyCurRect(CurRectType::Frame);
+    Point ptFromHandle(rSelRect.Right(), rSelRect.Bottom());
+    Point aFromHandle = rEditWin.LogicToPixel(ptFromHandle);
+    Point ptTo(rSelRect.Left() + rSelRect.Width() * 1.5, rSelRect.Top() + 
rSelRect.Height() * 1.5);
+    Point aTo = rEditWin.LogicToPixel(ptTo);
+    MouseEvent aClickEvent2(aFromHandle, 1, MouseEventModifiers::SIMPLECLICK, 
MOUSE_LEFT);
+    rEditWin.MouseButtonDown(aClickEvent2);
+    MouseEvent aClickEvent3(aTo, 0, MouseEventModifiers::SIMPLEMOVE, 
MOUSE_LEFT);
+    rEditWin.MouseMove(aClickEvent3);
+    rEditWin.MouseMove(aClickEvent3);
+    MouseEvent aClickEvent4(aTo, 1, MouseEventModifiers::SIMPLECLICK, 
MOUSE_LEFT);
+    rEditWin.MouseButtonUp(aClickEvent4);
+    Scheduler::ProcessEventsToIdle();
+
+    // Make sure image is greater than before, instead of minimizing it to the 
cell size
+    // This was 8707 and 6509
+    CPPUNIT_ASSERT_GREATER(sal_Int32(10000), xShape->getSize().Width);
+    CPPUNIT_ASSERT_GREATER(sal_Int32(8000), xShape->getSize().Height);
+}
+
 CPPUNIT_TEST_FIXTURE(SwUiWriterTest6, testTdf115132)
 {
     createSwDoc();
diff --git a/sw/source/core/layout/flylay.cxx b/sw/source/core/layout/flylay.cxx
index 1a39b735d2d8..42ea0332f6eb 100644
--- a/sw/source/core/layout/flylay.cxx
+++ b/sw/source/core/layout/flylay.cxx
@@ -1409,17 +1409,45 @@ bool CalcClipRect( const SdrObject *pSdrObj, SwRect 
&rRect, bool bMove )
         {
             const SwFrame *pUp = pFly->GetAnchorFrame()->GetUpper();
             SwRectFnSet aRectFnSet(pFly->GetAnchorFrame());
+            bool bOnlyCellFrame = pUp->IsCellFrame();
             while( pUp->IsColumnFrame() || pUp->IsSctFrame() || 
pUp->IsColBodyFrame())
                 pUp = pUp->GetUpper();
             rRect = pUp->getFrameArea();
             if( !pUp->IsBodyFrame() )
             {
-                rRect += pUp->getFramePrintArea().Pos();
-                rRect.SSize( pUp->getFramePrintArea().SSize() );
-                if ( pUp->IsCellFrame() )
+                bool bCropByFixedHeightCell = false;
+                // allow zoom image cropped by fixed height table cell
+                if ( bOnlyCellFrame && pUp->IsCellFrame() && pUp->GetUpper() &&
+                     // is a fixed height table row?
+                     pUp->GetUpper()->IsRowFrame() && SwFrameSize::Fixed ==
+                         
pUp->GetUpper()->GetAttrSet()->GetFrameSize().GetHeightSizeType() )
                 {
-                    const SwFrame *pTab = pUp->FindTabFrame();
-                    aRectFnSet.SetBottom( rRect, 
aRectFnSet.GetPrtBottom(*pTab->GetUpper()) );
+                    // is image anchored as character?
+                    if ( const SwContact* pC = GetUserCall(pSdrObj) )
+                    {
+                        const SwFrameFormat* pFormat = pC->GetFormat();
+                        const SwFormatAnchor& rAnch = pFormat->GetAnchor();
+                        if ( RndStdIds::FLY_AS_CHAR == rAnch.GetAnchorId() )
+                        {
+                            const SwPageFrame *pPageFrame = 
pFly->FindPageFrame();
+                            Size aSize( 
pPageFrame->getFramePrintArea().SSize() );
+                            // TODO doubled print area is still cropped by 
full page size, yet
+                            rRect.SSize(Size(aSize.getWidth() * 2, 
aSize.getHeight() * 2));
+                            bCropByFixedHeightCell = true;
+                        }
+                    }
+                }
+
+                if ( !bCropByFixedHeightCell )
+                {
+                    rRect += pUp->getFramePrintArea().Pos();
+                    rRect.SSize( pUp->getFramePrintArea().SSize() );
+
+                    if ( pUp->IsCellFrame() )
+                    {
+                        const SwFrame *pTab = pUp->FindTabFrame();
+                        aRectFnSet.SetBottom( rRect, 
aRectFnSet.GetPrtBottom(*pTab->GetUpper()) );
+                    }
                 }
             }
             else if ( pUp->GetUpper()->IsPageFrame() )

Reply via email to