sw/qa/extras/ooxmlexport/data/tdf140336_paraNoneShading.odt |binary
 sw/qa/extras/ooxmlexport/ooxmlexport16.cxx                  |   12 ++++++
 sw/source/filter/ww8/attributeoutputbase.hxx                |    2 -
 sw/source/filter/ww8/docxattributeoutput.cxx                |    5 +-
 sw/source/filter/ww8/docxattributeoutput.hxx                |    2 -
 sw/source/filter/ww8/ww8atr.cxx                             |   21 +++++++++---
 6 files changed, 34 insertions(+), 8 deletions(-)

New commits:
commit 8ef5d0f724b75ef62c20996271e9a6997ff6c3dd
Author:     Justin Luth <justin.l...@collabora.com>
AuthorDate: Thu Mar 25 14:52:01 2021 +0200
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Tue Mar 30 12:50:43 2021 +0200

    tdf#140336 ms formats export: export NONE background for ParaBackColor
    
    This fixes a regression from LO 4.2 with tdf#88583's
    commit 60cdeb2d441a6bf5c55f511f574b2b9dd598fbb8.
    
    It isn't only SOLID that needs to be written,
    otherwise there is no way to cancel an inherited background.
    
    And only write out a SOLID if one is specified here.
    Do not duplicate a style's SOLID fill into every
    sub-style and paragraph. (Yikes)
    
    This fixes DOCX (seriously) and DOC (de-duplication),
    but not RTF (which doesn't write out transparent brushes).
    
    Surprisingly, I didn't find any examples
    where a NONE was specified that matched an inherited NONE.
    But it IS important (probably because of a bug) and also smart
    to determine and avoid writing NONE if there is no inheritance.
    So then, there is no reason not to do the last step of
    checking if the current brush matches the inherited brush.
    
    [That also paves the way for a potential follow-up commit
    to try deduplicating SOLID fills as well,
    although that likely adds grabbag complications into the mix.
    And perhaps deduplication isn't desired either,
    in case the user actually wanted to duplicate
    (if that is even possible under UI conditions).]
    
    Change-Id: I8958a68c779057d9fc5da74eca50fcf5b41d8b52
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113105
    Tested-by: Jenkins
    Reviewed-by: Justin Luth <justin_l...@sil.org>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/sw/qa/extras/ooxmlexport/data/tdf140336_paraNoneShading.odt 
b/sw/qa/extras/ooxmlexport/data/tdf140336_paraNoneShading.odt
new file mode 100644
index 000000000000..c4bd80f1a65c
Binary files /dev/null and 
b/sw/qa/extras/ooxmlexport/data/tdf140336_paraNoneShading.odt differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx
index ac46467b87f7..bda5911c1b16 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport16.cxx
@@ -15,6 +15,7 @@
 #include <svx/svdobj.hxx>
 
 #include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/drawing/FillStyle.hpp>
 #include <com/sun/star/text/XTextViewCursorSupplier.hpp>
 #include <com/sun/star/text/XTextTable.hpp>
 #include <com/sun/star/text/XTextTablesSupplier.hpp>
@@ -140,6 +141,17 @@ 
DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testTdf135773_numberingShading, "tdf135774_n
     assertXPath(pXmlStyles, 
"/w:numbering/w:abstractNum[@w:abstractNumId='1']/w:lvl[@w:ilvl='0']/w:rPr/w:shd",
 "fill", "ED4C05");
 }
 
+DECLARE_OOXMLEXPORT_TEST(testTdf140336_paraNoneShading, 
"tdf140336_paraNoneShading.odt")
+{
+    // Before the fix, the background from a style was exported to 
dis-inheriting paragraphs/styles.
+    CPPUNIT_ASSERT_EQUAL(sal_uInt32(COL_AUTO), 
getProperty<sal_uInt32>(getParagraph(1), "ParaBackColor"));
+    uno::Reference<beans::XPropertySet> 
xStyle(getStyles("ParagraphStyles")->getByName("CanclledBackground"), 
uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_NONE, 
getProperty<drawing::FillStyle>(xStyle, "FillStyle"));
+
+    // sanity check: backgroundColor paragraph style has a golden 
color(FF7F50), which para2 inherits
+    CPPUNIT_ASSERT_EQUAL(sal_uInt32(16744272), 
getProperty<sal_uInt32>(getParagraph(2), "ParaBackColor"));
+}
+
 DECLARE_OOXMLEXPORT_TEST(testTdf141173_missingFrames, 
"tdf141173_missingFrames.rtf")
 {
     // Without the fix in place, almost all of the text and textboxes were 
missing.
diff --git a/sw/source/filter/ww8/attributeoutputbase.hxx 
b/sw/source/filter/ww8/attributeoutputbase.hxx
index e102b3f7012b..cea47b8e3c60 100644
--- a/sw/source/filter/ww8/attributeoutputbase.hxx
+++ b/sw/source/filter/ww8/attributeoutputbase.hxx
@@ -666,7 +666,7 @@ public:
     ( ww8::WW8TableNodeInfoInner const * pTableTextNodeInfoInner,
       tools::Long& rPageSize, bool& rRelBoxSize );
 
-    virtual void MaybeOutputBrushItem(SfxItemSet const&) { }
+    virtual bool MaybeOutputBrushItem(SfxItemSet const&) { return false; }
 
     /// Exports the definition (image, size) of a single numbering picture 
bullet.
     virtual void BulletDefinition(int /*nId*/, const Graphic& /*rGraphic*/, 
Size /*aSize*/) {}
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx 
b/sw/source/filter/ww8/docxattributeoutput.cxx
index f4688e5f6a01..7e67ffda5590 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -6308,14 +6308,14 @@ oox::drawingml::DrawingML& 
DocxAttributeOutput::GetDrawingML()
     return m_rDrawingML;
 }
 
-void DocxAttributeOutput::MaybeOutputBrushItem(SfxItemSet const& rSet)
+bool DocxAttributeOutput::MaybeOutputBrushItem(SfxItemSet const& rSet)
 {
     const XFillStyleItem* 
pXFillStyleItem(rSet.GetItem<XFillStyleItem>(XATTR_FILLSTYLE));
 
     if ((pXFillStyleItem && pXFillStyleItem->GetValue() != 
drawing::FillStyle_NONE)
         || !m_rExport.SdrExporter().getDMLTextFrameSyntax())
     {
-        return;
+        return false;
     }
 
     // sw text frames are opaque by default, even with fill none!
@@ -6327,6 +6327,7 @@ void DocxAttributeOutput::MaybeOutputBrushItem(SfxItemSet 
const& rSet)
     pClone->Put(aSolid);
     std::unique_ptr<SvxBrushItem> const 
pBrush(getSvxBrushItemFromSourceSet(*pClone, RES_BACKGROUND));
     FormatBackground(*pBrush);
+    return true;
 }
 
 namespace {
diff --git a/sw/source/filter/ww8/docxattributeoutput.hxx 
b/sw/source/filter/ww8/docxattributeoutput.hxx
index 565741bd0afe..7a2826e81ea9 100644
--- a/sw/source/filter/ww8/docxattributeoutput.hxx
+++ b/sw/source/filter/ww8/docxattributeoutput.hxx
@@ -1031,7 +1031,7 @@ public:
     virtual css::uno::Reference<css::text::XTextFrame> GetUnoTextFrame(
         css::uno::Reference<css::drawing::XShape> xShape) override;
     virtual oox::drawingml::DrawingML& GetDrawingML() override;
-    virtual void MaybeOutputBrushItem(SfxItemSet const&) override;
+    virtual bool MaybeOutputBrushItem(SfxItemSet const&) override;
 
     void BulletDefinition(int nId, const Graphic& rGraphic, Size aSize) 
override;
 
diff --git a/sw/source/filter/ww8/ww8atr.cxx b/sw/source/filter/ww8/ww8atr.cxx
index 5d3f4b8ae0d2..95b7bab8034b 100644
--- a/sw/source/filter/ww8/ww8atr.cxx
+++ b/sw/source/filter/ww8/ww8atr.cxx
@@ -352,7 +352,7 @@ void MSWordExportBase::OutputItemSet( const SfxItemSet& 
rSet, bool bPapFormat, b
         ExportPoolItemsToCHP(aItems, nScript, nullptr);
     if ( bPapFormat )
     {
-        AttrOutput().MaybeOutputBrushItem(rSet);
+        const bool bAlreadyOutputBrushItem = 
AttrOutput().MaybeOutputBrushItem(rSet);
 
         for ( const auto& rItem : aItems )
         {
@@ -365,12 +365,25 @@ void MSWordExportBase::OutputItemSet( const SfxItemSet& 
rSet, bool bPapFormat, b
         }
 
         // Has to be called after RES_PARATR_GRABBAG is processed.
-        const XFillStyleItem* 
pXFillStyleItem(rSet.GetItem<XFillStyleItem>(XATTR_FILLSTYLE));
-        if (pXFillStyleItem && pXFillStyleItem->GetValue() == 
drawing::FillStyle_SOLID && !rSet.HasItem(RES_BACKGROUND))
+        const XFillStyleItem* 
pFill(rSet.GetItem<XFillStyleItem>(XATTR_FILLSTYLE, false));
+        if (!bAlreadyOutputBrushItem && pFill
+            && (pFill->GetValue() == drawing::FillStyle_SOLID || 
pFill->GetValue() == drawing::FillStyle_NONE)
+            && !rSet.GetItem(RES_BACKGROUND, false))
         {
+            const bool bFillStyleNone = pFill->GetValue() == 
drawing::FillStyle_NONE;
+            // No need to write out a NONE background if it can't inherit 
something else, or if it already inherits a NONE.
+            std::unique_ptr<SvxBrushItem> pInherited;
+            if (bFillStyleNone)
+            {
+                if ( auto pNd = dynamic_cast<const 
SwContentNode*>(m_pOutFormatNode)) //paragraph
+                    pInherited = 
getSvxBrushItemFromSourceSet(static_cast<SwTextFormatColl&>(pNd->GetAnyFormatColl()).GetAttrSet(),
 RES_BACKGROUND);
+                else if (m_bStyDef && m_pCurrentStyle && 
m_pCurrentStyle->DerivedFrom()) //style
+                    pInherited = 
getSvxBrushItemFromSourceSet(m_pCurrentStyle->DerivedFrom()->GetAttrSet(), 
RES_BACKGROUND);
+            }
             // Construct an SvxBrushItem, as expected by the exporters.
             std::unique_ptr<SvxBrushItem> 
aBrush(getSvxBrushItemFromSourceSet(rSet, RES_BACKGROUND));
-            AttrOutput().OutputItem(*aBrush);
+            if (!bFillStyleNone || (pInherited && *pInherited != *aBrush))
+                AttrOutput().OutputItem(*aBrush);
         }
 #if 0
         else
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to