summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2018-03-17 23:49:37 +0300
committerAron Budea <aron.budea@collabora.com>2018-03-23 00:25:59 +0100
commiteea91d8f4baeb7ce1d22ea695c4f84a9186b6634 (patch)
tree3cf69a7c74d27c07fd80881f4a578d9892ec7c62
parent67e89d90731df5379173eb561512fd6cdc38c37d (diff)
tdf#112118: Use correct border when calculating margin
This is a longstanding (at least since 2000: already present in commit 7b0b5cdf) error where left border linespace was used when calculating right margin. It was copypasted from ww8 import to ooxml code verbatim. The problem only manifests itself when left and right border spacings are not the same; and since we had other errors in the borders import, that additional problem simply wasn't apparent. Also use scaled border width in border distance/margin calculations. Unit tests updated. Change-Id: I70961e1bde29471def69e1ef944ba2779cffe307 Reviewed-on: https://gerrit.libreoffice.org/51474 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/51489 Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk> Tested-by: Miklos Vajna <vmiklos@collabora.co.uk> Reviewed-on: https://gerrit.libreoffice.org/51688 Reviewed-by: Aron Budea <aron.budea@collabora.com> Tested-by: Aron Budea <aron.budea@collabora.com>
-rw-r--r--editeng/source/items/frmitems.cxx8
-rw-r--r--sw/qa/extras/ooxmlexport/data/tdf112118.docxbin11672 -> 11702 bytes
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlexport9.cxx77
-rw-r--r--sw/qa/extras/ww8export/data/tdf112118.docbin27136 -> 26624 bytes
-rw-r--r--sw/qa/extras/ww8export/ww8export2.cxx74
-rw-r--r--sw/source/core/tox/ToxTabStopTokenHandler.cxx4
-rw-r--r--sw/source/filter/ww8/docxattributeoutput.cxx4
-rw-r--r--sw/source/filter/ww8/ww8atr.cxx4
-rw-r--r--sw/source/filter/ww8/ww8par6.cxx2
9 files changed, 108 insertions, 65 deletions
diff --git a/editeng/source/items/frmitems.cxx b/editeng/source/items/frmitems.cxx
index b6494b764e01..a82259546566 100644
--- a/editeng/source/items/frmitems.cxx
+++ b/editeng/source/items/frmitems.cxx
@@ -2984,10 +2984,10 @@ void BorderDistancesToWord(const SvxBoxItem& rBox, const WordPageMargins& rMargi
const SvxBorderLine* pLnR = rBox.GetLine(SvxBoxItemLine::RIGHT);
// We need to take border widths into account
- const long nWidthT = pLnT ? pLnT->GetWidth() : 0;
- const long nWidthL = pLnL ? pLnL->GetWidth() : 0;
- const long nWidthB = pLnB ? pLnB->GetWidth() : 0;
- const long nWidthR = pLnR ? pLnR->GetWidth() : 0;
+ const long nWidthT = pLnT ? pLnT->GetScaledWidth() : 0;
+ const long nWidthL = pLnL ? pLnL->GetScaledWidth() : 0;
+ const long nWidthB = pLnB ? pLnB->GetScaledWidth() : 0;
+ const long nWidthR = pLnR ? pLnR->GetScaledWidth() : 0;
// Resulting distances from text to borders
const sal_Int32 nT2BT = pLnT ? nT : 0;
diff --git a/sw/qa/extras/ooxmlexport/data/tdf112118.docx b/sw/qa/extras/ooxmlexport/data/tdf112118.docx
index dc3e14ae82c7..3ddb06839492 100644
--- a/sw/qa/extras/ooxmlexport/data/tdf112118.docx
+++ b/sw/qa/extras/ooxmlexport/data/tdf112118.docx
Binary files differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx
index ddd2ae8b35b1..d1327a5216fb 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx
@@ -650,38 +650,63 @@ DECLARE_OOXMLEXPORT_TEST(testGraphicObjectFliph, "graphic-object-fliph.docx")
DECLARE_OOXMLEXPORT_TEST(testTdf112118_DOCX, "tdf112118.docx")
{
- auto xStyles = getStyles("PageStyles");
- const std::initializer_list<OUStringLiteral> sides = {
- OUStringLiteral("Top"),
- OUStringLiteral("Left"),
- OUStringLiteral("Bottom"),
- OUStringLiteral("Right")
+ // The resulting left margin width (2081) differs from its DOC counterpart from ww8export2.cxx,
+ // because DOCX import does two conversions between mm/100 and twips on the route, loosing one
+ // twip on the road and arriving with a value that is 2 mm/100 less. I don't see an obvious way
+ // to avoid that.
+ struct {
+ const char* styleName;
+ struct {
+ const char* sideName;
+ sal_Int32 nMargin;
+ sal_Int32 nBorderDistance;
+ sal_Int32 nBorderWidth;
+ } sideParams[4];
+ } const styleParams[] = { // Margin (MS-style), border distance, border width
+ {
+ "Standard",
+ {
+ { "Top", 496, 847, 159 }, // 851 twip, 24 pt (from text), 4.5 pt
+ { "Left", 2081, 706, 212 }, // 1701 twip, 20 pt (from text), 6.0 pt
+ { "Bottom", 1401, 564, 35 }, // 1134 twip, 16 pt (from text), 1.0 pt
+ { "Right", 3471, 423, 106 } // 2268 twip, 12 pt (from text), 3.0 pt
+ }
+ },
+ {
+ "Converted1",
+ {
+ { "Top", 847, 496, 159 }, // 851 twip, 24 pt (from edge), 4.5 pt
+ { "Left", 706, 2081, 212 }, // 1701 twip, 20 pt (from edge), 6.0 pt
+ { "Bottom", 564, 1401, 35 }, // 1134 twip, 16 pt (from edge), 1.0 pt
+ { "Right", 423, 3471, 106 } // 2268 twip, 12 pt (from edge), 3.0 pt
+ }
+ }
};
- auto testProc = [&](const OUString& sStyleName, sal_Int32 nMargin, sal_Int32 nBorderDistance,
- sal_Int16 nBorderWidth)
+ auto xStyles = getStyles("PageStyles");
+
+ for (const auto& style : styleParams)
{
- uno::Reference<beans::XPropertySet> xStyle(xStyles->getByName(sStyleName), uno::UNO_QUERY_THROW);
- for (const auto& side : sides)
+ const OUString sName = OUString::createFromAscii(style.styleName);
+ uno::Reference<beans::XPropertySet> xStyle(xStyles->getByName(sName), uno::UNO_QUERY_THROW);
+ for (const auto& side : style.sideParams)
{
- table::BorderLine aBorder = getProperty<table::BorderLine>(xStyle, side + "Border");
- CPPUNIT_ASSERT_EQUAL(sal_Int16(nBorderWidth), aBorder.OuterLineWidth);
- CPPUNIT_ASSERT_EQUAL(sal_Int16(0), aBorder.InnerLineWidth);
- CPPUNIT_ASSERT_EQUAL(sal_Int16(0), aBorder.LineDistance);
+ const OUString sSide = OUString::createFromAscii(side.sideName);
+ const OString sStage = OString(style.styleName) + " " + side.sideName;
- sal_Int32 nMarginActual = getProperty<sal_Int32>(xStyle, side + "Margin");
- CPPUNIT_ASSERT_EQUAL(nMargin, nMarginActual);
+ sal_Int32 nMargin = getProperty<sal_Int32>(xStyle, sSide + "Margin");
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(OString(sStage + " margin width").getStr(),
+ side.nMargin, nMargin);
- sal_Int32 nBorderDistanceActual = getProperty<sal_Int32>(xStyle, side + "BorderDistance");
- CPPUNIT_ASSERT_EQUAL(nBorderDistance, nBorderDistanceActual);
- }
- };
+ sal_Int32 nBorderDistance = getProperty<sal_Int32>(xStyle, sSide + "BorderDistance");
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(OString(sStage + " border distance").getStr(),
+ side.nBorderDistance, nBorderDistance);
- // For both styles used in document, the total distance from page edge to text must be 2.54 cm.
- // The first style uses "from edge" border distance; the second uses "from text" border distance
- // Border distances in both cases are 24 pt = 847 mm100; line widths are 6 pt = 212 mm100.
- // 1482 + 847 + 212 = 2541
- testProc("Standard", 847, 1482, 212);
- testProc("Converted1", 1482, 847, 212);
+ table::BorderLine aBorder = getProperty<table::BorderLine>(xStyle, sSide + "Border");
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(OString(sStage + " border width").getStr(),
+ side.nBorderWidth,
+ sal_Int32(aBorder.OuterLineWidth + aBorder.InnerLineWidth + aBorder.LineDistance));
+ }
+ }
}
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/qa/extras/ww8export/data/tdf112118.doc b/sw/qa/extras/ww8export/data/tdf112118.doc
index 3c8e256407ad..f1aaa9b54d82 100644
--- a/sw/qa/extras/ww8export/data/tdf112118.doc
+++ b/sw/qa/extras/ww8export/data/tdf112118.doc
Binary files differ
diff --git a/sw/qa/extras/ww8export/ww8export2.cxx b/sw/qa/extras/ww8export/ww8export2.cxx
index 9e712b13a68a..f86982239640 100644
--- a/sw/qa/extras/ww8export/ww8export2.cxx
+++ b/sw/qa/extras/ww8export/ww8export2.cxx
@@ -198,39 +198,59 @@ DECLARE_WW8EXPORT_TEST(testTdf67207_MERGEFIELD, "mailmerge.doc")
DECLARE_WW8EXPORT_TEST(testTdf112118_DOC, "tdf112118.doc")
{
- auto xStyles = getStyles("PageStyles");
- const std::initializer_list<OUStringLiteral> sides = {
- OUStringLiteral("Top"),
- OUStringLiteral("Left"),
- OUStringLiteral("Bottom"),
- OUStringLiteral("Right")
+ struct {
+ const char* styleName;
+ struct {
+ const char* sideName;
+ sal_Int32 nMargin;
+ sal_Int32 nBorderDistance;
+ sal_Int32 nBorderWidth;
+ } sideParams[4];
+ } const styleParams[] = { // Margin (MS-style), border distance, border width
+ {
+ "Standard",
+ {
+ { "Top", 496, 847, 159 }, // 851 twip, 24 pt (from text), 4.5 pt
+ { "Left", 2083, 706, 212 }, // 1701 twip, 20 pt (from text), 6.0 pt
+ { "Bottom", 1401, 564, 35 }, // 1134 twip, 16 pt (from text), 1.0 pt
+ { "Right", 3471, 423, 106 } // 2268 twip, 12 pt (from text), 3.0 pt
+ }
+ },
+ {
+ "Convert 1",
+ {
+ { "Top", 847, 496, 159 }, // 851 twip, 24 pt (from edge), 4.5 pt
+ { "Left", 706, 2083, 212 }, // 1701 twip, 20 pt (from edge), 6.0 pt
+ { "Bottom", 564, 1401, 35 }, // 1134 twip, 16 pt (from edge), 1.0 pt
+ { "Right", 423, 3471, 106 } // 2268 twip, 12 pt (from edge), 3.0 pt
+ }
+ }
};
- auto testProc = [&](const OUString& sStyleName, sal_Int32 nMargin, sal_Int32 nBorderDistance,
- sal_Int16 nBorderWidth)
+ auto xStyles = getStyles("PageStyles");
+
+ for (const auto& style : styleParams)
{
- typedef std::initializer_list<OUStringLiteral> StringList;
- uno::Reference<beans::XPropertySet> xStyle(xStyles->getByName(sStyleName), uno::UNO_QUERY_THROW);
- for (const auto& side : sides)
+ const OUString sName = OUString::createFromAscii(style.styleName);
+ uno::Reference<beans::XPropertySet> xStyle(xStyles->getByName(sName), uno::UNO_QUERY_THROW);
+ for (const auto& side : style.sideParams)
{
- table::BorderLine aBorder = getProperty<table::BorderLine>(xStyle, side + "Border");
- CPPUNIT_ASSERT_EQUAL(sal_Int16(nBorderWidth), aBorder.OuterLineWidth);
- CPPUNIT_ASSERT_EQUAL(sal_Int16(0), aBorder.InnerLineWidth);
- CPPUNIT_ASSERT_EQUAL(sal_Int16(0), aBorder.LineDistance);
+ const OUString sSide = OUString::createFromAscii(side.sideName);
+ const OString sStage = OString(style.styleName) + " " + side.sideName;
- sal_Int32 nMarginActual = getProperty<sal_Int32>(xStyle, side + "Margin");
- CPPUNIT_ASSERT_EQUAL(nMargin, nMarginActual);
+ sal_Int32 nMargin = getProperty<sal_Int32>(xStyle, sSide + "Margin");
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(OString(sStage + " margin width").getStr(),
+ side.nMargin, nMargin);
- sal_Int32 nBorderDistanceActual = getProperty<sal_Int32>(xStyle, side + "BorderDistance");
- CPPUNIT_ASSERT_EQUAL(nBorderDistance, nBorderDistanceActual);
- }
- };
+ sal_Int32 nBorderDistance = getProperty<sal_Int32>(xStyle, sSide + "BorderDistance");
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(OString(sStage + " border distance").getStr(),
+ side.nBorderDistance, nBorderDistance);
- // For both styles used in document, the total distance from page edge to text must be 2.54 cm.
- // The first style uses "from edge" border distance; the second uses "from text" border distance
- // Border distances in both cases are 24 pt = 847 mm100; line widths are 6 pt = 212 mm100.
- // 1482 + 847 + 212 = 2541
- testProc("Standard", 847, 1482, 212);
- testProc("Convert 1", 1482, 847, 212);
+ table::BorderLine aBorder = getProperty<table::BorderLine>(xStyle, sSide + "Border");
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(OString(sStage + " border width").getStr(),
+ side.nBorderWidth,
+ sal_Int32(aBorder.OuterLineWidth + aBorder.InnerLineWidth + aBorder.LineDistance));
+ }
+ }
}
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/core/tox/ToxTabStopTokenHandler.cxx b/sw/source/core/tox/ToxTabStopTokenHandler.cxx
index 53bae640e396..6360dfe6f91c 100644
--- a/sw/source/core/tox/ToxTabStopTokenHandler.cxx
+++ b/sw/source/core/tox/ToxTabStopTokenHandler.cxx
@@ -95,9 +95,7 @@ DefaultToxTabStopTokenHandler::CalculatePageMarginFromPageDescription(const SwTe
- rPgDscFormat.GetLRSpace().GetRight();
// Also consider borders
const SvxBoxItem& rBox = rPgDscFormat.GetBox();
- for (SvxBoxItemLine eLine : { SvxBoxItemLine::LEFT, SvxBoxItemLine::RIGHT })
- if (const editeng::SvxBorderLine* pBorder = rBox.GetLine(eLine))
- result -= pBorder->GetWidth() + rBox.GetDistance(eLine);
+ result -= rBox.CalcLineSpace(SvxBoxItemLine::LEFT) + rBox.CalcLineSpace(SvxBoxItemLine::RIGHT);
return result;
}
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index 824ea4498100..859b9925ae65 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -7440,8 +7440,8 @@ void DocxAttributeOutput::FormatLRSpace( const SvxLRSpaceItem& rLRSpace )
if ( auto pBoxItem = static_cast<const SvxBoxItem*>(m_rExport.HasItem( RES_BOX )) )
{
- m_pageMargins.nRight = pBoxItem->CalcLineSpace( SvxBoxItemLine::LEFT, /*bEvenIfNoLine*/true );
- m_pageMargins.nLeft = pBoxItem->CalcLineSpace( SvxBoxItemLine::RIGHT, /*bEvenIfNoLine*/true );
+ m_pageMargins.nLeft = pBoxItem->CalcLineSpace( SvxBoxItemLine::LEFT, /*bEvenIfNoLine*/true );
+ m_pageMargins.nRight = pBoxItem->CalcLineSpace( SvxBoxItemLine::RIGHT, /*bEvenIfNoLine*/true );
}
m_pageMargins.nLeft += sal::static_int_cast<sal_uInt16>(rLRSpace.GetLeft());
diff --git a/sw/source/filter/ww8/ww8atr.cxx b/sw/source/filter/ww8/ww8atr.cxx
index 67a4655c0081..7c36f4977faa 100644
--- a/sw/source/filter/ww8/ww8atr.cxx
+++ b/sw/source/filter/ww8/ww8atr.cxx
@@ -3685,8 +3685,8 @@ void WW8AttributeOutput::FormatLRSpace( const SvxLRSpaceItem& rLR )
if ( auto pBoxItem = static_cast<const SvxBoxItem*>(m_rWW8Export.HasItem( RES_BOX )) )
{
- m_pageMargins.nRight = pBoxItem->CalcLineSpace( SvxBoxItemLine::LEFT, /*bEvenIfNoLine*/true );
- m_pageMargins.nLeft = pBoxItem->CalcLineSpace( SvxBoxItemLine::RIGHT, /*bEvenIfNoLine*/true );
+ m_pageMargins.nLeft = pBoxItem->CalcLineSpace( SvxBoxItemLine::LEFT, /*bEvenIfNoLine*/true );
+ m_pageMargins.nRight = pBoxItem->CalcLineSpace( SvxBoxItemLine::RIGHT, /*bEvenIfNoLine*/true );
}
m_pageMargins.nLeft += sal::static_int_cast<sal_uInt16>(rLR.GetLeft());
diff --git a/sw/source/filter/ww8/ww8par6.cxx b/sw/source/filter/ww8/ww8par6.cxx
index 6241020e486f..e47413fd1906 100644
--- a/sw/source/filter/ww8/ww8par6.cxx
+++ b/sw/source/filter/ww8/ww8par6.cxx
@@ -439,7 +439,7 @@ long SetBorderDistance(bool bFromEdge, SvxBoxItem& aBox, SvxBoxItemLine eLine, l
return nMSMargin;
sal_Int32 nNewMargin = nMSMargin;
sal_Int32 nNewDist = aBox.GetDistance(eLine);
- sal_Int32 nLineWidth = pLine->GetWidth();
+ sal_Int32 nLineWidth = pLine->GetScaledWidth();
editeng::BorderDistanceFromWord(bFromEdge, nNewMargin, nNewDist, nLineWidth);
aBox.SetDistance(nNewDist, eLine);