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 <vmiklos@collabora.com> Tested-by: Jenkins
This commit is contained in:
parent
66df55d800
commit
f2e80f9f9b
5 changed files with 48 additions and 1 deletions
|
@ -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>
|
||||
|
|
|
@ -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:
|
||||
|
|
BIN
sw/qa/extras/ooxmlexport/data/dont-add-new-styles.docx
Normal file
BIN
sw/qa/extras/ooxmlexport/data/dont-add-new-styles.docx
Normal file
Binary file not shown.
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue