summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Cecchetti <marco.cecchetti@collabora.com>2021-01-11 10:28:57 +0100
committerAndras Timar <andras.timar@collabora.com>2021-01-19 15:14:45 +0100
commit92e9de9ab53ae717693c7097c9390d26b9564c1b (patch)
treee1bc3a5d9fbc5024d35738191161a4ba4d23f1bf
parentBump version to 6.2-28 (diff)
downloadcore-92e9de9ab53ae717693c7097c9390d26b9564c1b.tar.gz
core-92e9de9ab53ae717693c7097c9390d26b9564c1b.zip
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@gmail.com> Reviewed-by: Marco Cecchetti <marco.cecchetti@collabora.com>
-rw-r--r--filter/source/svg/presentation_engine.js22
-rw-r--r--filter/source/svg/svgexport.cxx73
-rw-r--r--sd/qa/unit/SVGExportTests.cxx2
3 files changed, 72 insertions, 25 deletions
diff --git a/filter/source/svg/presentation_engine.js b/filter/source/svg/presentation_engine.js
index 150510446324..3d82aac0eaab 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';
@@ -5042,10 +5043,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 );
@@ -5167,6 +5178,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;
@@ -5646,10 +5663,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 ac16f7e754f6..938d833c1275 100644
--- a/filter/source/svg/svgexport.cxx
+++ b/filter/source/svg/svgexport.cxx
@@ -33,6 +33,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>
@@ -85,6 +87,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";
@@ -1155,6 +1158,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'
@@ -1760,35 +1776,48 @@ bool SVGFilter::implExportPage( const OUString & sPageId,
const GDIMetaFile& rMtf = (*mpObjects)[ rxPage ].GetRepresentation();
if( rMtf.GetActionSize() )
{
- // background id = "bg-" + page id
+ // 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 ) );
+ }
+ {
+ // background id = "bg-" + page id
OUString sBackgroundId = "bg-";
sBackgroundId += 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( !mVisiblePagePropSet.bIsBackgroundVisible )
+ 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 400d604e786c..8c55bf45d48b 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);
}