[Libreoffice-commits] core.git: sw/source writerfilter/source

Justin Luth (via logerrit) logerrit at kemper.freedesktop.org
Fri Mar 13 08:59:35 UTC 2020


 sw/source/filter/ww8/docxattributeoutput.cxx  |   10 ++++++++--
 writerfilter/source/dmapper/SettingsTable.cxx |   13 +++++++++++--
 2 files changed, 19 insertions(+), 4 deletions(-)

New commits:
commit 6bc01f234de9a3c5abc00253fed8dc691320fd3b
Author:     Justin Luth <justin.luth at collabora.com>
AuthorDate: Thu Mar 12 20:13:53 2020 +0300
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Fri Mar 13 09:59:00 2020 +0100

    tdf#131304 writerfilter: cache Word compatibilityMode
    
    GetWordCompatibilityMode() is an expensive call
    that is called at least for every table row.
    Caching will soon be even more beneficial
    when LO also starts writing out this value
    and thus quickly caches a non-negative result.
    
    Anything created by MS Word since at least 2010 specifies
    this optional setting, so most .docx files specify
    this value - and thus will benefit from the cache.
    
    One difference that I ignored is that Word replaces a
    "number greater than what I know" with its own
    compatibilityMode value. (tested in Word 2010 and 2016.)
    That is probably only a concern at export time anyway...
    
    Change-Id: I0ee71d34150c5f3d9858adb678814a10c7fe8959
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/90434
    Tested-by: Jenkins
    Reviewed-by: Justin Luth <justin_luth at sil.org>
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>

diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index dc840a227e38..1810a8d595f7 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -3721,11 +3721,13 @@ OString lcl_padStartToLength(OString const & aString, sal_Int32 nLen, char cFill
         return aString;
 }
 
+//Keep this function in-sync with the one in writerfilter/.../SettingsTable.cxx
 sal_Int32 lcl_getWordCompatibilityMode( const SwDoc& rDoc )
 {
     uno::Reference< beans::XPropertySet >     xPropSet( rDoc.GetDocShell()->GetBaseModel(), uno::UNO_QUERY_THROW );
     uno::Reference< beans::XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo();
 
+    sal_Int32 nWordCompatibilityMode = -1;
     if ( xPropSetInfo->hasPropertyByName( UNO_NAME_MISC_OBJ_INTEROPGRABBAG ) )
     {
         uno::Sequence< beans::PropertyValue > propList;
@@ -3756,14 +3758,18 @@ sal_Int32 lcl_getWordCompatibilityMode( const SwDoc& rDoc )
 
                     if ( sName == "compatibilityMode" && sUri == "http://schemas.microsoft.com/office/word" )
                     {
-                        return sVal.toInt32();
+                        const sal_Int32 nValidMode = sVal.toInt32();
+                        // if repeated, highest mode wins in MS Word. 11 is the first valid mode.
+                        if ( nValidMode > 10 && nValidMode > nWordCompatibilityMode )
+                            nWordCompatibilityMode = nValidMode;
+
                     }
                 }
             }
         }
     }
 
-    return -1; // Word compatibility mode not found
+    return nWordCompatibilityMode;
 }
 
 }
diff --git a/writerfilter/source/dmapper/SettingsTable.cxx b/writerfilter/source/dmapper/SettingsTable.cxx
index 7658d299e712..7028f06e7fe9 100644
--- a/writerfilter/source/dmapper/SettingsTable.cxx
+++ b/writerfilter/source/dmapper/SettingsTable.cxx
@@ -241,6 +241,7 @@ struct SettingsTable_Impl
     bool                m_bLinkStyles;
     sal_Int16           m_nZoomFactor;
     sal_Int16 m_nZoomType = 0;
+    sal_Int32           m_nWordCompatibilityMode;
     Id                  m_nView;
     bool                m_bEvenAndOddHeaders;
     bool                m_bUsePrinterMetrics;
@@ -277,6 +278,7 @@ struct SettingsTable_Impl
     , m_bShowMarkupChanges(true)
     , m_bLinkStyles(false)
     , m_nZoomFactor(0)
+    , m_nWordCompatibilityMode(-1)
     , m_nView(0)
     , m_bEvenAndOddHeaders(false)
     , m_bUsePrinterMetrics(false)
@@ -757,8 +759,12 @@ void SettingsTable::ApplyProperties(uno::Reference<text::XTextDocument> const& x
     }
 }
 
+//Keep this function in-sync with the one in sw/.../docxattributeoutput.cxx
 sal_Int32 SettingsTable::GetWordCompatibilityMode() const
 {
+    if ( m_pImpl->m_nWordCompatibilityMode != -1 )
+        return m_pImpl->m_nWordCompatibilityMode;
+
     for (const auto& rProp : m_pImpl->m_aCompatSettings)
     {
         if (rProp.Name == "compatSetting")
@@ -776,12 +782,15 @@ sal_Int32 SettingsTable::GetWordCompatibilityMode() const
 
             if (sName == "compatibilityMode" && sUri == "http://schemas.microsoft.com/office/word")
             {
-                return sVal.toInt32();
+                const sal_Int32 nValidMode = sVal.toInt32();
+                // if repeated, highest mode wins in MS Word. 11 is the first valid mode.
+                if ( nValidMode > 10 && nValidMode > m_pImpl->m_nWordCompatibilityMode )
+                    m_pImpl->m_nWordCompatibilityMode = nValidMode;
             }
         }
     }
 
-    return -1; // Word compatibility mode not found
+    return m_pImpl->m_nWordCompatibilityMode;
 }
 
 bool SettingsTable::GetLongerSpaceSequence() const


More information about the Libreoffice-commits mailing list