[Libreoffice-commits] core.git: Branch 'libreoffice-4-2' - include/oox oox/source sd/qa

Matúš Kukan matus.kukan at collabora.com
Fri Sep 12 02:12:10 PDT 2014


 include/oox/drawingml/shape.hxx          |    1 
 oox/source/drawingml/fillproperties.cxx  |    8 ++++-
 oox/source/drawingml/table/tablecell.cxx |   36 +++++++++++++++++++---
 sd/qa/unit/data/pptx/bnc480256.pptx      |binary
 sd/qa/unit/import-tests.cxx              |   49 +++++++++++++++++++++++++++++++
 5 files changed, 88 insertions(+), 6 deletions(-)

New commits:
commit 9ccb70b397bbc90a39553cfd1ad1c897a01f101f
Author: Matúš Kukan <matus.kukan at collabora.com>
Date:   Tue Sep 9 10:37:23 2014 +0200

    bnc#480256: OOXML import: Respect table background properties a bit more
    
    Only getBackgroundFillProperties() (fill) was used.
    Use also getBackgroundFillStyleRef() (fillRef).
    Also, do not replace table background color value with cell color,
    we have to interpolate the two colors (if cell color is transparent).
    
    Unfortunately, we don't use background table property in LibreOffice, so
    this seems to be a best workaround.
    
    (cherry picked from commit 43efd9b40d40b791a2c2deedcac36b99f7efb2cf)
    
    And add unit test.
    (cherry picked from commit 5681725f1a2535a13b86104d8b8a33f750f34efc)
    
    Change-Id: I21bcc87a149c9f6d865ebee4012132ccc3a54af2
    Reviewed-on: https://gerrit.libreoffice.org/11352
    Reviewed-by: Andras Timar <andras.timar at collabora.com>
    Tested-by: Andras Timar <andras.timar at collabora.com>

diff --git a/include/oox/drawingml/shape.hxx b/include/oox/drawingml/shape.hxx
index dd0daa9..0811a91 100644
--- a/include/oox/drawingml/shape.hxx
+++ b/include/oox/drawingml/shape.hxx
@@ -50,6 +50,7 @@ struct ShapeStyleRef
 {
     Color               maPhClr;
     sal_Int32           mnThemedIdx;
+    ShapeStyleRef() : mnThemedIdx(0) {}
 };
 
 typedef ::std::map< sal_Int32, ShapeStyleRef > ShapeStyleRefMap;
diff --git a/oox/source/drawingml/fillproperties.cxx b/oox/source/drawingml/fillproperties.cxx
index a81a5d2..fba879f 100644
--- a/oox/source/drawingml/fillproperties.cxx
+++ b/oox/source/drawingml/fillproperties.cxx
@@ -232,7 +232,13 @@ Color FillProperties::getBestSolidColor() const
         break;
         case XML_gradFill:
             if( !maGradientProps.maGradientStops.empty() )
-                aSolidColor = maGradientProps.maGradientStops.begin()->second;
+            {
+                GradientFillProperties::GradientStopMap::const_iterator aGradientStop =
+                    maGradientProps.maGradientStops.begin();
+                if (maGradientProps.maGradientStops.size() > 2)
+                    ++aGradientStop;
+                aSolidColor = aGradientStop->second;
+            }
         break;
         case XML_pattFill:
             aSolidColor = maPatternProps.maPattBgColor.isUsed() ? maPatternProps.maPattBgColor : maPatternProps.maPattFgColor;
diff --git a/oox/source/drawingml/table/tablecell.cxx b/oox/source/drawingml/table/tablecell.cxx
index 1bb6241..583d7aa 100644
--- a/oox/source/drawingml/table/tablecell.cxx
+++ b/oox/source/drawingml/table/tablecell.cxx
@@ -21,8 +21,11 @@
 #include "oox/drawingml/table/tableproperties.hxx"
 #include "oox/drawingml/shapepropertymap.hxx"
 #include "oox/drawingml/textbody.hxx"
+#include "oox/drawingml/theme.hxx"
 #include "oox/core/xmlfilterbase.hxx"
 #include "oox/helper/propertyset.hxx"
+#include <basegfx/color/bcolor.hxx>
+#include <tools/color.hxx>
 #include <com/sun/star/container/XNameContainer.hpp>
 #include <com/sun/star/beans/XMultiPropertySet.hpp>
 #include <com/sun/star/table/XTable.hpp>
@@ -99,7 +102,7 @@ void applyTableStylePart( oox::drawingml::FillProperties& rFillProperties,
                           oox::drawingml::LineProperties& rBottomLeftToTopRightBorder,
                           TableStylePart& rTableStylePart )
 {
-    boost::shared_ptr< ::oox::drawingml::FillProperties >& rPartFillPropertiesPtr( rTableStylePart.getFillProperties() );
+    ::oox::drawingml::FillPropertiesPtr& rPartFillPropertiesPtr( rTableStylePart.getFillProperties() );
     if ( rPartFillPropertiesPtr.get() )
         rFillProperties.assignUsed( *rPartFillPropertiesPtr );
 
@@ -168,10 +171,6 @@ void TableCell::pushToXCell( const ::oox::core::XmlFilterBase& rFilterBase, ::oo
     oox::drawingml::LineProperties aLinePropertiesTopLeftToBottomRight;
     oox::drawingml::LineProperties aLinePropertiesBottomLeftToTopRight;
 
-    boost::shared_ptr< ::oox::drawingml::FillProperties >& rBackgroundFillPropertiesPtr( rTable.getBackgroundFillProperties() );
-    if ( rBackgroundFillPropertiesPtr.get() )
-        aFillProperties.assignUsed( *rBackgroundFillPropertiesPtr );
-
     applyTableStylePart( aFillProperties, aTextStyleProps,
         aLinePropertiesLeft,
         aLinePropertiesRight,
@@ -352,6 +351,33 @@ void TableCell::pushToXCell( const ::oox::core::XmlFilterBase& rFilterBase, ::oo
 
     aFillProperties.assignUsed( maFillProperties );
     ShapePropertyMap aPropMap( rFilterBase.getModelObjectHelper() );
+
+    Color aBgColor;
+    sal_Int32 nPhClr = API_RGB_TRANSPARENT;
+    boost::shared_ptr< ::oox::drawingml::FillProperties >& rBackgroundFillPropertiesPtr( rTable.getBackgroundFillProperties() );
+    ::oox::drawingml::ShapeStyleRef& rBackgroundFillStyle( rTable.getBackgroundFillStyleRef() );
+    if (rBackgroundFillPropertiesPtr.get())
+        aBgColor = rBackgroundFillPropertiesPtr->getBestSolidColor();
+    else if (rBackgroundFillStyle.mnThemedIdx != 0)
+    {
+        if (const Theme* pTheme = rFilterBase.getCurrentTheme())
+        {
+            aBgColor = pTheme->getFillStyle(rBackgroundFillStyle.mnThemedIdx)->getBestSolidColor();
+            nPhClr = rBackgroundFillStyle.maPhClr.getColor(rFilterBase.getGraphicHelper());
+        }
+    }
+    if (aBgColor.isUsed())
+    {
+        const Color& rCellColor = aFillProperties.getBestSolidColor();
+        const double fTransparency = rCellColor.isUsed() ? 0.01 * rCellColor.getTransparency() : 1.0;
+        ::Color nBgColor( aBgColor.getColor(rFilterBase.getGraphicHelper(), nPhClr) );
+        ::Color nCellColor( rCellColor.getColor(rFilterBase.getGraphicHelper()) );
+        ::Color aResult( basegfx::interpolate(nBgColor.getBColor(), nCellColor.getBColor(), 1.0 - fTransparency) );
+        aFillProperties.maFillColor.clearTransformations();
+        aFillProperties.maFillColor.setSrgbClr(aResult.GetRGBColor());
+        aFillProperties.moFillType.set(XML_solidFill);
+    }
+
     // TODO: phClr?
     aFillProperties.pushToPropMap( aPropMap, rFilterBase.getGraphicHelper() );
     PropertySet( xPropSet ).setProperties( aPropMap );
diff --git a/sd/qa/unit/data/pptx/bnc480256.pptx b/sd/qa/unit/data/pptx/bnc480256.pptx
new file mode 100755
index 0000000..71e91c2
Binary files /dev/null and b/sd/qa/unit/data/pptx/bnc480256.pptx differ
diff --git a/sd/qa/unit/import-tests.cxx b/sd/qa/unit/import-tests.cxx
index 7920e0e..df7384e 100644
--- a/sd/qa/unit/import-tests.cxx
+++ b/sd/qa/unit/import-tests.cxx
@@ -25,6 +25,7 @@
 #include <svx/svdogrp.hxx>
 #include <svx/svdomedia.hxx>
 #include <svx/svdoole2.hxx>
+#include <svx/svdotable.hxx>
 #include <svx/xflclit.hxx>
 #include <animations/animationnodehelper.hxx>
 #include <sax/tools/converter.hxx>
@@ -65,6 +66,7 @@ public:
     void testBnc870233_2();
     void testBnc880763();
     void testBnc862510_5();
+    void testBnc480256();
     void testCreationDate();
 
     CPPUNIT_TEST_SUITE(SdFiltersTest);
@@ -82,6 +84,7 @@ public:
     CPPUNIT_TEST(testBnc870233_2);
     CPPUNIT_TEST(testBnc880763);
     CPPUNIT_TEST(testBnc862510_5);
+    CPPUNIT_TEST(testBnc480256);
     CPPUNIT_TEST(testCreationDate);
 
     CPPUNIT_TEST_SUITE_END();
@@ -631,6 +634,52 @@ void SdFiltersTest::testBnc862510_5()
     xDocShRef->DoClose();
 }
 
+void SdFiltersTest::testBnc480256()
+{
+    ::sd::DrawDocShellRef xDocShRef = loadURL(getURLFromSrc("/sd/qa/unit/data/pptx/bnc480256.pptx"));
+    // In the document, there are two tables with table background properties.
+    // Make sure colors are set properly for individual cells.
+
+    // TODO: If you are working on improving table background support, expect
+    // this unit test to fail. In that case, feel free to change the numbers.
+
+    SdDrawDocument *pDoc = xDocShRef->GetDoc();
+    CPPUNIT_ASSERT_MESSAGE( "no document", pDoc != NULL );
+    const SdrPage *pPage = pDoc->GetPage(1);
+    CPPUNIT_ASSERT_MESSAGE( "no page", pPage != NULL );
+
+    sdr::table::SdrTableObj *pTableObj;
+    uno::Reference< table::XCellRange > xTable;
+    uno::Reference< beans::XPropertySet > xCell;
+    sal_Int32 nColor;
+
+    pTableObj = dynamic_cast<sdr::table::SdrTableObj*>(pPage->GetObj(0));
+    CPPUNIT_ASSERT( pTableObj );
+    xTable.set(pTableObj->getTable(), uno::UNO_QUERY_THROW);
+
+    xCell.set(xTable->getCellByPosition(0, 0), uno::UNO_QUERY_THROW);
+    xCell->getPropertyValue("FillColor") >>= nColor;
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(10208238), nColor);
+
+    xCell.set(xTable->getCellByPosition(0, 1), uno::UNO_QUERY_THROW);
+    xCell->getPropertyValue("FillColor") >>= nColor;
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(13032959), nColor);
+
+    pTableObj = dynamic_cast<sdr::table::SdrTableObj*>(pPage->GetObj(1));
+    CPPUNIT_ASSERT( pTableObj );
+    xTable.set(pTableObj->getTable(), uno::UNO_QUERY_THROW);
+
+    xCell.set(xTable->getCellByPosition(0, 0), uno::UNO_QUERY_THROW);
+    xCell->getPropertyValue("FillColor") >>= nColor;
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(7056614), nColor);
+
+    xCell.set(xTable->getCellByPosition(0, 1), uno::UNO_QUERY_THROW);
+    xCell->getPropertyValue("FillColor") >>= nColor;
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(4626400), nColor);
+
+    xDocShRef->DoClose();
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(SdFiltersTest);
 
 CPPUNIT_PLUGIN_IMPLEMENT();


More information about the Libreoffice-commits mailing list