summaryrefslogtreecommitdiff
path: root/sw/source/filter/ww8
diff options
context:
space:
mode:
authorJustin Luth <justin.luth@collabora.com>2020-03-13 07:14:29 +0300
committerThorsten Behrens <Thorsten.Behrens@CIB.de>2020-04-02 21:22:43 +0200
commit0ee0ee3eb66dadf50b3d2c6a7af9c095b26afd88 (patch)
tree348b1cbaef73fa69664bc7574f40863ccbfe7080 /sw/source/filter/ww8
parent3c92bceceea49f4a4449395ef0cf1c7d27e13d50 (diff)
tdf#131304 .docx: flag new files as MS Word 2019 native mode
compatibilityMode = 15: [Word 2013/2016/2019] Up till now, documents that were exported into the docx format were treated by default as native Word 2007 format, since no compatibilityMode setting was provided. (Don't worry, we still round-trip existing older values. This patch only affects non-docx >>= .docx export.) Ultimately, this change is for the benefit of MS Word. It has no practical effect for LO. NOTE: This patch depends on previous commit 53f099c842d39266a0b4786a1af3db5628746634 which sets an appropriate value for existing .docx files. This scary change shouldn't actually be all that scary, since we already round-trip native 2019 files, without any complaint from Word or our users. The biggest change is that Word 2010 users might not be able to open NEW files perfectly. But Microsoft has already been doing that to them since 2013. By the time LO 7.0 hits stable version, it will have been months since 2010 has reached end-of-life. The vast majority of documents will still open perfectly for them. Plus, if a Word 2010 user does modify our new document, we will drop back down to their level. A nice, clear explanation of what compatibilityMode does is at howtogeek.com/256269/what-is-compatibility-mode-in-microsoft-office/ The MAIN CHANGE is that MS WORD has been DE-ACTIVATING features when it notices that it is SHARING the document with OLD_VERSION users. So Word is limiting what it will do for the BENEFIT OF THE OTHER USER while collaborating. There are a few instances where layout is affected by compatiblityMode. For example, tdf#123116 wants compat=15 so that Word will nicely layout an oversized table-row. tdf#131121 wants it too. By changing to compat=15, we can help Word take advantage of some fixes since docx 1.0, and avoid having to write new logic to export to old formats as well as new. Unfortunately, documentation on what layout changes are expected has not been identified yet. But in 7 years we should have run into most of them already... well maybe no. Change-Id: I1ce016618a680b9842fa6828c9e87cc6b677a557 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/90455 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmiklos@collabora.com> (cherry picked from commit f25985c55541cbbc9a4fc79e660592d3d0485196) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/90920 Tested-by: Thorsten Behrens <Thorsten.Behrens@CIB.de> Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
Diffstat (limited to 'sw/source/filter/ww8')
-rw-r--r--sw/source/filter/ww8/docxattributeoutput.cxx7
-rw-r--r--sw/source/filter/ww8/docxexport.cxx48
2 files changed, 53 insertions, 2 deletions
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index ec37717bc7bc..303f38b1376e 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -3690,6 +3690,8 @@ OString lcl_padStartToLength(OString const & aString, sal_Int32 nLen, sal_Char c
return aString;
}
+//Since this is not import code, "-1" needs to be handled as the mode that LO will save as.
+//To identify how your code should handle a "-1", look in DocxExport::WriteSettings().
sal_Int32 lcl_getWordCompatibilityMode( const SwDoc& rDoc )
{
uno::Reference< beans::XPropertySet > xPropSet( rDoc.GetDocShell()->GetBaseModel(), uno::UNO_QUERY_THROW );
@@ -4041,10 +4043,11 @@ void DocxAttributeOutput::TableDefinition( ww8::WW8TableNodeInfoInner::Pointer_t
// so, table_spacing + table_spacing_to_content = tblInd
// tdf#106742: since MS Word 2013 (compatibilityMode >= 15), top-level tables are handled the same as nested tables;
- // the default behavior when DOCX doesn't define "compatibilityMode" option is to add the cell spacing
+ // if no compatibilityMode is defined (which now should only happen on a new export to .docx),
+ // LO uses a higher compatibility than 2010's 14.
sal_Int32 nMode = lcl_getWordCompatibilityMode( *m_rExport.m_pDoc );
- if (((nMode < 0) || (0 < nMode && nMode <= 14)) && m_tableReference->m_nTableDepth == 0)
+ if ((0 < nMode && nMode <= 14) && m_tableReference->m_nTableDepth == 0)
{
const SwTableBox* pTabBox = pTableTextNodeInfoInner->getTableBox();
const SwFrameFormat* pFrameFormat = pTabBox->GetFrameFormat();
diff --git a/sw/source/filter/ww8/docxexport.cxx b/sw/source/filter/ww8/docxexport.cxx
index 7fed578100d1..53731ac2126c 100644
--- a/sw/source/filter/ww8/docxexport.cxx
+++ b/sw/source/filter/ww8/docxexport.cxx
@@ -1045,6 +1045,24 @@ void DocxExport::WriteSettings()
bHasRedlineProtectionKey = aKey.hasElements();
bHasDummyRedlineProtectionKey = aKey.getLength() == 1 && aKey[0] == 1;
}
+
+ /* Compatibility Mode (tdf#131304)
+ * 11: .doc level [Word 97-2003]
+ * 12: .docx default [Word 2007] [LO < 7.0]
+ * 14: [Word 2010]
+ * 15: [Word 2013/2016/2019] [LO >= 7.0]
+ *
+ * The PRIMARY purpose of compatibility mode does not seem to be related to layout etc.
+ * Its focus is on sharing files between multiple users, tracking the lowest supported mode in the group.
+ * It is to BENEFIT older programs by not using certain new features that they don't understand.
+ *
+ * The next time the compat mode needs to be changed, I forsee the following steps:
+ * 1.) Accept the new mode: Start round-tripping the new value, indicating we understand that format.
+ * 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
+ bool bHasCompatibilityMode = false;
const OUString aGrabBagName = UNO_NAME_MISC_OBJ_INTEROPGRABBAG;
if ( xPropSetInfo->hasPropertyByName( aGrabBagName ) )
{
@@ -1096,12 +1114,33 @@ void DocxExport::WriteSettings()
else if( rPropVal.Name == "val" )
rPropVal.Value >>= aValue;
}
+ if ( aName == "compatibilityMode" )
+ {
+ bHasCompatibilityMode = true;
+ // Among the group of programs sharing this document, the lowest mode is retained.
+ // Reduce this number if we are not comfortable with the new/unknown mode yet.
+ // Step 1 in accepting a new mode would be to comment out the following clause
+ // and roundtrip the new value instead of overwriting with the older number.
+ // There are no newer modes at the time this code was written.
+ if ( aValue.toInt32() > nTargetCompatibilityMode )
+ aValue = OUString::number(nTargetCompatibilityMode);
+ }
+
pFS->singleElementNS( XML_w, XML_compatSetting,
FSNS( XML_w, XML_name ), aName.toUtf8(),
FSNS( XML_w, XML_uri ), aUri.toUtf8(),
FSNS( XML_w, XML_val ), aValue.toUtf8());
}
+ if ( !bHasCompatibilityMode )
+ {
+ pFS->singleElementNS( XML_w, XML_compatSetting,
+ FSNS( XML_w, XML_name ), "compatibilityMode",
+ FSNS( XML_w, XML_uri ), "http://schemas.microsoft.com/office/word",
+ FSNS( XML_w, XML_val ), OString::number(nTargetCompatibilityMode));
+ bHasCompatibilityMode = true;
+ }
+
pFS->endElementNS( XML_w, XML_compat );
}
else if (rProp.Name == "DocumentProtection")
@@ -1161,6 +1200,15 @@ void DocxExport::WriteSettings()
}
}
}
+ if ( !bHasCompatibilityMode )
+ {
+ pFS->startElementNS(XML_w, XML_compat);
+ pFS->singleElementNS( XML_w, XML_compatSetting,
+ FSNS( XML_w, XML_name ), "compatibilityMode",
+ FSNS( XML_w, XML_uri ), "http://schemas.microsoft.com/office/word",
+ FSNS( XML_w, XML_val ), OString::number(nTargetCompatibilityMode));
+ pFS->endElementNS( XML_w, XML_compat );
+ }
if (! hasProtectionProperties)
{