[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.4' - filter/source sd/qa

Marco Cecchetti (via logerrit) logerrit at kemper.freedesktop.org
Thu Jan 14 13:17:40 UTC 2021


 filter/source/svg/presentation_engine.js |   22 ++++++++-
 filter/source/svg/svgexport.cxx          |   73 +++++++++++++++++++++----------
 sd/qa/unit/SVGExportTests.cxx            |    2 
 3 files changed, 72 insertions(+), 25 deletions(-)

New commits:
commit e46be321b928992e2cc2622cc4af69b949d2e5f2
Author:     Marco Cecchetti <marco.cecchetti at collabora.com>
AuthorDate: Mon Jan 11 10:28:57 2021 +0100
Commit:     Marco Cecchetti <marco.cecchetti at collabora.com>
CommitDate: Thu Jan 14 14:17:05 2021 +0100

    filter: svg: slide with a custom background are not exported correctly
    
    When a slide has a custom background, the background overlaps any
    master page object: text fields, shapes, ...
    
    Change-Id: Icc410617760502fa4092cfe248155b3e20906abb
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109089
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Marco Cecchetti <marco.cecchetti at collabora.com>

diff --git a/filter/source/svg/presentation_engine.js b/filter/source/svg/presentation_engine.js
index b4c8d3a63078..ce68bc6484fe 100644
--- a/filter/source/svg/presentation_engine.js
+++ b/filter/source/svg/presentation_engine.js
@@ -359,7 +359,7 @@ function uniqueArray(src, key, sort) {
  * @returns {String|Undefined} prefixed
  */
 function prefixed(obj, property) {
-    // tml: Have to check for obj being undefined 
+    // tml: Have to check for obj being undefined
     if (obj === undefined) {
         return undefined;
     }
@@ -4436,6 +4436,7 @@ var aOOOAttrSlide = 'slide';
 var aOOOAttrMaster = 'master';
 var aOOOAttrSlideDuration = 'slide-duration';
 var aOOOAttrHasTransition = 'has-transition';
+var aOOOAttrHasCustomBackground = 'has-custom-background';
 var aOOOAttrBackgroundVisibility = 'background-visibility';
 var aOOOAttrMasterObjectsVisibility = 'master-objects-visibility';
 var aOOOAttrPageNumberVisibility = 'page-number-visibility';
@@ -5056,10 +5057,20 @@ function MetaSlide( sMetaSlideId, aMetaDoc )
     assert( this.pageElement,
             'MetaSlide: page element <' + this.slideId + '> not found.' );
 
+    // The slide custom background element and its id attribute.
+    this.backgroundElement = getElementByClassName( this.pageElement, 'Background' );
+    if( this.backgroundElement )
+    {
+        this.backgroundId = this.backgroundElement.getAttribute( 'id' );
+    }
+
     // We initialize the MasterPage object that provides direct access to
     // the target master page element.
     this.masterPage = this.initMasterPage();
 
+    // We check if the slide has a custom background which overrides the one of the targeted master page
+    this.bHasCustomBackground = this.initHasCustomBackground();
+
     // We initialize visibility properties of the target master page elements.
     this.nAreMasterObjectsVisible     = this.initVisibilityProperty( aOOOAttrMasterObjectsVisibility,  VISIBLE );
     this.nIsBackgroundVisible         = this.initVisibilityProperty( aOOOAttrBackgroundVisibility,     VISIBLE );
@@ -5181,6 +5192,12 @@ initHasTransition : function()
     return ( sHasTransition === 'true' );
 },
 
+initHasCustomBackground : function()
+{
+    var sHasCustomBackground = this.element.getAttributeNS( NSS['ooo'], aOOOAttrHasCustomBackground );
+    return ( sHasCustomBackground === 'true' );
+},
+
 initVisibilityProperty : function( aVisibilityAttribute, nDefaultValue )
 {
     var nVisibility = nDefaultValue;
@@ -5660,10 +5677,11 @@ MasterPageView.prototype.createElement = function()
     // init the Background element
     if( this.aMetaSlide.nIsBackgroundVisible )
     {
+        var nBackgroundId = this.aMetaSlide.bHasCustomBackground ? this.aMetaSlide.backgroundId : this.aMasterPage.backgroundId;
         this.aBackgroundElement = theDocument.createElementNS( NSS['svg'], 'use' );
         this.aBackgroundElement.setAttribute( 'class', 'Background' );
         setNSAttribute( 'xlink', this.aBackgroundElement,
-                        'href', '#' + this.aMasterPage.backgroundId );
+                        'href', '#' + nBackgroundId );
 
         // node linking
         aMasterPageViewElement.appendChild( this.aBackgroundElement );
diff --git a/filter/source/svg/svgexport.cxx b/filter/source/svg/svgexport.cxx
index d30415380207..425a13161024 100644
--- a/filter/source/svg/svgexport.cxx
+++ b/filter/source/svg/svgexport.cxx
@@ -34,6 +34,8 @@
 #include <com/sun/star/xml/sax/Writer.hpp>
 #include <com/sun/star/beans/XPropertySet.hpp>
 #include <com/sun/star/drawing/ShapeCollection.hpp>
+#include <com/sun/star/drawing/BitmapMode.hpp>
+#include <com/sun/star/drawing/RectanglePoint.hpp>
 
 #include <rtl/bootstrap.hxx>
 #include <svtools/miscopt.hxx>
@@ -87,6 +89,7 @@ static const char    aOOOElemTextField[] = NSPREFIX "text_field";
 // ooo xml attributes for meta_slide
 static const char    aOOOAttrSlide[] = NSPREFIX "slide";
 static const char    aOOOAttrMaster[] = NSPREFIX "master";
+static const char    aOOOAttrHasCustomBackground[] = NSPREFIX "has-custom-background";
 static const char    aOOOAttrBackgroundVisibility[] = NSPREFIX "background-visibility";
 static const char    aOOOAttrMasterObjectsVisibility[] = NSPREFIX "master-objects-visibility";
 static const char    aOOOAttrSlideDuration[] = NSPREFIX "slide-duration";
@@ -1145,6 +1148,19 @@ void SVGFilter::implGenerateMetaData()
                         VariableDateTimeField         aVariableDateTimeField;
                         FooterField                   aFooterField;
 
+                        // check if the slide has a custom background wich overlaps the matser page background
+                        Reference< XPropertySet > xBackground;
+                        xPropSet->getPropertyValue( "Background" ) >>= xBackground;
+                        if( xBackground.is() )
+                        {
+                            drawing::FillStyle aFillStyle;
+                            bool assigned = ( xBackground->getPropertyValue( "FillStyle" ) >>= aFillStyle );
+                            // has a custom background ?
+                            if( assigned && aFillStyle != drawing::FillStyle_NONE )
+                                mpSVGExport->AddAttribute( XML_NAMESPACE_NONE, aOOOAttrHasCustomBackground, "true" );
+
+                        }
+
                         xPropSet->getPropertyValue( "IsBackgroundVisible" )  >>= bBackgroundVisibility;
                         // in case the attribute is set to its default value it is not appended to the meta-slide element
                         if( !bBackgroundVisibility ) // visibility default value: 'visible'
@@ -1745,34 +1761,47 @@ bool SVGFilter::implExportPage( const OUString & sPageId,
             const GDIMetaFile& rMtf = (*mpObjects)[ rxPage ].GetRepresentation();
             if( rMtf.GetActionSize() )
             {
-                // background id = "bg-" + page id
-                OUString sBackgroundId = "bg-" + sPageId;
-                mpSVGExport->AddAttribute( XML_NAMESPACE_NONE, "id", sBackgroundId );
-
-                // At present (LibreOffice 3.4.0) the 'IsBackgroundVisible' property is not handled
-                // by Impress; anyway we handle this property as referring only to the visibility
-                // of the master page background. So if a slide has its own background object,
-                // the visibility of such a background object is always inherited from the visibility
-                // of the parent slide regardless of the value of the 'IsBackgroundVisible' property.
-                // This means that we need to set up the visibility attribute only for the background
-                // element of a master page.
-                if( !mbPresentation && bMaster )
+                // If this is not a master page wrap the slide custom background
+                // by a <defs> element.
+                // Slide custom background, if any, is referenced at a different position
+                // in order to not overlap background objects.
+                std::unique_ptr<SvXMLElementExport> xDefsExp;
+                if (!bMaster) // insert the <defs> open tag related to the slide background
+                {
+                    mpSVGExport->AddAttribute( XML_NAMESPACE_NONE, "class",  "SlideBackground" );
+                    xDefsExp.reset( new SvXMLElementExport( *mpSVGExport, XML_NAMESPACE_NONE, "defs", true, true ) );
+                }
                 {
-                    if( !mVisiblePagePropSet.bIsBackgroundVisible )
+                    // background id = "bg-" + page id
+                    OUString sBackgroundId = "bg-" + sPageId;
+                    mpSVGExport->AddAttribute( XML_NAMESPACE_NONE, "id", sBackgroundId );
+
+                    // At present (LibreOffice 3.4.0) the 'IsBackgroundVisible' property is not handled
+                    // by Impress; anyway we handle this property as referring only to the visibility
+                    // of the master page background. So if a slide has its own background object,
+                    // the visibility of such a background object is always inherited from the visibility
+                    // of the parent slide regardless of the value of the 'IsBackgroundVisible' property.
+                    // This means that we need to set up the visibility attribute only for the background
+                    // element of a master page.
+                    if( !mbPresentation && bMaster )
                     {
-                        mpSVGExport->AddAttribute( XML_NAMESPACE_NONE, "visibility", "hidden" );
+                        if( !mVisiblePagePropSet.bIsBackgroundVisible )
+                        {
+                            mpSVGExport->AddAttribute( XML_NAMESPACE_NONE, "visibility", "hidden" );
+                        }
                     }
-                }
 
-                mpSVGExport->AddAttribute( XML_NAMESPACE_NONE, "class",  "Background" );
+                    mpSVGExport->AddAttribute( XML_NAMESPACE_NONE, "class",  "Background" );
+
+                    // insert the <g> open tag related to the Background
+                    SvXMLElementExport aExp2( *mpSVGExport, XML_NAMESPACE_NONE, "g", true, true );
 
-                // insert the <g> open tag related to the Background
-                SvXMLElementExport aExp2( *mpSVGExport, XML_NAMESPACE_NONE, "g", true, true );
+                    // append all elements that make up the Background
+                    const Point aNullPt;
+                    mpSVGWriter->WriteMetaFile( aNullPt, rMtf.GetPrefSize(), rMtf, SVGWRITER_WRITE_FILL );
+                } // insert the </g> closing tag related to the Background
 
-                // append all elements that make up the Background
-                const Point aNullPt;
-                mpSVGWriter->WriteMetaFile( aNullPt, rMtf.GetPrefSize(), rMtf, SVGWRITER_WRITE_FILL );
-            }   // insert the </g> closing tag related to the Background
+            } // insert the </defs> closing tag related to the slide background
         }
 
         // In case we are dealing with a master page we need to group all its shapes
diff --git a/sd/qa/unit/SVGExportTests.cxx b/sd/qa/unit/SVGExportTests.cxx
index 63883f49c828..8f9476f9d452 100644
--- a/sd/qa/unit/SVGExportTests.cxx
+++ b/sd/qa/unit/SVGExportTests.cxx
@@ -120,7 +120,7 @@ public:
         // There should be only one child (no link to javascript url)
         assertXPathChildren(svgDoc,
                             MAKE_PATH_STRING(/ SVG_SVG / SVG_G[2] / SVG_G / SVG_G / SVG_G / SVG_G
-                                             / SVG_G[4] / SVG_G),
+                                             / SVG_G[3] / SVG_G),
                             1);
     }
 


More information about the Libreoffice-commits mailing list