officecfg/registry/schema/org/openoffice/Office/Common.xcs | 6 ++ sw/CppunitTest_sw_ooxmlexport17.mk | 4 + sw/qa/extras/ooxmlexport/data/dont-add-new-styles.docx |binary sw/qa/extras/ooxmlexport/ooxmlexport17.cxx | 33 +++++++++++++ sw/source/uibase/app/docshini.cxx | 6 +- 5 files changed, 48 insertions(+), 1 deletion(-)
New commits: commit f2e80f9f9b5d53ed270687f000bcb8b76dd81fb9 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Wed Sep 15 15:26:41 2021 +0200 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Wed Sep 15 16:45:57 2021 +0200 sw: add a DisableBuiltinStyles API setting The built-in Writer styles (e.g. Caption) are written to each & every document to help compatibility: this way if the built-in style changes, existing documents are not changing. While this is a good default, sometimes document conversion workflows want to ensure that no new styles are added to the document during conversion. This new settings allows to opt in for this behavior in case not polluting the doc model is more important than the negative effects of changing built-in styles. Change-Id: I43130a215ee10ee6952724dbef2caab7174ff77f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122154 Reviewed-by: Miklos Vajna <vmik...@collabora.com> Tested-by: Jenkins diff --git a/officecfg/registry/schema/org/openoffice/Office/Common.xcs b/officecfg/registry/schema/org/openoffice/Office/Common.xcs index c9940001b573..d967d748b90a 100644 --- a/officecfg/registry/schema/org/openoffice/Office/Common.xcs +++ b/officecfg/registry/schema/org/openoffice/Office/Common.xcs @@ -2590,6 +2590,12 @@ </info> <value>true</value> </prop> + <prop oor:name="DisableBuiltinStyles" oor:type="xs:boolean" oor:nillable="false"> + <info> + <desc>Determines whether to skip addition of built-in styles to the document model.</desc> + </info> + <value>false</value> + </prop> </group> <group oor:name="Security"> <info> diff --git a/sw/CppunitTest_sw_ooxmlexport17.mk b/sw/CppunitTest_sw_ooxmlexport17.mk index 80316e1c0ca4..bcf27750c529 100644 --- a/sw/CppunitTest_sw_ooxmlexport17.mk +++ b/sw/CppunitTest_sw_ooxmlexport17.mk @@ -11,4 +11,8 @@ $(eval $(call sw_ooxmlexport_test,17)) +$(eval $(call gb_CppunitTest_use_custom_headers,sw_ooxmlexport17,\ + officecfg/registry \ +)) + # vim: set noet sw=4 ts=4: diff --git a/sw/qa/extras/ooxmlexport/data/dont-add-new-styles.docx b/sw/qa/extras/ooxmlexport/data/dont-add-new-styles.docx new file mode 100644 index 000000000000..1ee154a8187f Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/dont-add-new-styles.docx differ diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx index 10d7bab40a23..523d4a6e747d 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx @@ -10,8 +10,13 @@ #include <sal/config.h> #include <string_view> + #include <com/sun/star/text/XBookmarksSupplier.hpp> +#include <comphelper/configuration.hxx> +#include <comphelper/scopeguard.hxx> +#include <officecfg/Office/Common.hxx> + #include <swmodeltestbase.hxx> constexpr OUStringLiteral DATA_DIRECTORY = u"/sw/qa/extras/ooxmlexport/data/"; @@ -54,6 +59,34 @@ CPPUNIT_TEST_FIXTURE(Test, testParaStyleNumLevel) assertXPath(pXmlDoc, "/w:styles/w:style[@w:styleId='Mystyle']/w:pPr/w:numPr/w:ilvl", "val", "1"); } +CPPUNIT_TEST_FIXTURE(Test, testDontAddNewStyles) +{ + // Given a document that lacks builtin styles, and addition of them is disabled: + { + std::shared_ptr<comphelper::ConfigurationChanges> pBatch( + comphelper::ConfigurationChanges::create()); + officecfg::Office::Common::Load::DisableBuiltinStyles::set(true, pBatch); + pBatch->commit(); + } + comphelper::ScopeGuard g([] { + std::shared_ptr<comphelper::ConfigurationChanges> pBatch( + comphelper::ConfigurationChanges::create()); + officecfg::Office::Common::Load::DisableBuiltinStyles::set(false, pBatch); + pBatch->commit(); + }); + + // When saving that document: + loadAndSave("dont-add-new-styles.docx"); + + // Then make sure that export doesn't have additional styles, Caption was one of them: + xmlDocUniquePtr pXmlDoc = parseExport("word/styles.xml"); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 0 + // - Actual : 1 + // i.e. builtin styles were added to the export result, even if we opted out. + assertXPath(pXmlDoc, "/w:styles/w:style[@w:styleId='Caption']", 0); +} + DECLARE_OOXMLEXPORT_TEST(testTdf123642_BookmarkAtDocEnd, "tdf123642.docx") { // get bookmark interface diff --git a/sw/source/uibase/app/docshini.cxx b/sw/source/uibase/app/docshini.cxx index 0b47fc6d26cc..6cc2448d5a99 100644 --- a/sw/source/uibase/app/docshini.cxx +++ b/sw/source/uibase/app/docshini.cxx @@ -80,6 +80,8 @@ #include <memory> +#include <officecfg/Office/Common.hxx> + using namespace ::com::sun::star::i18n; using namespace ::com::sun::star::lang; using namespace ::com::sun::star::uno; @@ -234,7 +236,9 @@ bool SwDocShell::InitNew( const uno::Reference < embed::XStorage >& xStor ) sal_uInt16 nFontWhich = RES_CHRATR_FONT; sal_uInt16 nFontHeightWhich = RES_CHRATR_FONTSIZE; LanguageType eLanguage = m_xDoc->GetDefault( RES_CHRATR_LANGUAGE ).GetLanguage(); - for(sal_uInt8 nIdx = 0; nIdx < 24; nIdx += 2) + bool bDisableBuiltinStyles = officecfg::Office::Common::Load::DisableBuiltinStyles::get(); + sal_uInt8 nLimit = bDisableBuiltinStyles ? 0 : 24; + for(sal_uInt8 nIdx = 0; nIdx < nLimit; nIdx += 2) { if(nIdx == 8) {