summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2020-11-16 21:07:48 +0100
committerXisco Fauli <xiscofauli@libreoffice.org>2020-11-17 14:25:05 +0100
commit8a5e6b1698cb9c31709aa19fff53c73794055448 (patch)
treea5d8fda42369dcf3fb04312865519f2a4ab1ad4d
parentb89e61976dbf4d990f8cc74d90d6e73aba98a629 (diff)
tdf#137980 sw textbox: fix automatic size of shapes with rotated text
If a shape+fly pair has automatic size for the fly frame, then only the sw layout knows the necessary size, this is then sent to the shape and SdrObjCustomShape::AdjustTextFrameWidthAndHeight() is meant to respect those "suggestion", instead of sizing the shape based on the contained editeng text, which is always empty for shape+fly pairs. Improve this mechanism so it works better when the writing direction of the fly frame is tbrl ("rotate to the right"): make sure we always grow to the left and to the bottom, so the shape and the fly geometry matches. Also improve the testTextBoxSizeAtBottomOfPage "change detector" test which had a hardcoded height, but which did not clearly derive from any in-bugdoc value. Rather just test that the shape wider than taller, which was probably the intention. (cherry picked from commit 712d7a5df188bb20527f1a7533b2e2c1d4377247) Conflicts: sw/qa/core/layout/layout.cxx Change-Id: Ic6a77a1125bbf31b198aaf9048dc4812c87b4d9b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105971 Tested-by: Jenkins Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
-rw-r--r--svx/source/svdraw/svdoashp.cxx18
-rw-r--r--sw/CppunitTest_sw_core_layout.mk1
-rw-r--r--sw/qa/core/layout/data/textbox-autogrow-vertical.docxbin0 -> 13722 bytes
-rw-r--r--sw/qa/core/layout/layout.cxx25
4 files changed, 39 insertions, 5 deletions
diff --git a/svx/source/svdraw/svdoashp.cxx b/svx/source/svdraw/svdoashp.cxx
index 1708dc64ccc3..4e44f1658c7b 100644
--- a/svx/source/svdraw/svdoashp.cxx
+++ b/svx/source/svdraw/svdoashp.cxx
@@ -2340,12 +2340,16 @@ bool SdrObjCustomShape::AdjustTextFrameWidthAndHeight(tools::Rectangle& rR, bool
bWdtGrow = false;
if ( nHgtGrow == 0 )
bHgtGrow=false;
- if ( bWdtGrow || bHgtGrow )
+ if ( bWdtGrow || bHgtGrow || !m_aSuggestedTextFrameSize.IsEmpty())
{
- if ( bWdtGrow )
+ if ( bWdtGrow || m_aSuggestedTextFrameSize.Width() )
{
SdrTextHorzAdjust eHAdj=GetTextHorizontalAdjust();
- if ( eHAdj == SDRTEXTHORZADJUST_LEFT )
+ if (m_aSuggestedTextFrameSize.Width())
+ {
+ rR.SetRight(rR.Left() + m_aSuggestedTextFrameSize.Width());
+ }
+ else if ( eHAdj == SDRTEXTHORZADJUST_LEFT )
rR.AdjustRight(nWdtGrow );
else if ( eHAdj == SDRTEXTHORZADJUST_RIGHT )
rR.AdjustLeft( -nWdtGrow );
@@ -2356,10 +2360,14 @@ bool SdrObjCustomShape::AdjustTextFrameWidthAndHeight(tools::Rectangle& rR, bool
rR.SetRight(rR.Left()+nWdt );
}
}
- if ( bHgtGrow )
+ if ( bHgtGrow || m_aSuggestedTextFrameSize.Height() )
{
SdrTextVertAdjust eVAdj=GetTextVerticalAdjust();
- if ( eVAdj == SDRTEXTVERTADJUST_TOP )
+ if (m_aSuggestedTextFrameSize.Height())
+ {
+ rR.SetBottom(rR.Top() + m_aSuggestedTextFrameSize.Height());
+ }
+ else if ( eVAdj == SDRTEXTVERTADJUST_TOP )
rR.AdjustBottom(nHgtGrow );
else if ( eVAdj == SDRTEXTVERTADJUST_BOTTOM )
rR.AdjustTop( -nHgtGrow );
diff --git a/sw/CppunitTest_sw_core_layout.mk b/sw/CppunitTest_sw_core_layout.mk
index 1801e66a713d..81c7e22e70bc 100644
--- a/sw/CppunitTest_sw_core_layout.mk
+++ b/sw/CppunitTest_sw_core_layout.mk
@@ -23,6 +23,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sw_core_layout, \
cppuhelper \
sal \
sfx \
+ svxcore \
sw \
test \
unotest \
diff --git a/sw/qa/core/layout/data/textbox-autogrow-vertical.docx b/sw/qa/core/layout/data/textbox-autogrow-vertical.docx
new file mode 100644
index 000000000000..0cc45a781cb3
--- /dev/null
+++ b/sw/qa/core/layout/data/textbox-autogrow-vertical.docx
Binary files differ
diff --git a/sw/qa/core/layout/layout.cxx b/sw/qa/core/layout/layout.cxx
index ccf2b5cd513a..947152de49c6 100644
--- a/sw/qa/core/layout/layout.cxx
+++ b/sw/qa/core/layout/layout.cxx
@@ -10,8 +10,11 @@
#include <swmodeltestbase.hxx>
#include <vcl/gdimtf.hxx>
+#include <svx/svdpage.hxx>
#include <wrtsh.hxx>
+#include <IDocumentDrawModelAccess.hxx>
+#include <drawdoc.hxx>
static char const DATA_DIRECTORY[] = "/sw/qa/core/layout/data/";
@@ -146,6 +149,28 @@ CPPUNIT_TEST_FIXTURE(SwCoreLayoutTest, testContinuousEndnotesMoveBackwards)
assertXPath(pLayout, "/root/page[2]/ftncont", 1);
}
+CPPUNIT_TEST_FIXTURE(SwCoreLayoutTest, testTextBoxAutoGrowVertical)
+{
+ load(DATA_DIRECTORY, "textbox-autogrow-vertical.docx");
+ SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
+ SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+ SdrPage* pPage = pDoc->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0);
+ SdrObject* pShape = pPage->GetObj(0);
+ tools::Rectangle aShapeRect = pShape->GetCurrentBoundRect();
+
+ discardDumpedLayout();
+ xmlDocUniquePtr pLayout = parseLayoutDump();
+ CPPUNIT_ASSERT(pLayout);
+ sal_Int32 nFlyLeft = getXPath(pLayout, "//fly/infos/bounds", "left").toInt32();
+ sal_Int32 nFlyTop = getXPath(pLayout, "//fly/infos/bounds", "top").toInt32();
+ sal_Int32 nFlyRight = getXPath(pLayout, "//fly/infos/bounds", "right").toInt32();
+ sal_Int32 nFlyBottom = getXPath(pLayout, "//fly/infos/bounds", "bottom").toInt32();
+ tools::Rectangle aFlyRect(nFlyLeft, nFlyTop, nFlyRight, nFlyBottom);
+ // Without the accompanying fix in place, this test would have failed, as aFlyRect was too wide,
+ // so it was not inside aShapeRect anymore.
+ CPPUNIT_ASSERT(aShapeRect.IsInside(aFlyRect));
+}
+
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */