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

Ravindra_Vidhate ravindra.vidhate at synerzip.com
Mon Jul 20 14:11:40 PDT 2015


 sc/qa/unit/data/xlsx/cell-anchored-hidden-shapes.xlsx |binary
 sc/qa/unit/subsequent_filters-test.cxx                |   23 ++++++++++++++++++
 sc/source/filter/inc/drawingbase.hxx                  |    8 ++++++
 sc/source/filter/oox/drawingbase.cxx                  |   14 ++++++++++
 sc/source/filter/oox/drawingfragment.cxx              |    4 +++
 5 files changed, 49 insertions(+)

New commits:
commit b71901da42a0429ff759b96bc9dd7cfd1bd189ac
Author: Ravindra_Vidhate <ravindra.vidhate at synerzip.com>
Date:   Fri May 15 14:35:40 2015 +0530

    tdf#68868: better handle xlsx with samecell anchor image
    
    Problem Description :
    In the bugzill attached file, a image is anchored to the cell,
    it is shown as stretched image after opening in the LO.
    The image anchor attribute <xdr:from> and <xdr:to> are having the
    same value. It means <xdr:col>, <xdr:colOff>, <xdr:row>, <xdr:rowOff>
    tag values of from and to are the same.
    
    So this image will have width and height as 1.
    
    Although, this is very rare case, where from and to has the same
    attribute values. Eventhough, we tried to create such kind of EXCEL
    file but failed to do so.
    
    Solution :
    When twocellAnchor attributes of from and to has the same value, then
    hide the shape.
    If we avoid to add the shape, then the original image file will be
    shown as stretched. If we don't add it into the shape, the original
    image will not be preserved.
    
    Change-Id: I48ea1cffcdfb013cec115ef8df5401e532fd2efd

diff --git a/sc/qa/unit/data/xlsx/cell-anchored-hidden-shapes.xlsx b/sc/qa/unit/data/xlsx/cell-anchored-hidden-shapes.xlsx
new file mode 100755
index 0000000..7e79cc3
Binary files /dev/null and b/sc/qa/unit/data/xlsx/cell-anchored-hidden-shapes.xlsx differ
diff --git a/sc/qa/unit/subsequent_filters-test.cxx b/sc/qa/unit/subsequent_filters-test.cxx
index f9b35fa..9ab7f16 100644
--- a/sc/qa/unit/subsequent_filters-test.cxx
+++ b/sc/qa/unit/subsequent_filters-test.cxx
@@ -172,6 +172,7 @@ public:
     void testNumberFormatCSV();
 
     void testCellAnchoredShapesODS();
+    void testCellAnchoredHiddenShapesXLSX();
 
     void testPivotTableBasicODS();
     void testPivotTableNamedRangeSourceODS();
@@ -261,6 +262,7 @@ public:
     CPPUNIT_TEST(testNumberFormatCSV);
 
     CPPUNIT_TEST(testCellAnchoredShapesODS);
+    CPPUNIT_TEST(testCellAnchoredHiddenShapesXLSX);
 
     CPPUNIT_TEST(testPivotTableBasicODS);
     CPPUNIT_TEST(testPivotTableNamedRangeSourceODS);
@@ -1701,6 +1703,27 @@ void ScFiltersTest::testCellAnchoredShapesODS()
     xDocSh->DoClose();
 }
 
+void ScFiltersTest::testCellAnchoredHiddenShapesXLSX()
+{
+    ScDocShellRef xDocSh = loadDoc("cell-anchored-hidden-shapes.", XLSX);
+    CPPUNIT_ASSERT_MESSAGE("Failed to load cell-anchored-shapes.xlsx", xDocSh.Is());
+
+    // There are two cell-anchored objects on the first sheet.
+    ScDocument& rDoc = xDocSh->GetDocument();
+
+    CPPUNIT_ASSERT_MESSAGE("There should be at least one sheet.", rDoc.GetTableCount() > 0);
+
+    ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer();
+    SdrPage* pPage = pDrawLayer->GetPage(0);
+    CPPUNIT_ASSERT_MESSAGE("draw page for sheet 1 should exist.", pPage);
+    const size_t nCount = pPage->GetObjCount();
+    CPPUNIT_ASSERT_MESSAGE("There should be 2 shapes.", !(nCount == 2));
+
+    SdrObject* pObj = pPage->GetObj(1);
+    CPPUNIT_ASSERT_MESSAGE("Failed to get drawing object.", pObj);
+    CPPUNIT_ASSERT_MESSAGE("The shape having same twocellanchor from and to attribute values, is visible.", !pObj->IsVisible());
+}
+
 namespace {
 
 class FindDimByName : std::unary_function<const ScDPSaveDimension*, bool>
diff --git a/sc/source/filter/inc/drawingbase.hxx b/sc/source/filter/inc/drawingbase.hxx
index 85f529a..a0dc337 100644
--- a/sc/source/filter/inc/drawingbase.hxx
+++ b/sc/source/filter/inc/drawingbase.hxx
@@ -92,6 +92,14 @@ public:
     /** Imports the client anchor settings from a VML element. */
     void                importVmlAnchor( const OUString& rAnchor );
 
+    /** Checks whether the shape is visible based on the anchor
+
+        If From and To anchor has the same attribute values, the shape
+        will not have width and height and thus we can assume that
+        such kind of shape will be not be visible
+    */
+    bool isAnchorValid() const;
+
     /** Calculates the resulting shape anchor in EMUs. */
     ::oox::drawingml::EmuRectangle calcAnchorRectEmu(
                             const ::com::sun::star::awt::Size& rPageSizeHmm ) const;
diff --git a/sc/source/filter/oox/drawingbase.cxx b/sc/source/filter/oox/drawingbase.cxx
index c07d5ea..6f6a06c 100644
--- a/sc/source/filter/oox/drawingbase.cxx
+++ b/sc/source/filter/oox/drawingbase.cxx
@@ -170,6 +170,20 @@ void ShapeAnchor::importVmlAnchor( const OUString& rAnchor )
     }
 }
 
+bool ShapeAnchor::isAnchorValid() const
+{
+    // Checks whether the shape is visible based on the anchor
+    // if From and To anchor has the same attribute values, the shape will not have width and height
+    // and thus we can assume that such kind of shape will be not be visible
+    if (meAnchorType == ANCHOR_TWOCELL &&
+        (maTo.mnRow == maFrom.mnRow && maTo.mnCol == maFrom.mnCol) &&
+        (maTo.mnColOffset == maFrom.mnColOffset && maTo.mnRowOffset == maFrom.mnRowOffset))
+    {
+        return false;
+    }
+    return true;
+}
+
 EmuRectangle ShapeAnchor::calcAnchorRectEmu( const css::awt::Size& rPageSizeHmm ) const
 {
     AddressConverter& rAddrConv = getAddressConverter();
diff --git a/sc/source/filter/oox/drawingfragment.cxx b/sc/source/filter/oox/drawingfragment.cxx
index 967b0ff..d1824ec 100644
--- a/sc/source/filter/oox/drawingfragment.cxx
+++ b/sc/source/filter/oox/drawingfragment.cxx
@@ -256,6 +256,7 @@ void DrawingFragment::onEndElement()
                 if ( getCurrentElement() == XDR_TOKEN( twoCellAnchor ) )
                     mxShape->setRotation(0);
                 EmuRectangle aShapeRectEmu = mxAnchor->calcAnchorRectEmu( getDrawPageSize() );
+                const bool bIsShapeVisible = mxAnchor->isAnchorValid();
                 if( (aShapeRectEmu.X >= 0) && (aShapeRectEmu.Y >= 0) && (aShapeRectEmu.Width >= 0) && (aShapeRectEmu.Height >= 0) )
                 {
                     // TODO: DrawingML implementation expects 32-bit coordinates for EMU rectangles (change that to EmuRectangle)
@@ -270,6 +271,9 @@ void DrawingFragment::onEndElement()
                     mxShape->setSize(Size(aShapeRectEmu.Width, aShapeRectEmu.Height));
 
                     basegfx::B2DHomMatrix aTransformation;
+                    if ( !bIsShapeVisible)
+                        mxShape->setHidden(true);
+
                     mxShape->addShape( getOoxFilter(), &getTheme(), mxDrawPage, aTransformation, mxShape->getFillProperties(), &aShapeRectEmu32 );
 
                     /*  Collect all shape positions in the WorksheetHelper base


More information about the Libreoffice-commits mailing list