tdf#133863 tdf#133864 DOCX shape import: width relative to inside
and outside margins. See commit43d7f4e364(offapi: document the 4 new properties which are no longer read-only). commitb46f4bc976(tdf#133070 DOCX import: fix shape height relative to bottom page margin) commit330ed8120e(tdf#133670 DOCX import: fix shape width relative to right margin) commit7380905abc(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>
This commit is contained in:
committed by
László Németh
co-authored by
Szabolcs Tóth
parent
b8db739c20
commit
d63321d949
BIN
Binary file not shown.
@@ -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: */
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user