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

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Fri Sep 7 12:51:12 UTC 2018


 filter/source/msfilter/escherex.cxx   |   13 ++++++++-----
 filter/source/msfilter/msdffimp.cxx   |   14 ++++++++++++--
 oox/source/drawingml/shape.cxx        |    3 +++
 sc/qa/unit/data/xls/hiddenShape.xls   |binary
 sc/qa/unit/subsequent_export-test.cxx |   30 ++++++++++++++++++++++++++++++
 5 files changed, 53 insertions(+), 7 deletions(-)

New commits:
commit b38065ea941375bf4f78f13314e84f4a875545d9
Author:     Aron Budea <aron.budea at collabora.com>
AuthorDate: Mon Sep 3 02:42:44 2018 +0200
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Fri Sep 7 14:50:40 2018 +0200

    tdf#108691, tdf#119639 Don't print hidden objects in XLS(X)
    
    In Excel hidden drawing objects aren't printed. When not
    hidden, printing is controlled by a separate 'Print object'
    setting.
    
    Only rely visibility setting for now, but properly:
    visible means also printed, hidden means not printed.
    Ie. import visible property also as printable, and only
    output visible property in XLS(X) formats.
    
    For the future, in XLSX format printability is controlled by
    attribute 'fPrintsWithSheet' of element 'clientData', don't
    know about XLS, there fUsefPrint/fPrint bits don't appear to
    be used anymore (see note in tdf#119639).
    
    Change-Id: I728107b30056f7bf073f2fefddece1bef1eb2e7a
    Reviewed-on: https://gerrit.libreoffice.org/59915
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/filter/source/msfilter/escherex.cxx b/filter/source/msfilter/escherex.cxx
index 6bd7638a8cc9..b5951b441f9c 100644
--- a/filter/source/msfilter/escherex.cxx
+++ b/filter/source/msfilter/escherex.cxx
@@ -1255,17 +1255,20 @@ void EscherPropertyContainer::CreateShapeProperties( const uno::Reference<drawin
     uno::Reference< beans::XPropertySet > aXPropSet( rXShape, uno::UNO_QUERY );
     if ( aXPropSet.is() )
     {
-        bool bVal = false;
+        bool bVisible = false;
+        bool bPrintable = false;
         uno::Any aAny;
         sal_uInt32 nShapeAttr = 0;
-        if (EscherPropertyValueHelper::GetPropertyValue(aAny, aXPropSet, "Visible", true) && (aAny >>= bVal))
+        if (EscherPropertyValueHelper::GetPropertyValue(aAny, aXPropSet, "Visible", true) && (aAny >>= bVisible))
         {
-            if ( !bVal )
+            if ( !bVisible )
                 nShapeAttr |= 0x20002;  // set fHidden = true
         }
-        if (EscherPropertyValueHelper::GetPropertyValue(aAny, aXPropSet, "Printable", true) && (aAny >>= bVal))
+        // This property (fPrint) isn't used in Excel anymore, leaving it for legacy reasons
+        // one change, based on XLSX: hidden implies not printed, let's not export the fPrint property in that case
+        if (bVisible && EscherPropertyValueHelper::GetPropertyValue(aAny, aXPropSet, "Printable", true) && (aAny >>= bPrintable))
         {
-            if ( !bVal )
+            if ( !bPrintable )
                 nShapeAttr |= 0x10000;  // set fPrint = false;
         }
         if ( nShapeAttr )
diff --git a/filter/source/msfilter/msdffimp.cxx b/filter/source/msfilter/msdffimp.cxx
index 9084e1b42638..0938905edb52 100644
--- a/filter/source/msfilter/msdffimp.cxx
+++ b/filter/source/msfilter/msdffimp.cxx
@@ -4864,8 +4864,18 @@ SdrObject* SvxMSDffManager::ImportShape( const DffRecordHeader& rHd, SvStream& r
     if ( pRet )
     {
         sal_Int32 nGroupProperties( GetPropertyValue( DFF_Prop_fPrint, 0 ) );
-        pRet->SetVisible( ( nGroupProperties & 2 ) == 0 );
-        pRet->SetPrintable( ( nGroupProperties & 1 ) != 0 );
+        const bool bVisible = ( ( nGroupProperties & 2 ) == 0 );
+        pRet->SetVisible( bVisible );
+        // In Excel hidden means not printed
+        if ( !bVisible )
+        {
+            pRet->SetPrintable( false );
+        }
+        else
+        {
+            // This property isn't used in Excel anymore, leaving it for legacy reasons
+            pRet->SetPrintable( ( nGroupProperties & 1 ) != 0 );
+        }
     }
 
     //Import alt text as description
diff --git a/oox/source/drawingml/shape.cxx b/oox/source/drawingml/shape.cxx
index 6b5f9ac79b0e..0f5437dc9519 100644
--- a/oox/source/drawingml/shape.cxx
+++ b/oox/source/drawingml/shape.cxx
@@ -842,6 +842,9 @@ Reference< XShape > const & Shape::createAndInsert(
             SAL_INFO("oox.drawingml", "Shape::createAndInsert: invisible shape with id='" << msId << "'");
             const OUString sVisible( "Visible" );
             xSet->setPropertyValue( sVisible, Any( false ) );
+            // In Excel hidden means not printed, let's use visibility for now until that's handled separately
+            const OUString sPrintable( "Printable" );
+            xSet->setPropertyValue( sPrintable, Any( false ) );
         }
 
         ActionLockGuard const alg(mxShape);
diff --git a/sc/qa/unit/data/xls/hiddenShape.xls b/sc/qa/unit/data/xls/hiddenShape.xls
new file mode 100644
index 000000000000..339a39c9acbf
Binary files /dev/null and b/sc/qa/unit/data/xls/hiddenShape.xls differ
diff --git a/sc/qa/unit/subsequent_export-test.cxx b/sc/qa/unit/subsequent_export-test.cxx
index 5d0f1dce5313..77f7de435ec1 100644
--- a/sc/qa/unit/subsequent_export-test.cxx
+++ b/sc/qa/unit/subsequent_export-test.cxx
@@ -188,6 +188,7 @@ public:
     void testSheetCondensedCharacterSpaceXLSX();
     void testTextUnderlineColorXLSX();
     void testSheetRunParagraphPropertyXLSX();
+    void testHiddenShapeXLS();
     void testHiddenShapeXLSX();
     void testShapeAutofitXLSX();
     void testHyperlinkXLSX();
@@ -302,6 +303,7 @@ public:
     CPPUNIT_TEST(testSheetCondensedCharacterSpaceXLSX);
     CPPUNIT_TEST(testTextUnderlineColorXLSX);
     CPPUNIT_TEST(testSheetRunParagraphPropertyXLSX);
+    CPPUNIT_TEST(testHiddenShapeXLS);
     CPPUNIT_TEST(testHiddenShapeXLSX);
     CPPUNIT_TEST(testShapeAutofitXLSX);
     CPPUNIT_TEST(testHyperlinkXLSX);
@@ -3576,14 +3578,42 @@ void ScExportTest::testPreserveTextWhitespace2XLSX()
     xDocSh->DoClose();
 }
 
+void ScExportTest::testHiddenShapeXLS()
+{
+    ScDocShellRef xDocSh = loadDoc("hiddenShape.", FORMAT_XLS);
+    CPPUNIT_ASSERT(xDocSh.is());
+
+    ScDocument& rDoc = xDocSh->GetDocument();
+    CPPUNIT_ASSERT(rDoc.GetTableCount() > 0);
+    ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer();
+    SdrPage* pPage = pDrawLayer->GetPage(0);
+    CPPUNIT_ASSERT(pPage);
+    SdrObject* pObj = pPage->GetObj(0);
+    CPPUNIT_ASSERT(pObj);
+    CPPUNIT_ASSERT_MESSAGE("Drawing object should not be visible.", !pObj->IsVisible());
+    CPPUNIT_ASSERT_MESSAGE("Drawing object should not be printable.", !pObj->IsPrintable());
+    xDocSh->DoClose();
+}
+
 void ScExportTest::testHiddenShapeXLSX()
 {
     ScDocShellRef xDocSh = loadDoc("hiddenShape.", FORMAT_XLSX);
     CPPUNIT_ASSERT(xDocSh.is());
 
+    ScDocument& rDoc = xDocSh->GetDocument();
+    CPPUNIT_ASSERT(rDoc.GetTableCount() > 0);
+    ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer();
+    SdrPage* pPage = pDrawLayer->GetPage(0);
+    CPPUNIT_ASSERT(pPage);
+    SdrObject* pObj = pPage->GetObj(0);
+    CPPUNIT_ASSERT(pObj);
+    CPPUNIT_ASSERT_MESSAGE("Drawing object should not be visible.", !pObj->IsVisible());
+    CPPUNIT_ASSERT_MESSAGE("Drawing object should not be printable.", !pObj->IsPrintable());
+
     xmlDocPtr pDoc = XPathHelper::parseExport2(*this, *xDocSh, m_xSFactory, "xl/drawings/drawing1.xml", FORMAT_XLSX);
     CPPUNIT_ASSERT(pDoc);
     assertXPath(pDoc, "/xdr:wsDr/xdr:twoCellAnchor/xdr:sp[1]/xdr:nvSpPr/xdr:cNvPr", "hidden", "1");
+    xDocSh->DoClose();
 }
 
 void ScExportTest::testShapeAutofitXLSX()


More information about the Libreoffice-commits mailing list