sw/qa/extras/unowriter/data/table-line-spacing.docx |binary sw/qa/extras/unowriter/unowriter.cxx | 25 ++++++++++++++++++++ sw/source/core/unocore/unotbl.cxx | 11 ++++++++ 3 files changed, 35 insertions(+), 1 deletion(-)
New commits: commit c424a1f509205cfbaa3421bddfd6514b340a798a Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Thu Oct 3 17:24:21 2019 +0200 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Thu Oct 3 18:16:26 2019 +0200 DOCX import: fix interaction of table and paragraph style in table cells Both table and paragraph styles can define paragraph properties for the content of table cells, e.g. line spacing. The intended behavior is that direct formatting has priority, then paragraph style, then the table styles. But in practice table style had priority: table style is turned into a set of property name-value pairs by writerfilter/ code, then this is applied to the content of a cell using SwXCell::setPropertyValue(). To make sure that direct-format-from-table-style doesn't override direct-format, there was already a check to not replace properties which are set directly. The problem is that in case the property value comes from a paragraph style, that's not direct and still should have priority over direct-format-from-table-style. Fix this by checking for custom values not only in the paragraph's item set, but also in its parents. Unless the parent would be the default style, which doesn't count. Or in case the paragraph is numbered, which complicates the situation, so leave that case unchanged. Change-Id: Ib554247cdc51fee0d9a6c7a26aecd38442dfa692 Reviewed-on: https://gerrit.libreoffice.org/80146 Reviewed-by: Miklos Vajna <vmik...@collabora.com> Tested-by: Jenkins diff --git a/sw/qa/extras/unowriter/data/table-line-spacing.docx b/sw/qa/extras/unowriter/data/table-line-spacing.docx new file mode 100644 index 000000000000..60621f03cadb Binary files /dev/null and b/sw/qa/extras/unowriter/data/table-line-spacing.docx differ diff --git a/sw/qa/extras/unowriter/unowriter.cxx b/sw/qa/extras/unowriter/unowriter.cxx index e16562372bc3..f1b2b7671cdf 100644 --- a/sw/qa/extras/unowriter/unowriter.cxx +++ b/sw/qa/extras/unowriter/unowriter.cxx @@ -17,6 +17,7 @@ #include <com/sun/star/awt/XDevice.hpp> #include <com/sun/star/awt/XToolkit.hpp> #include <com/sun/star/graphic/XGraphic.hpp> +#include <com/sun/star/style/LineSpacing.hpp> #include <comphelper/propertyvalue.hxx> #include <toolkit/helper/vclunohelper.hxx> #include <vcl/graphicfilter.hxx> @@ -670,6 +671,30 @@ CPPUNIT_TEST_FIXTURE(SwUnoWriter, testShapeAllowOverlap) CPPUNIT_ASSERT(getProperty<bool>(xShapeProperties, "AllowOverlap")); } +CPPUNIT_TEST_FIXTURE(SwUnoWriter, testTextConvertToTableLineSpacing) +{ + // Load a document which has a table with a single cell. + // The cell has both a table style and a paragraph style, with different line spacing + // heights. + load(mpTestDocumentPath, "table-line-spacing.docx"); + uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XIndexAccess> xTables(xTablesSupplier->getTextTables(), + uno::UNO_QUERY); + uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY); + uno::Reference<table::XCell> xCell = xTable->getCellByName("A1"); + uno::Reference<text::XText> xCellText(xCell, uno::UNO_QUERY); + uno::Reference<text::XTextRange> xParagraph = getParagraphOfText(1, xCellText); + style::LineSpacing aLineSpacing + = getProperty<style::LineSpacing>(xParagraph, "ParaLineSpacing"); + // Make sure that we take the line spacing from the paragraph style, not from the table style. + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 388 + // - Actual : 635 + // I.e. the 360 twips line spacing was taken from the table style, not the 220 twips one from + // the paragraph style. + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int16>(convertTwipToMm100(220)), aLineSpacing.Height); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/unocore/unotbl.cxx b/sw/source/core/unocore/unotbl.cxx index 8cdddc8d72d2..1ad6dc454657 100644 --- a/sw/source/core/unocore/unotbl.cxx +++ b/sw/source/core/unocore/unotbl.cxx @@ -115,6 +115,7 @@ #include <docsh.hxx> #include <fesh.hxx> #include <itabenum.hxx> +#include <poolfmt.hxx> using namespace ::com::sun::star; using ::editeng::SvxBorderLine; @@ -1030,8 +1031,16 @@ void SwXCell::setPropertyValue(const OUString& rPropertyName, const uno::Any& aV const bool bHasAttrSet = pNd->HasSwAttrSet(); const SfxItemSet& aSet = pNd->GetSwAttrSet(); // isPARATR: replace DEFAULT_VALUE properties only + // Require that the property is default in the paragraph style as well, + // unless the style is the default style. // isCHRATR: change the base/auto SwAttr property, but don't remove the DIRECT hints - if ( !bHasAttrSet || SfxItemState::DEFAULT == aSet.GetItemState(pEntry->nWID, /*bSrchInParent=*/false) ) + bool bCustomParent = false; + if (const SwFormatColl* pFormatColl = pNd->GetFormatColl()) + { + bCustomParent = pFormatColl->GetPoolFormatId() != RES_POOLCOLL_STANDARD; + } + bool bSearchInParent = bCustomParent && !pNd->GetNumRule(); + if ( !bHasAttrSet || SfxItemState::DEFAULT == aSet.GetItemState(pEntry->nWID, bSearchInParent) ) SwUnoCursorHelper::SetPropertyValue(aPaM, rParaPropSet, rPropertyName, aValue, SetAttrMode::DONTREPLACE); } ++aIdx; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits