diff options
author | Michael Stahl <Michael.Stahl@cib.de> | 2020-04-14 17:42:06 +0200 |
---|---|---|
committer | Michael Stahl <michael.stahl@cib.de> | 2020-04-15 11:29:15 +0200 |
commit | 968a7e3247169489d29cc7de0079eea12a663870 (patch) | |
tree | 51d8e8c3e3e342419c7f86f4905108a21ca04939 /sw | |
parent | 903070a573b87714458c3cb3d18635f5eda6aa15 (diff) |
sw: DOCX export: export AddExternalLeading as w:noLeading
For 11pt Arial, can fit 59 paragraphs on a page vs. 57...
This is annoyingly complicated by the fact that Word 2013 ignores
w:noLeading element if compatibilityMode is 15.
Change-Id: Ie3093eabba45cdf6e7903ed860f5bad24dcc0323
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92208
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@cib.de>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport5.cxx | 5 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxattributeoutput.cxx | 9 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxexport.cxx | 34 |
3 files changed, 37 insertions, 11 deletions
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx index 95fcebbf9c42..ee4b35698533 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx @@ -1119,10 +1119,11 @@ DECLARE_OOXMLEXPORT_TEST(tdf106843, "tdf106843.fodt") assertXPath(pXmlSettings, "/w:settings/w:documentProtection", "edit", "trackedChanges"); assertXPath(pXmlSettings, "/w:settings/w:documentProtection", "enforcement", "1"); - // LO intends to export a .docx format that is natively compatible with 2013. + // LO intends to export a .docx format that is natively compatible with 2013 + // but this document has an implicitly added setting AddExternalLeading = false assertXPath(pXmlSettings, "/w:settings/w:compat/w:compatSetting[1]", "name", "compatibilityMode"); assertXPath(pXmlSettings, "/w:settings/w:compat/w:compatSetting[1]", "uri", "http://schemas.microsoft.com/office/word"); - assertXPath(pXmlSettings, "/w:settings/w:compat/w:compatSetting[1]", "val", "15"); // compatible with 2003/2016/2019 + assertXPath(pXmlSettings, "/w:settings/w:compat/w:compatSetting[1]", "val", "14"); // compatible with 2010 } } diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index a8ed8e88a47d..10afeb9fd918 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -3770,6 +3770,15 @@ sal_Int32 lcl_getWordCompatibilityMode( const SwDoc& rDoc ) } } + // TODO: this is duplicative, better store it in DocxExport member? + if (!rDoc.getIDocumentSettingAccess().get(DocumentSettingId::ADD_EXT_LEADING)) + { + if (nWordCompatibilityMode == -1 || 14 < nWordCompatibilityMode) + { + nWordCompatibilityMode = 14; + } + } + return nWordCompatibilityMode; } diff --git a/sw/source/filter/ww8/docxexport.cxx b/sw/source/filter/ww8/docxexport.cxx index 035f50cbeaac..b18d94410027 100644 --- a/sw/source/filter/ww8/docxexport.cxx +++ b/sw/source/filter/ww8/docxexport.cxx @@ -944,6 +944,25 @@ void DocxExport::WriteDocVars(const sax_fastparser::FSHelperPtr& pFS) } } +static auto +WriteCompat(SwDoc const& rDoc, ::sax_fastparser::FSHelperPtr const& rpFS, + sal_Int32 & rTargetCompatibilityMode) -> void +{ + if (!rDoc.getIDocumentSettingAccess().get(DocumentSettingId::ADD_EXT_LEADING)) + { + rpFS->singleElementNS(XML_w, XML_noLeading); + if (rTargetCompatibilityMode > 14) + { // Word ignores noLeading in compatibilityMode 15 + rTargetCompatibilityMode = 14; + } + } + // Do not justify lines with manual break + if (rDoc.getIDocumentSettingAccess().get(DocumentSettingId::DO_NOT_JUSTIFY_LINES_WITH_MANUAL_BREAK)) + { + rpFS->singleElementNS(XML_w, XML_doNotExpandShiftReturn); + } +} + void DocxExport::WriteSettings() { SwViewShell *pViewShell(m_pDoc->getIDocumentLayoutAccess().GetCurrentViewShell()); @@ -1027,14 +1046,6 @@ void DocxExport::WriteSettings() pFS->singleElementNS( XML_w, XML_defaultTabStop, FSNS( XML_w, XML_val ), OString::number(m_aSettings.defaultTabStop) ); - // Do not justify lines with manual break - if( m_pDoc->getIDocumentSettingAccess().get( DocumentSettingId::DO_NOT_JUSTIFY_LINES_WITH_MANUAL_BREAK )) - { - pFS->startElementNS(XML_w, XML_compat); - pFS->singleElementNS(XML_w, XML_doNotExpandShiftReturn); - pFS->endElementNS( XML_w, XML_compat ); - } - // export current mail merge database and table names SwDBData aData = m_pDoc->GetDBData(); if ( !aData.sDataSource.isEmpty() && aData.nCommandType == css::sdb::CommandType::TABLE && !aData.sCommand.isEmpty() ) @@ -1121,7 +1132,7 @@ void DocxExport::WriteSettings() * 2.) Many years later, change the TargetCompatilityMode for new documents, when we no longer care * about working with perfect compatibility with older versions of MS Word. */ - const sal_Int32 nTargetCompatibilityMode = 15; //older versions might not open our files well + sal_Int32 nTargetCompatibilityMode = 15; //older versions might not open our files well bool bHasCompatibilityMode = false; const OUString aGrabBagName = UNO_NAME_MISC_OBJ_INTEROPGRABBAG; if ( xPropSetInfo->hasPropertyByName( aGrabBagName ) ) @@ -1154,6 +1165,8 @@ void DocxExport::WriteSettings() { pFS->startElementNS(XML_w, XML_compat); + WriteCompat(*m_pDoc, pFS, nTargetCompatibilityMode); + uno::Sequence< beans::PropertyValue > aCompatSettingsSequence; rProp.Value >>= aCompatSettingsSequence; @@ -1282,6 +1295,9 @@ void DocxExport::WriteSettings() if ( !bHasCompatibilityMode ) { pFS->startElementNS(XML_w, XML_compat); + + WriteCompat(*m_pDoc, pFS, nTargetCompatibilityMode); + pFS->singleElementNS( XML_w, XML_compatSetting, FSNS( XML_w, XML_name ), "compatibilityMode", FSNS( XML_w, XML_uri ), "http://schemas.microsoft.com/office/word", |