sw/qa/extras/ooxmlexport/data/tdf166141_linkedStyles.docx |binary sw/qa/extras/ooxmlexport/data/tdf166141_linkedStyles2.docx |binary sw/qa/extras/ooxmlexport/ooxmlexport25.cxx | 26 +++++++++++++ sw/source/writerfilter/dmapper/SettingsTable.cxx | 13 +++++- sw/source/writerfilter/dmapper/SettingsTable.hxx | 3 + 5 files changed, 38 insertions(+), 4 deletions(-)
New commits: commit bf326cd72905df985a1f150dbaabf4470fb5aabb Author: Justin Luth <[email protected]> AuthorDate: Mon Jun 23 13:35:15 2025 -0400 Commit: Justin Luth <[email protected]> CommitDate: Tue Jun 24 14:23:26 2025 +0200 tdf#166141 writerfilter docx: linkStyles != 0.35cm bottom margin 17.15.1.55 linkStyles (Automatically Update Styles From Document Template) This element specifies that styles in the given document shall be updated to match the styles in the attached template specified using the attachedTemplate element (§17.15.1.6) when the document is opened by a hosting application. This setting enables the styles contained in documents with attached templates to stay synchronized with the styles used in the attached template. <the key part is this> "If the attached template cannot be located or is not a valid file, then this setting should be silently ignored." This was added probably in LO 3.6 for a Novell bug for n751020.rtf. If there is no attachedTemplate provided, then yes - we need to update styles using Word's application defaults, but if an attachedTemplate is referenced, then we need to update the styles using that template. Since of course LO don't support updating styles from another file and almost certainly would not have that template available anyway, just ignore linkStyles when a template is specified. make CppunitTest_sw_ooxmlexport25 \ CPPUNIT_TEST_NAME=testTdf166141_linkedStyles Change-Id: I5ec2f0abeb8073c3caa9a579ba338f30dea9d5ac Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186855 Tested-by: Jenkins Reviewed-by: Justin Luth <[email protected]> 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<beans::XPropertySet> 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<sal_Int32>(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<beans::XPropertySet> 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<sal_Int32>(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 <com/sun/star/text/XTextDocument.hpp> #include <rtl/ref.hxx> #include <memory> +#include <optional> 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<bool> m_oLinkStyles; sal_Int16 m_nZoomFactor; sal_Int16 m_nZoomType = 0; sal_Int32 m_nWordCompatibilityMode;
