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

Justin Luth (via logerrit) logerrit at kemper.freedesktop.org
Fri Nov 27 11:15:55 UTC 2020


 sw/qa/extras/globalfilter/data/tdf138345_charstyle_highlight.odt |binary
 sw/qa/extras/globalfilter/globalfilter.cxx                       |   46 ++++++++++
 sw/source/filter/ww8/ww8atr.cxx                                  |    7 +
 3 files changed, 53 insertions(+)

New commits:
commit 5951a867b87cbb88886968c1e2059f2cf461d11c
Author:     Justin Luth <justin.luth at collabora.com>
AuthorDate: Thu Nov 19 19:58:16 2020 +0300
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Fri Nov 27 12:15:18 2020 +0100

    tdf#138345 sw ms export: Char highlight: no export to char-style
    
    MS Word ignores w:highlight in a character style.
    It only accepts it as direct formatting or in para-styles.
    
    So never export the character background as w:highlight,
    but always as w:shd for character styles.
    
    Change-Id: I7c9f4f00d957a8add848746051d3c4b1522d1520
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/106182
    Tested-by: Jenkins
    Reviewed-by: Justin Luth <justin_luth at sil.org>
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>

diff --git a/sw/qa/extras/globalfilter/data/tdf138345_charstyle_highlight.odt b/sw/qa/extras/globalfilter/data/tdf138345_charstyle_highlight.odt
new file mode 100644
index 000000000000..6886ed8f71c6
Binary files /dev/null and b/sw/qa/extras/globalfilter/data/tdf138345_charstyle_highlight.odt differ
diff --git a/sw/qa/extras/globalfilter/globalfilter.cxx b/sw/qa/extras/globalfilter/globalfilter.cxx
index a2ef4d318ca6..bb9521823783 100644
--- a/sw/qa/extras/globalfilter/globalfilter.cxx
+++ b/sw/qa/extras/globalfilter/globalfilter.cxx
@@ -48,6 +48,7 @@ public:
     void testCharHighlight();
     void testCharHighlightODF();
     void testCharHighlightBody();
+    void testCharStyleHighlight();
     void testMSCharBackgroundEditing();
     void testCharBackgroundToHighlighting();
 #if !defined(_WIN32)
@@ -574,16 +575,61 @@ void Test::testCharHighlightBody()
     }
 }
 
+void Test::testCharStyleHighlight()
+{
+    // MS Word has two kind of character backgrounds called character shading and highlighting.
+    // However, their character style can only accept shading. It ignores the highlighting value.
+
+    const OUString aFilterNames[] = {
+        "Rich Text Format",
+        "MS Word 97",
+        "Office Open XML Text",
+    };
+
+    for (OUString const & rFilterName : aFilterNames)
+    {
+        if (mxComponent.is())
+            mxComponent->dispose();
+        mxComponent = loadFromDesktop(m_directories.getURLFromSrc("/sw/qa/extras/globalfilter/data/tdf138345_charstyle_highlight.odt"),
+                                      "com.sun.star.text.TextDocument");
+
+        const OString sFailedMessage = OStringLiteral("Failed on filter: ") + rFilterName.toUtf8();
+
+        // Export the document and import again for a check
+        uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
+
+        utl::MediaDescriptor aMediaDescriptor;
+        aMediaDescriptor["FilterName"] <<= rFilterName;
+
+        utl::TempFile aTempFile;
+        aTempFile.EnableKillingFile();
+        xStorable->storeToURL(aTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList());
+        uno::Reference< lang::XComponent > xComponent(xStorable, uno::UNO_QUERY);
+        xComponent->dispose();
+        mxComponent = loadFromDesktop(aTempFile.GetURL(), "com.sun.star.text.TextDocument");
+
+        uno::Reference<beans::XPropertySet> xCharStyle;
+        getStyles("CharacterStyles")->getByName("charBackground") >>= xCharStyle;
+        const sal_Int32 nBackColor(0xFFDBB6); //orange-y
+
+        // Always export character style's background colour as shading, never as highlighting.
+        CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), static_cast<sal_Int32>(COL_TRANSPARENT), getProperty<sal_Int32>(xCharStyle,"CharHighlight"));
+        CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), nBackColor, getProperty<sal_Int32>(xCharStyle,"CharBackColor"));
+    }
+}
+
 void Test::testCharHighlight()
 {
     SvtFilterOptions& rOpt = SvtFilterOptions::Get();
     rOpt.SetCharBackground2Shading();
 
     testCharHighlightBody();
+    testCharStyleHighlight();
 
     rOpt.SetCharBackground2Highlighting();
 
     testCharHighlightBody();
+    testCharStyleHighlight();
 }
 
 void Test::testCharHighlightODF()
diff --git a/sw/source/filter/ww8/ww8atr.cxx b/sw/source/filter/ww8/ww8atr.cxx
index 0da5f1fb4c1c..ef5ea8b38ae6 100644
--- a/sw/source/filter/ww8/ww8atr.cxx
+++ b/sw/source/filter/ww8/ww8atr.cxx
@@ -5556,6 +5556,13 @@ void AttributeOutputBase::CharBackgroundBase( const SvxBrushItem& rBrush )
     bool bConvertToShading = SvtFilterOptions::Get().IsCharBackground2Shading();
     bool bHasShadingMarker = false;
 
+    // MS Word doesn't support highlight in character styles. Always export those as shading.
+    if ( !bConvertToShading && GetExport().m_bStyDef )
+    {
+        const SwFormat* pFormat = dynamic_cast<const SwFormat*>( GetExport().m_pOutFormatNode );
+        bConvertToShading = pFormat && pFormat->Which() == RES_CHRFMT;
+    }
+
     // Check shading marker
     const SfxPoolItem* pItem = GetExport().HasItem(RES_CHRATR_GRABBAG);
     if( pItem )


More information about the Libreoffice-commits mailing list