editeng/source/items/frmitems.cxx | 8 +- sw/qa/extras/ooxmlexport/data/tdf112118.docx |binary sw/qa/extras/ooxmlexport/ooxmlexport11.cxx | 72 ++++++++++++++++++-------- sw/qa/extras/ww8export/data/tdf112118.doc |binary sw/qa/extras/ww8export/ww8export2.cxx | 68 ++++++++++++++++-------- sw/source/core/tox/ToxTabStopTokenHandler.cxx | 4 - sw/source/filter/ww8/docxattributeoutput.cxx | 4 - sw/source/filter/ww8/ww8atr.cxx | 4 - sw/source/filter/ww8/ww8par6.cxx | 2 9 files changed, 108 insertions(+), 54 deletions(-)
New commits: commit 45f1b733e0f736f4db677ba1fd17695ac1009c9f Author: Mike Kaganski <mike.kagan...@collabora.com> Date: Sat Mar 17 23:49:37 2018 +0300 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 <c...@libreoffice.org> Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> diff --git a/editeng/source/items/frmitems.cxx b/editeng/source/items/frmitems.cxx index 6b60d5a4ffaa..7339035a6500 100644 --- a/editeng/source/items/frmitems.cxx +++ b/editeng/source/items/frmitems.cxx @@ -2661,10 +2661,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 Binary files a/sw/qa/extras/ooxmlexport/data/tdf112118.docx and b/sw/qa/extras/ooxmlexport/data/tdf112118.docx differ diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx index ba89b63b2f6e..5990e635394a 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx @@ -283,33 +283,63 @@ DECLARE_OOXMLEXPORT_TEST(testTdf107035, "tdf107035.docx") DECLARE_OOXMLEXPORT_TEST(testTdf112118_DOCX, "tdf112118.docx") { + // 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]; + } 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 xStyles = getStyles("PageStyles"); - auto testProc = [&](const OUString& sStyleName, sal_Int32 nMargin, sal_Int32 nBorderDistance, - sal_Int16 nBorderWidth) + + 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 : StringList{ "Top", "Left", "Bottom", "Right" }) + 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 Binary files a/sw/qa/extras/ww8export/data/tdf112118.doc and b/sw/qa/extras/ww8export/data/tdf112118.doc differ diff --git a/sw/qa/extras/ww8export/ww8export2.cxx b/sw/qa/extras/ww8export/ww8export2.cxx index 4bb2947aef78..2f2ca8200086 100644 --- a/sw/qa/extras/ww8export/ww8export2.cxx +++ b/sw/qa/extras/ww8export/ww8export2.cxx @@ -743,33 +743,59 @@ DECLARE_OOXMLEXPORT_TEST( testObjectCrossReference, "object_cross_reference.odt" DECLARE_WW8EXPORT_TEST(testTdf112118_DOC, "tdf112118.doc") { + struct { + const char* styleName; + struct { + const char* sideName; + sal_Int32 nMargin; + sal_Int32 nBorderDistance; + sal_Int32 nBorderWidth; + } sideParams[4]; + } 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 xStyles = getStyles("PageStyles"); - auto testProc = [&](const OUString& sStyleName, sal_Int32 nMargin, sal_Int32 nBorderDistance, - sal_Int16 nBorderWidth) + + 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 : StringList{ "Top", "Left", "Bottom", "Right" }) + 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 3fd3abb8abb1..0efd0125a1e1 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 fd8750dfb1ac..2cdd6670dc0e 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -7906,8 +7906,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 9f1419f75209..285716d280cc 100644 --- a/sw/source/filter/ww8/ww8atr.cxx +++ b/sw/source/filter/ww8/ww8atr.cxx @@ -3964,8 +3964,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 5e8341e88060..a476a800dc93 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); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits