[Libreoffice-commits] core.git: Branch 'libreoffice-5-4-7' - 2 commits - sw/qa sw/source

Miklos Vajna vmiklos at collabora.co.uk
Mon May 7 13:25:27 UTC 2018


 sw/qa/extras/layout/data/tdf116925.docx |binary
 sw/qa/extras/layout/data/tdf117028.docx |binary
 sw/qa/extras/layout/layout.cxx          |   46 ++++++++++++++++++++++++++++++++
 sw/source/core/access/accpara.cxx       |    2 -
 sw/source/core/doc/notxtfrm.cxx         |    2 -
 sw/source/core/inc/frame.hxx            |    3 +-
 sw/source/core/layout/paintfrm.cxx      |   41 ++++++++++++++++++++++++----
 sw/source/core/text/inftxt.cxx          |    2 -
 sw/source/core/txtnode/fntcache.cxx     |    2 -
 9 files changed, 87 insertions(+), 11 deletions(-)

New commits:
commit f99fc4a3dbb9bc01d619b93e9759e744d146bdde
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Mon Apr 16 10:11:26 2018 +0200

    tdf#117028 sw: conditionally consider fill of shape for in-textbox auto color
    
    Commit f966767e1ccfa432da33e1a0fd6de69e17a36bc3 (tdf#116925 sw: consider
    fill styles of shape for in-textbox auto color, 2018-04-10) did this
    unconditionally, but there are two cases:
    
    1) Shape (with textbox) has a fill, in that case auto text color of
    textbox should consider the shape fill.
    
    2) Shape has no fill, in that case the shape fill should not be
    considered when counting the background of a transparent fly frame.
    
    Fix 2) without breaking 1) by making the change to
    SwFrame::GetBackgroundBrush() opt-in, and only use it for auto font
    color, not in other cases.
    
    Change-Id: I761a1b7d6ecf47586edbe5641ec012f22f6a53d7
    Reviewed-on: https://gerrit.libreoffice.org/52941
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>
    (cherry picked from commit d9420a64fbb288020d33b681f40a858db49afca7)
    Reviewed-on: https://gerrit.libreoffice.org/52986
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>
    (cherry picked from commit b981c148ef82d0a519e270974db01c9c5879a52c)
    Reviewed-on: https://gerrit.libreoffice.org/53742
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>
    Reviewed-by: Christian Lohmaier <lohmaier+LibreOffice at googlemail.com>
    Tested-by: Christian Lohmaier <lohmaier+LibreOffice at googlemail.com>

diff --git a/sw/qa/extras/layout/data/tdf117028.docx b/sw/qa/extras/layout/data/tdf117028.docx
new file mode 100644
index 000000000000..877264b4db33
Binary files /dev/null and b/sw/qa/extras/layout/data/tdf117028.docx differ
diff --git a/sw/qa/extras/layout/layout.cxx b/sw/qa/extras/layout/layout.cxx
index 3709e306f53d..9a73e2025147 100644
--- a/sw/qa/extras/layout/layout.cxx
+++ b/sw/qa/extras/layout/layout.cxx
@@ -18,10 +18,12 @@ class SwLayoutWriter : public SwModelTestBase
 public:
     void testTdf116830();
     void testTdf116925();
+    void testTdf117028();
 
     CPPUNIT_TEST_SUITE(SwLayoutWriter);
     CPPUNIT_TEST(testTdf116830);
     CPPUNIT_TEST(testTdf116925);
+    CPPUNIT_TEST(testTdf117028);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -84,6 +86,28 @@ void SwLayoutWriter::testTdf116925()
         "/metafile/push[1]/push[1]/push[1]/push[4]/push[1]/push[3]/textcolor[@color='#ffffff']", 1);
 }
 
+void SwLayoutWriter::testTdf117028()
+{
+    SwDoc* pDoc = createDoc("tdf117028.docx");
+    SwDocShell* pShell = pDoc->GetDocShell();
+
+    // Dump the rendering of the first page as an XML file.
+    std::shared_ptr<GDIMetaFile> xMetaFile = pShell->GetPreviewMetaFile();
+    MetafileXmlDump dumper;
+    xmlDocPtr pXmlDoc = dumper.dumpAndParse(*xMetaFile);
+    CPPUNIT_ASSERT(pXmlDoc);
+
+    // The only polypolygon in the rendering result was the white background we
+    // want to avoid.
+    xmlXPathObjectPtr pXmlObj = getXPathNode(pXmlDoc, "//polypolygon");
+    xmlNodeSetPtr pXmlNodes = pXmlObj->nodesetval;
+    CPPUNIT_ASSERT_EQUAL(0, xmlXPathNodeSetGetLength(pXmlNodes));
+    xmlXPathFreeObject(pXmlObj);
+
+    // Make sure the text is still rendered.
+    assertXPathContent(pXmlDoc, "//textarray/text", "Hello");
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(SwLayoutWriter);
 CPPUNIT_PLUGIN_IMPLEMENT();
 
diff --git a/sw/source/core/access/accpara.cxx b/sw/source/core/access/accpara.cxx
index 86fe38c63871..e92d315b1350 100644
--- a/sw/source/core/access/accpara.cxx
+++ b/sw/source/core/access/accpara.cxx
@@ -1002,7 +1002,7 @@ static bool lcl_GetBackgroundColor( Color & rColor,
     drawinglayer::attribute::SdrAllFillAttributesHelperPtr aFillAttributes;
 
     if ( pFrame &&
-         pFrame->GetBackgroundBrush( aFillAttributes, pBackgrdBrush, pSectionTOXColor, aDummyRect, false ) )
+         pFrame->GetBackgroundBrush( aFillAttributes, pBackgrdBrush, pSectionTOXColor, aDummyRect, false, /*bConsiderTextBox=*/false ) )
     {
         if ( pSectionTOXColor )
         {
diff --git a/sw/source/core/doc/notxtfrm.cxx b/sw/source/core/doc/notxtfrm.cxx
index 4156753cf966..984c44ed6e90 100644
--- a/sw/source/core/doc/notxtfrm.cxx
+++ b/sw/source/core/doc/notxtfrm.cxx
@@ -183,7 +183,7 @@ static void lcl_ClearArea( const SwFrame &rFrame,
         SwRect aOrigRect;
         drawinglayer::attribute::SdrAllFillAttributesHelperPtr aFillAttributes;
 
-        if ( rFrame.GetBackgroundBrush( aFillAttributes, pItem, pCol, aOrigRect, false ) )
+        if ( rFrame.GetBackgroundBrush( aFillAttributes, pItem, pCol, aOrigRect, false, /*bConsiderTextBox=*/false ) )
         {
             SwRegionRects const region(rPtArea);
             basegfx::tools::B2DClipState aClipState;
diff --git a/sw/source/core/inc/frame.hxx b/sw/source/core/inc/frame.hxx
index 5e72455c35e8..e4c3ddb82d25 100644
--- a/sw/source/core/inc/frame.hxx
+++ b/sw/source/core/inc/frame.hxx
@@ -406,7 +406,8 @@ public:
         const SvxBrushItem*& rpBrush,
         const Color*& rpColor,
         SwRect &rOrigRect,
-        bool bLowerMode ) const;
+        bool bLowerMode,
+        bool bConsiderTextBox ) const;
 
     inline void SetCompletePaint() const;
     inline void ResetCompletePaint() const;
diff --git a/sw/source/core/layout/paintfrm.cxx b/sw/source/core/layout/paintfrm.cxx
index 2136601cd637..e13f67d32fc3 100644
--- a/sw/source/core/layout/paintfrm.cxx
+++ b/sw/source/core/layout/paintfrm.cxx
@@ -3970,7 +3970,7 @@ bool SwFlyFrame::IsBackgroundTransparent() const
         SwRect aDummyRect;
         drawinglayer::attribute::SdrAllFillAttributesHelperPtr aFillAttributes;
 
-        if ( GetBackgroundBrush( aFillAttributes, pBackgrdBrush, pSectionTOXColor, aDummyRect, false) )
+        if ( GetBackgroundBrush( aFillAttributes, pBackgrdBrush, pSectionTOXColor, aDummyRect, false, /*bConsiderTextBox=*/false) )
         {
             if ( pSectionTOXColor &&
                  (pSectionTOXColor->GetTransparency() != 0) &&
@@ -6509,7 +6509,7 @@ void SwFrame::PaintBackground( const SwRect &rRect, const SwPageFrame *pPage,
     bool bLowMode = true;
     drawinglayer::attribute::SdrAllFillAttributesHelperPtr aFillAttributes;
 
-    bool bBack = GetBackgroundBrush( aFillAttributes, pItem, pCol, aOrigBackRect, bLowerMode );
+    bool bBack = GetBackgroundBrush( aFillAttributes, pItem, pCol, aOrigBackRect, bLowerMode, /*bConsiderTextBox=*/false );
     //- Output if a separate background is used.
     bool bNoFlyBackground = !gProp.bSFlyMetafile && !bBack && IsFlyFrame();
     if ( bNoFlyBackground )
@@ -6519,7 +6519,7 @@ void SwFrame::PaintBackground( const SwRect &rRect, const SwPageFrame *pPage,
         // <GetBackgroundBrush> disabled this option with the parameter <bLowerMode>
         if ( bLowerMode )
         {
-            bBack = GetBackgroundBrush( aFillAttributes, pItem, pCol, aOrigBackRect, false );
+            bBack = GetBackgroundBrush( aFillAttributes, pItem, pCol, aOrigBackRect, false, /*bConsiderTextBox=*/false );
         }
         // If still no background found for the fly frame, initialize the
         // background brush <pItem> with global retouche color and set <bBack>
@@ -7311,7 +7311,7 @@ const Color SwPageFrame::GetDrawBackgrdColor() const
     SwRect aDummyRect;
     drawinglayer::attribute::SdrAllFillAttributesHelperPtr aFillAttributes;
 
-    if ( GetBackgroundBrush( aFillAttributes, pBrushItem, pDummyColor, aDummyRect, true) )
+    if ( GetBackgroundBrush( aFillAttributes, pBrushItem, pDummyColor, aDummyRect, true, /*bConsiderTextBox=*/false) )
     {
         if(aFillAttributes.get() && aFillAttributes->isUsed())
         {
@@ -7475,6 +7475,10 @@ void SwFrame::Retouch( const SwPageFrame * pPage, const SwRect &rRect ) const
  * input parameter - boolean indicating, if background brush should *not* be
  * taken from parent.
  *
+ * @param bConsiderTextBox
+ * consider the TextBox of this fly frame (if there is any) when determining
+ * the background color, useful for automatic font color.
+ *
  * @return true, if a background brush for the frame is found
  */
 bool SwFrame::GetBackgroundBrush(
@@ -7482,7 +7486,8 @@ bool SwFrame::GetBackgroundBrush(
     const SvxBrushItem* & rpBrush,
     const Color*& rpCol,
     SwRect &rOrigRect,
-    bool bLowerMode ) const
+    bool bLowerMode,
+    bool bConsiderTextBox ) const
 {
     const SwFrame *pFrame = this;
     SwViewShell *pSh = getRootFrame()->GetCurrShell();
@@ -7496,8 +7501,8 @@ bool SwFrame::GetBackgroundBrush(
 
         if (pFrame->supportsFullDrawingLayerFillAttributeSet())
         {
-            bool bTextBox = false;
-            if (pFrame->IsFlyFrame())
+            bool bHandledTextBox = false;
+            if (pFrame->IsFlyFrame() && bConsiderTextBox)
             {
                 const SwFlyFrame* pFlyFrame = static_cast<const SwFlyFrame*>(pFrame);
                 SwFrameFormat* pShape
@@ -7511,12 +7516,12 @@ bool SwFrame::GetBackgroundBrush(
                         rFillAttributes.reset(
                             new drawinglayer::attribute::SdrAllFillAttributesHelper(
                                 pObject->GetMergedItemSet()));
-                        bTextBox = true;
+                        bHandledTextBox = true;
                     }
                 }
             }
 
-            if (!bTextBox)
+            if (!bHandledTextBox)
                 rFillAttributes = pFrame->getSdrAllFillAttributesHelper();
         }
         const SvxBrushItem &rBack = pFrame->GetAttrSet()->GetBackground();
diff --git a/sw/source/core/text/inftxt.cxx b/sw/source/core/text/inftxt.cxx
index 2dbe5940fb15..955663509cdb 100644
--- a/sw/source/core/text/inftxt.cxx
+++ b/sw/source/core/text/inftxt.cxx
@@ -534,7 +534,7 @@ static bool lcl_IsDarkBackground( const SwTextPaintInfo& rInf )
         // See implementation in /core/layout/paintfrm.cxx
         // There is a background color, if there is a background brush and
         // its color is *not* "no fill"/"auto fill".
-        if( rInf.GetTextFrame()->GetBackgroundBrush( aFillAttributes, pItem, pCol, aOrigBackRect, false ) )
+        if( rInf.GetTextFrame()->GetBackgroundBrush( aFillAttributes, pItem, pCol, aOrigBackRect, false, /*bConsiderTextBox=*/false ) )
         {
             if ( !pCol )
                 pCol = &pItem->GetColor();
diff --git a/sw/source/core/txtnode/fntcache.cxx b/sw/source/core/txtnode/fntcache.cxx
index a66494b03587..6edf9e6a88b0 100644
--- a/sw/source/core/txtnode/fntcache.cxx
+++ b/sw/source/core/txtnode/fntcache.cxx
@@ -2515,7 +2515,7 @@ bool SwDrawTextInfo::ApplyAutoColor( vcl::Font* pFont )
                 /// OD 21.08.2002 #99657#
                 ///     There is a user defined setting for the background, if there
                 ///     is a background brush and its color is *not* "no fill"/"auto fill".
-                if( GetFrame()->GetBackgroundBrush( aFillAttributes, pItem, pCol, aOrigBackRect, false ) )
+                if( GetFrame()->GetBackgroundBrush( aFillAttributes, pItem, pCol, aOrigBackRect, false, /*bConsiderTextBox=*/true ) )
                 {
                     if (aFillAttributes.get() && aFillAttributes->isUsed())
                     {
commit 75967a849ceae371b4548178ec74e461f9e1aa70
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Tue Apr 10 17:46:55 2018 +0200

    tdf#116925 sw: consider fill styles of shape for in-textbox auto color
    
    Automatic color is determined in SwDrawTextInfo::ApplyAutoColor(), but
    it uses this function to determine the background color.
    
    Be consistent and consider the same background in both the
    shape-with-editeng-text and shape-with-sw-text cases.
    
    (cherry picked from commit f966767e1ccfa432da33e1a0fd6de69e17a36bc3)
    
    Change-Id: I52249a908193765bc128789d96187af334c1017c
    Reviewed-on: https://gerrit.libreoffice.org/52983
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>
    (cherry picked from commit 9e0b21e416470d826f6f27d463ba2e42bee5222d)
    Reviewed-on: https://gerrit.libreoffice.org/53737
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>
    Reviewed-by: Christian Lohmaier <lohmaier+LibreOffice at googlemail.com>
    Tested-by: Christian Lohmaier <lohmaier+LibreOffice at googlemail.com>

diff --git a/sw/qa/extras/layout/data/tdf116925.docx b/sw/qa/extras/layout/data/tdf116925.docx
new file mode 100644
index 000000000000..1c99752e9eba
Binary files /dev/null and b/sw/qa/extras/layout/data/tdf116925.docx differ
diff --git a/sw/qa/extras/layout/layout.cxx b/sw/qa/extras/layout/layout.cxx
index 16efa14c5875..3709e306f53d 100644
--- a/sw/qa/extras/layout/layout.cxx
+++ b/sw/qa/extras/layout/layout.cxx
@@ -17,9 +17,11 @@ class SwLayoutWriter : public SwModelTestBase
 {
 public:
     void testTdf116830();
+    void testTdf116925();
 
     CPPUNIT_TEST_SUITE(SwLayoutWriter);
     CPPUNIT_TEST(testTdf116830);
+    CPPUNIT_TEST(testTdf116925);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -62,6 +64,26 @@ void SwLayoutWriter::testTdf116830()
     assertXPath(pXmlDoc, "/metafile/push[1]/push[1]/push[1]/push[3]/push[1]/rect", 1);
 }
 
+void SwLayoutWriter::testTdf116925()
+{
+    SwDoc* pDoc = createDoc("tdf116925.docx");
+    SwDocShell* pShell = pDoc->GetDocShell();
+
+    // Dump the rendering of the first page as an XML file.
+    std::shared_ptr<GDIMetaFile> xMetaFile = pShell->GetPreviewMetaFile();
+    MetafileXmlDump dumper;
+    xmlDocPtr pXmlDoc = dumper.dumpAndParse(*xMetaFile);
+    CPPUNIT_ASSERT(pXmlDoc);
+
+    assertXPathContent(pXmlDoc,
+                       "/metafile/push[1]/push[1]/push[1]/push[4]/push[1]/push[3]/textarray/text",
+                       "hello");
+    // This failed, text color was #000000.
+    assertXPath(
+        pXmlDoc,
+        "/metafile/push[1]/push[1]/push[1]/push[4]/push[1]/push[3]/textcolor[@color='#ffffff']", 1);
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(SwLayoutWriter);
 CPPUNIT_PLUGIN_IMPLEMENT();
 
diff --git a/sw/source/core/layout/paintfrm.cxx b/sw/source/core/layout/paintfrm.cxx
index 4b8d38cdecdb..2136601cd637 100644
--- a/sw/source/core/layout/paintfrm.cxx
+++ b/sw/source/core/layout/paintfrm.cxx
@@ -100,6 +100,7 @@
 #include <edtwin.hxx>
 #include <view.hxx>
 #include <paintfrm.hxx>
+#include <textboxhelper.hxx>
 #include <o3tl/typed_flags_set.hxx>
 
 #include <vcl/BitmapTools.hxx>
@@ -7494,7 +7495,30 @@ bool SwFrame::GetBackgroundBrush(
             return false;
 
         if (pFrame->supportsFullDrawingLayerFillAttributeSet())
-            rFillAttributes = pFrame->getSdrAllFillAttributesHelper();
+        {
+            bool bTextBox = false;
+            if (pFrame->IsFlyFrame())
+            {
+                const SwFlyFrame* pFlyFrame = static_cast<const SwFlyFrame*>(pFrame);
+                SwFrameFormat* pShape
+                    = SwTextBoxHelper::getOtherTextBoxFormat(pFlyFrame->GetFormat(), RES_FLYFRMFMT);
+                if (pShape)
+                {
+                    SdrObject* pObject = pShape->FindRealSdrObject();
+                    if (pObject)
+                    {
+                        // Work with the fill attributes of the shape of the fly frame.
+                        rFillAttributes.reset(
+                            new drawinglayer::attribute::SdrAllFillAttributesHelper(
+                                pObject->GetMergedItemSet()));
+                        bTextBox = true;
+                    }
+                }
+            }
+
+            if (!bTextBox)
+                rFillAttributes = pFrame->getSdrAllFillAttributesHelper();
+        }
         const SvxBrushItem &rBack = pFrame->GetAttrSet()->GetBackground();
 
         if( pFrame->IsSctFrame() )


More information about the Libreoffice-commits mailing list