sw/qa/extras/ooxmlexport/ooxmlexport10.cxx               |    7 +-
 sw/qa/extras/ooxmlexport/ooxmlexport5.cxx                |    5 +
 sw/source/filter/ww8/docxattributeoutput.cxx             |    7 +-
 sw/source/filter/ww8/docxexport.cxx                      |   48 +++++++++++++++
 writerfilter/source/dmapper/DomainMapperTableHandler.cxx |    3 
 5 files changed, 65 insertions(+), 5 deletions(-)

New commits:
commit f25985c55541cbbc9a4fc79e660592d3d0485196
Author:     Justin Luth <justin.l...@collabora.com>
AuthorDate: Fri Mar 13 07:14:29 2020 +0300
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Wed Mar 18 09:29:03 2020 +0100

    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 <vmik...@collabora.com>

diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx
index 1979a5180ec3..1057ab93485c 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx
@@ -1194,13 +1194,14 @@ DECLARE_OOXMLEXPORT_TEST(testTableMarginAdjustment, 
"table.fodt")
     auto const xTable(getParagraphOrTable(1));
     CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty<sal_Int32>(xTable, 
"LeftMargin"));
 
-    // currently no compatibilityMode is generated, it's only round-tripped if
-    // it exists in the input; if it doesn't exist, the default is "12" (old)
+    // Now that compatibilityMode is set to 2013's 15 (new), expect the new 
values,
+    // since LO is exporting in the NEW way now instead of the OLD way.
+    // This was 55 when using 2007's compatibilityMode of 12 (old)
 
     xmlDocPtr pXmlDoc = parseExport("word/document.xml");
 
     assertXPath(pXmlDoc, "//w:tbl[1]/w:tblPr[1]/w:tblInd[1]", "type", "dxa");
-    assertXPath(pXmlDoc, "//w:tbl[1]/w:tblPr[1]/w:tblInd[1]", "w", "55");
+    assertXPath(pXmlDoc, "//w:tbl[1]/w:tblPr[1]/w:tblInd[1]", "w", "0");
 }
 
 DECLARE_OOXMLEXPORT_TEST( testTableCellMargin, "table-cell-margin.docx" )
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx
index 8615ee121f01..2ba06ce0982e 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx
@@ -1026,6 +1026,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.
+        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
     }
 }
 
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx 
b/sw/source/filter/ww8/docxattributeoutput.cxx
index 9dd1e4de9559..636f12bf5deb 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -3722,6 +3722,8 @@ OString lcl_padStartToLength(OString const & aString, 
sal_Int32 nLen, char cFill
 }
 
 //Keep this function in-sync with the one in writerfilter/.../SettingsTable.cxx
+//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 );
@@ -4086,10 +4088,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 c39cfea40b9d..1e85b8ca8c70 100644
--- a/sw/source/filter/ww8/docxexport.cxx
+++ b/sw/source/filter/ww8/docxexport.cxx
@@ -1091,6 +1091,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 ) )
     {
@@ -1142,12 +1160,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")
@@ -1205,6 +1244,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 );
+    }
 
     WriteDocVars(pFS);
 
diff --git a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx 
b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
index 37ff993f3b41..0e5a0cfdfd61 100644
--- a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
+++ b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
@@ -615,6 +615,9 @@ TableStyleSheetEntry * 
DomainMapperTableHandler::endTableGetTableStyle(TableInfo
 
         // 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
+
+        // Undefined should not be possible any more for DOCX, but it is for 
RTF.
+        // In any case, continue to treat undefined as version 12 during 
import.
         sal_Int32 nMode = 
m_rDMapper_Impl.GetSettingsTable()->GetWordCompatibilityMode();
 
         if (((nMode < 0) || (0 < nMode && nMode <= 14)) && rInfo.nNestLevel == 
1)
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to