diff --git a/sw/qa/extras/ooxmlexport/data/tdf166141_linkedStyles.docx b/sw/qa/extras/ooxmlexport/data/tdf166141_linkedStyles.docx new file mode 100644 index 000000000000..72c18ad7abc9 Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf166141_linkedStyles.docx differ diff --git a/sw/qa/extras/ooxmlexport/data/tdf166141_linkedStyles2.docx b/sw/qa/extras/ooxmlexport/data/tdf166141_linkedStyles2.docx new file mode 100644 index 000000000000..f40c24703fc7 Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf166141_linkedStyles2.docx differ diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport25.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport25.cxx index 65e778abe675..33465e2c15c7 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport25.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport25.cxx @@ -44,6 +44,32 @@ DECLARE_OOXMLEXPORT_TEST(testTdf166544_noTopMargin_fields, "tdf166544_noTopMargi CPPUNIT_ASSERT_EQUAL(sal_Int32(269), nHeight); } +DECLARE_OOXMLEXPORT_TEST(testTdf166141_linkedStyles, "tdf166141_linkedStyles.docx") +{ + // Given a document with settings.xml containing both linkStyles and attachedTemplate + + // The problem was that there should not be any spacing between the two paragraphs, + // but there was 200 twips of below spacing. + + uno::Reference xStyle( + getStyles(u"ParagraphStyles"_ustr)->getByName(u"Standard"_ustr), uno::UNO_QUERY); + // Since the "template" to update the styles from doesn't exist, make no changes + // This was being forced to 200 twips by linkedStyles... + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty(xStyle, u"ParaBottomMargin"_ustr)); +} + +DECLARE_OOXMLEXPORT_TEST(testTdf166141_linkedStyles2, "tdf166141_linkedStyles2.docx") +{ + // Given a document with settings.xml containing only linkStyles - no attachedTemplate + + // Since no "template" was provided to update the styles from, + // the styles must be updated using the application defaults. + uno::Reference xStyle( + getStyles(u"ParagraphStyles"_ustr)->getByName(u"Standard"_ustr), uno::UNO_QUERY); + // This must be 200 twips / 0.35cm. + CPPUNIT_ASSERT_EQUAL(sal_Int32(353), getProperty(xStyle, u"ParaBottomMargin"_ustr)); +} + DECLARE_OOXMLEXPORT_TEST(testTdf166510_sectPr_bottomSpacing, "tdf166510_sectPr_bottomSpacing.docx") { // given with a sectPr with different bottom spacing (undefined in this case - i.e. zero) diff --git a/sw/source/writerfilter/dmapper/SettingsTable.cxx b/sw/source/writerfilter/dmapper/SettingsTable.cxx index e65d7b5cf86b..6cb991955af2 100644 --- a/sw/source/writerfilter/dmapper/SettingsTable.cxx +++ b/sw/source/writerfilter/dmapper/SettingsTable.cxx @@ -82,7 +82,6 @@ SettingsTable::SettingsTable(const DomainMapper& rDomainMapper) , m_bShowInsDelChanges(true) , m_bShowFormattingChanges(false) , m_bShowMarkupChanges(true) -, m_bLinkStyles(false) , m_nZoomFactor(0) , m_nWordCompatibilityMode(-1) , m_nView(0) @@ -217,6 +216,11 @@ void SettingsTable::lcl_sprm(Sprm& rSprm) //PropertySetValues - need to be resolved { resolveSprmProps(*this, rSprm); + + // If attached template cannot be located or is not a valid file, silently ignore linkStyles + // and since LO doesn't know how to update styles anyway, just always ignore linkStyles + if (nSprmId == NS_ooxml::LN_CT_Settings_attachedTemplate) + m_oLinkStyles = false; } break; case NS_ooxml::LN_CT_Settings_stylePaneFormatFilter: // 92493; @@ -225,7 +229,10 @@ void SettingsTable::lcl_sprm(Sprm& rSprm) m_nDefaultTabStop = nIntValue; break; case NS_ooxml::LN_CT_Settings_linkStyles: // 92663; - m_bLinkStyles = nIntValue; + { + if (!m_oLinkStyles.has_value()) + m_oLinkStyles = bool(nIntValue); + } break; case NS_ooxml::LN_CT_Settings_evenAndOddHeaders: m_bEvenAndOddHeaders = nIntValue; @@ -430,7 +437,7 @@ int SettingsTable::GetDefaultTabStop() const bool SettingsTable::GetLinkStyles() const { - return m_bLinkStyles; + return m_oLinkStyles.has_value() && *m_oLinkStyles; } sal_Int16 SettingsTable::GetZoomFactor() const diff --git a/sw/source/writerfilter/dmapper/SettingsTable.hxx b/sw/source/writerfilter/dmapper/SettingsTable.hxx index fd2f9efbc37d..0b322bea1b54 100644 --- a/sw/source/writerfilter/dmapper/SettingsTable.hxx +++ b/sw/source/writerfilter/dmapper/SettingsTable.hxx @@ -23,6 +23,7 @@ #include #include #include +#include class SwXTextDocument; namespace com::sun::star::lang @@ -122,7 +123,7 @@ private: bool m_bShowInsDelChanges; bool m_bShowFormattingChanges; bool m_bShowMarkupChanges; - bool m_bLinkStyles; + std::optional m_oLinkStyles; sal_Int16 m_nZoomFactor; sal_Int16 m_nZoomType = 0; sal_Int32 m_nWordCompatibilityMode;