summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRegényi Balázs <regenyi.balazs+gerrit@gmail.com>2020-06-10 14:27:32 +0200
committerLászló Németh <nemeth@numbertext.org>2020-07-01 18:33:59 +0200
commitd63321d949563759ee2ada96fdc2e0f8728941b2 (patch)
treed94ebb64e18839b430760dba525a885b10ae8093
parentb8db739c20f7a174702bab34eb9373ee3d0a9d02 (diff)
tdf#133863 tdf#133864 DOCX shape import: width relative to inside
and outside margins. See commit 43d7f4e3640c5e370fd1204739c2b0c7eb5f40e4 (offapi: document the 4 new properties which are no longer read-only). commit b46f4bc9760267ac5e45d43b77b5d2721ee4c386 (tdf#133070 DOCX import: fix shape height relative to bottom page margin) commit 330ed8120e9881656716d70d87b9f49f861f0bfa (tdf#133670 DOCX import: fix shape width relative to right margin) commit 7380905abc0833d9e4c4fe731d76174db8a8724c (tdf#132976 DOCX import: fix shape width relative to left margin) Co-authored-by: Szabolcs Tóth Change-Id: If81b7c80732141be1491ca82770cf6eee99f5656 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/97627 Tested-by: László Németh <nemeth@numbertext.org> Reviewed-by: László Németh <nemeth@numbertext.org>
-rw-r--r--sw/qa/extras/ooxmlexport/data/tdf133861_RelativeAnchorWidthFromInsideOutsideMargin.docxbin0 -> 18324 bytes
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlexport3.cxx23
-rw-r--r--sw/source/core/layout/anchoreddrawobject.cxx36
-rw-r--r--writerfilter/source/dmapper/GraphicImport.cxx2
4 files changed, 59 insertions, 2 deletions
diff --git a/sw/qa/extras/ooxmlexport/data/tdf133861_RelativeAnchorWidthFromInsideOutsideMargin.docx b/sw/qa/extras/ooxmlexport/data/tdf133861_RelativeAnchorWidthFromInsideOutsideMargin.docx
new file mode 100644
index 000000000000..453320f388f1
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/data/tdf133861_RelativeAnchorWidthFromInsideOutsideMargin.docx
Binary files differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport3.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport3.cxx
index 4c6428321792..ea7a3643954b 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport3.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport3.cxx
@@ -1169,6 +1169,29 @@ DECLARE_OOXMLEXPORT_TEST(testRelativeAnchorWidthFromLeftMargin, "tdf132976_testR
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1133), nAnchoredWidth);
}
+DECLARE_OOXMLEXPORT_TEST(testRelativeAnchorWidthFromInsideOutsideMargin, "tdf133861_RelativeAnchorWidthFromInsideOutsideMargin.docx")
+{
+ // TODO: Fix export.
+ if (mbExported)
+ return;
+
+ // tdf#133863 tdf#133864 The sizes of the width of these shapes depend on the sizes of the inside and outside margins.
+ // The open book: outside --text-- inside | inside --text-- outside
+ xmlDocUniquePtr pXmlDoc = parseLayoutDump();
+ // Outside
+ sal_Int32 nAnchoredWidth = getXPath(pXmlDoc, "(//SwAnchoredDrawObject)[1]/bounds", "width").toInt32();
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2552), nAnchoredWidth);
+ // Inside
+ nAnchoredWidth = getXPath(pXmlDoc, "(//SwAnchoredDrawObject)[2]/bounds", "width").toInt32();
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1440), nAnchoredWidth);
+ // Inside
+ nAnchoredWidth = getXPath(pXmlDoc, "(//SwAnchoredDrawObject)[3]/bounds", "width").toInt32();
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1440), nAnchoredWidth);
+ // Outside
+ nAnchoredWidth = getXPath(pXmlDoc, "(//SwAnchoredDrawObject)[4]/bounds", "width").toInt32();
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2552), nAnchoredWidth);
+}
+
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/layout/anchoreddrawobject.cxx b/sw/source/core/layout/anchoreddrawobject.cxx
index 9b4bce8e44ef..1af32ed2fa80 100644
--- a/sw/source/core/layout/anchoreddrawobject.cxx
+++ b/sw/source/core/layout/anchoreddrawobject.cxx
@@ -620,6 +620,26 @@ SwRect SwAnchoredDrawObject::GetObjRect() const
return GetDrawObj()->GetSnapRect();
}
+namespace
+{
+ // Imagine an open book, inside margin is the one that is at the inner side of the pages, at the center of the book,
+ // outside margin is at the two opposite edges of the book.
+ // outside --text-- inside | inside --text-- outside
+ // With mirrored margins, when relating the size of an object from the inside margin for example, on the
+ // first page we calculate the new size of the object using the size of the right margin,
+ // on second page the left margin, third page right margin, etc.
+ long getInsideOutsideRelativeWidth(bool isOutside, const SwPageFrame* const pPageFrame)
+ {
+ // Alternating between the only two possible cases: inside and outside.
+ // Inside = false, Outside = true.
+ auto nPageNum = pPageFrame->GetPhyPageNum();
+ if (nPageNum % 2 == (isOutside ? 0 : 1))
+ return pPageFrame->GetRightMargin();
+ else
+ return pPageFrame->GetLeftMargin();
+ }
+}
+
// --> #i70122#
SwRect SwAnchoredDrawObject::GetObjBoundRect() const
{
@@ -640,10 +660,22 @@ SwRect SwAnchoredDrawObject::GetObjBoundRect() const
// The size of the shape's width is going to be relative to the size of the left margin.
// E.g.: (left margin = 8 && relative size = 150%) -> width of some shape = 12.
else if (GetDrawObj()->GetRelativeWidthRelation() == text::RelOrientation::PAGE_LEFT)
- nWidth = GetPageFrame()->GetLeftMargin();
+ {
+ if (GetPageFrame()->GetPageDesc()->GetUseOn() == UseOnPage::Mirror)
+ // We want to get the width of whatever is going through here using the size of the
+ // outside margin.
+ nWidth = getInsideOutsideRelativeWidth(true, GetPageFrame());
+ else
+ nWidth = GetPageFrame()->GetLeftMargin();
+ }
// Same as the left margin above.
else if (GetDrawObj()->GetRelativeWidthRelation() == text::RelOrientation::PAGE_RIGHT)
- nWidth = GetPageFrame()->GetRightMargin();
+ if (GetPageFrame()->GetPageDesc()->GetUseOn() == UseOnPage::Mirror)
+ // We want to get the width of whatever is going through here using the size of the
+ // inside margin.
+ nWidth = getInsideOutsideRelativeWidth(false, GetPageFrame());
+ else
+ nWidth = GetPageFrame()->GetRightMargin();
else
nWidth = GetPageFrame( )->GetBoundRect( GetPageFrame()->getRootFrame()->GetCurrShell()->GetOut() ).SVRect().GetWidth();
nTargetWidth = nWidth * (*GetDrawObj( )->GetRelativeWidth());
diff --git a/writerfilter/source/dmapper/GraphicImport.cxx b/writerfilter/source/dmapper/GraphicImport.cxx
index 7d4b0165d645..8286503ca114 100644
--- a/writerfilter/source/dmapper/GraphicImport.cxx
+++ b/writerfilter/source/dmapper/GraphicImport.cxx
@@ -946,6 +946,7 @@ void GraphicImport::lcl_attribute(Id nName, Value& rValue)
}
break;
case NS_ooxml::LN_ST_SizeRelFromH_leftMargin:
+ case NS_ooxml::LN_ST_SizeRelFromH_outsideMargin:
if (m_xShape.is())
{
// Here we handle the relative size of the width of some shape.
@@ -956,6 +957,7 @@ void GraphicImport::lcl_attribute(Id nName, Value& rValue)
}
break;
case NS_ooxml::LN_ST_SizeRelFromH_rightMargin:
+ case NS_ooxml::LN_ST_SizeRelFromH_insideMargin:
if (m_xShape.is())
{
// Same as the left margin above.