From bf3124cdf61b40c94ba117a76f1b63dabdfd528e Mon Sep 17 00:00:00 2001 From: László Németh Date: Wed, 19 Aug 2020 13:00:58 +0200 Subject: tdf#135187 DOCX import: fix table style at character formatting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit applied also on paragraph level during import. Regression from commit 4d5c0eaf3e0d3d3bcd9e691fffee19b75f3d6631 (tdf#118812 DOCX import: fix table style preference – part 2) See also commit 5ac6f02fdc6015a5d78071570dee310febf95fc6 (tdf#105215 DOCX import: fix paragraph-length direct formatting). Change-Id: I14072c81fc4c54e376a004fa36ba76b56d2beb01 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100996 Tested-by: László Németh Reviewed-by: László Németh --- sw/qa/extras/ooxmlexport/data/tdf135187.docx | Bin 0 -> 19696 bytes sw/qa/extras/ooxmlexport/ooxmlexport11.cxx | 17 +++++++++++++++++ .../source/dmapper/DomainMapperTableHandler.cxx | 12 +++++++++++- writerfilter/source/dmapper/DomainMapper_Impl.cxx | 4 +++- writerfilter/source/dmapper/PropertyMap.hxx | 2 ++ 5 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 sw/qa/extras/ooxmlexport/data/tdf135187.docx diff --git a/sw/qa/extras/ooxmlexport/data/tdf135187.docx b/sw/qa/extras/ooxmlexport/data/tdf135187.docx new file mode 100644 index 000000000000..98a151048f08 Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf135187.docx differ diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx index bc80088f7a94..a80b76a21223 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx @@ -1222,6 +1222,23 @@ DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testTdf105215, "tdf105215.docx") assertXPath(pXmlDoc, "/w:document/w:body/w:tbl/w:tr/w:tc/w:p/w:r[5]/w:rPr/w:rFonts", "ascii", "Lohit Devanagari"); } +DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testTdf135187, "tdf135187.docx") +{ + xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml"); + assertXPath(pXmlDoc, "/w:document/w:body/w:tbl/w:tr[2]/w:tc[1]/w:p/w:pPr/w:rPr/w:b", 0); + // FIXME: remove duplicate + assertXPath(pXmlDoc, "/w:document/w:body/w:tbl/w:tr[3]/w:tc[1]/w:p/w:pPr/w:rPr/w:b", 2); + assertXPath(pXmlDoc, "/w:document/w:body/w:tbl/w:tr[4]/w:tc[1]/w:p/w:pPr/w:rPr/w:b", 2); + + assertXPath(pXmlDoc, "/w:document/w:body/w:tbl/w:tr[2]/w:tc[1]/w:p/w:r[1]/w:rPr/w:b", 1); + assertXPathNoAttribute(pXmlDoc, "/w:document/w:body/w:tbl/w:tr[2]/w:tc[1]/w:p/w:r[1]/w:rPr/w:b", "val"); + // This was 0 + assertXPath(pXmlDoc, "/w:document/w:body/w:tbl/w:tr[3]/w:tc[1]/w:p/w:r[1]/w:rPr/w:b", 1); + assertXPathNoAttribute(pXmlDoc, "/w:document/w:body/w:tbl/w:tr[3]/w:tc[1]/w:p/w:r[1]/w:rPr/w:b", "val"); + assertXPath(pXmlDoc, "/w:document/w:body/w:tbl/w:tr[4]/w:tc[1]/w:p/w:r[1]/w:rPr/w:b", 1); + assertXPath(pXmlDoc, "/w:document/w:body/w:tbl/w:tr[4]/w:tc[1]/w:p/w:r[1]/w:rPr/w:b", "val", "false"); +} + DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testTdf121597TrackedDeletionOfMultipleParagraphs, "tdf121597.odt") { CPPUNIT_ASSERT_EQUAL(1, getPages()); diff --git a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx index b44325fa06d3..02baba345d58 100644 --- a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx +++ b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx @@ -1094,7 +1094,8 @@ void DomainMapperTableHandler::ApplyParagraphPropertiesFromTableStyle(TableParag { // apply paragraph and character properties of the table style on table paragraphs // if there is no direct paragraph formatting - if ( !rParaProp.m_pPropertyMap->isSet(eId) ) + bool bIsParaLevel = rParaProp.m_pPropertyMap->isSet(eId); + if ( !bIsParaLevel || isCharacterProperty(eId) ) { if ( (eId == PROP_PARA_LEFT_MARGIN || eId == PROP_PARA_FIRST_LINE_INDENT) && rParaProp.m_pPropertyMap->isSet(PROP_NUMBERING_RULES) ) @@ -1104,6 +1105,15 @@ void DomainMapperTableHandler::ApplyParagraphPropertiesFromTableStyle(TableParag } OUString sPropertyName = getPropertyName(eId); + + if ( bIsParaLevel && ( rParaProp.m_aParaOverrideApplied.find(sPropertyName) != rParaProp.m_aParaOverrideApplied.end() || + sPropertyName.startsWith("CharFontName") ) ) + { + // don't apply table style, if this character property was applied on paragraph level + // (or in the case of paragraph level font name settings to avoid regressions) + continue; + } + auto pCellProp = std::find_if(rCellProperties.begin(), rCellProperties.end(), [&](const beans::PropertyValue& rProp) { return rProp.Name == sPropertyName; }); // this cell applies the table style property diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx index 333f1170ea09..d720e53a2a53 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx @@ -1877,7 +1877,7 @@ void DomainMapper_Impl::finishParagraph( const PropertyMapPtr& pPropertyMap, con xParaCursor->gotoStartOfParagraph(false); if (m_nTableDepth > 0) { - TableParagraph aPending{xParaCursor, xCur, pParaContext, xParaProps}; + TableParagraph aPending{xParaCursor, xCur, pParaContext, xParaProps, std::set()}; getTableManager().getCurrentParagraphs()->push_back(aPending); } @@ -1995,6 +1995,8 @@ void DomainMapper_Impl::finishParagraph( const PropertyMapPtr& pPropertyMap, con { uno::Reference xRunPropertySet(xCur, uno::UNO_QUERY); xParaProps->setPropertyValue( rParaProp.Name, xRunPropertySet->getPropertyValue(rParaProp.Name) ); + // remember this for table style handling + getTableManager().getCurrentParagraphs()->back().m_aParaOverrideApplied.insert(rParaProp.Name); } } diff --git a/writerfilter/source/dmapper/PropertyMap.hxx b/writerfilter/source/dmapper/PropertyMap.hxx index 0ac658f7674d..c48d52803ee1 100644 --- a/writerfilter/source/dmapper/PropertyMap.hxx +++ b/writerfilter/source/dmapper/PropertyMap.hxx @@ -33,6 +33,7 @@ #include #include #include +#include namespace com::sun::star { namespace beans { @@ -594,6 +595,7 @@ struct TableParagraph css::uno::Reference m_rEndParagraph; PropertyMapPtr m_pPropertyMap; css::uno::Reference m_rPropertySet; + std::set m_aParaOverrideApplied; }; typedef std::shared_ptr< std::vector > TableParagraphVectorPtr; -- cgit v1.2.3