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

Marco Cecchetti (via logerrit) logerrit at kemper.freedesktop.org
Sun Jan 24 15:18:03 UTC 2021


 filter/source/svg/presentation_engine.js |   68 ++++++++++++++++++++-----------
 filter/source/svg/svgexport.cxx          |    7 +++
 filter/source/svg/svgwriter.cxx          |    3 -
 sd/qa/unit/SVGExportTests.cxx            |   32 +++++++++++++-
 sd/qa/unit/data/odp/text-fields.odp      |binary
 5 files changed, 85 insertions(+), 25 deletions(-)

New commits:
commit 944d289f5a1017f86646157314c88b496a0d3a30
Author:     Marco Cecchetti <marco.cecchetti at collabora.com>
AuthorDate: Mon Jan 18 12:36:42 2021 +0100
Commit:     Andras Timar <andras.timar at collabora.com>
CommitDate: Sun Jan 24 15:40:01 2021 +0100

    filter: svg: js engine: text fields support: unit test
    
    Change-Id: I80a7e7906fb2a82d955562a137b208497d4c0d9c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109543
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Marco Cecchetti <marco.cecchetti at collabora.com>

diff --git a/sd/qa/unit/SVGExportTests.cxx b/sd/qa/unit/SVGExportTests.cxx
index 57e5f3fcfc0a..394a591ccbbf 100644
--- a/sd/qa/unit/SVGExportTests.cxx
+++ b/sd/qa/unit/SVGExportTests.cxx
@@ -125,7 +125,7 @@ public:
                             1);
     }
 
-    void testSVGExporSlidetCustomBackground()
+    void testSVGExportSlideCustomBackground()
     {
         executeExport("slide-custom-background.odp");
 
@@ -135,10 +135,38 @@ public:
         assertXPath(svgDoc, MAKE_PATH_STRING( /SVG_SVG/SVG_G[2]/SVG_G/SVG_G/SVG_G/SVG_G/SVG_DEFS ), "class", "SlideBackground");
     }
 
+    void testSVGExportTextFieldsInMasterPage()
+    {
+        executeExport("text-fields.odp");
+
+        xmlDocPtr svgDoc = parseXml(maTempFile);
+        CPPUNIT_ASSERT(svgDoc);
+
+        assertXPath(svgDoc, MAKE_PATH_STRING( /SVG_SVG/SVG_DEFS[9]/SVG_G[2] ), "class", "Master_Slide");
+        assertXPath(svgDoc, MAKE_PATH_STRING( /SVG_SVG/SVG_DEFS[9]/SVG_G[2]/SVG_G[2] ), "class", "BackgroundObjects");
+        // Current Date Field
+        assertXPath(svgDoc, MAKE_PATH_STRING( /SVG_SVG/SVG_DEFS[9]/SVG_G[2]/SVG_G[2]/SVG_G[4] ), "class", "com.sun.star.drawing.TextShape");
+        assertXPath(svgDoc, MAKE_PATH_STRING( /SVG_SVG/SVG_DEFS[9]/SVG_G[2]/SVG_G[2]/SVG_G[4]/SVG_G/SVG_TEXT/SVG_TSPAN/SVG_TSPAN/SVG_TSPAN ), "class", "PlaceholderText");
+        assertXPathContent(svgDoc, MAKE_PATH_STRING( /SVG_SVG/SVG_DEFS[9]/SVG_G[2]/SVG_G[2]/SVG_G[4]/SVG_G/SVG_TEXT/SVG_TSPAN/SVG_TSPAN/SVG_TSPAN ), "<date>");
+        // Current Time Field
+        assertXPath(svgDoc, MAKE_PATH_STRING( /SVG_SVG/SVG_DEFS[9]/SVG_G[2]/SVG_G[2]/SVG_G[5] ), "class", "com.sun.star.drawing.TextShape");
+        assertXPath(svgDoc, MAKE_PATH_STRING( /SVG_SVG/SVG_DEFS[9]/SVG_G[2]/SVG_G[2]/SVG_G[5]/SVG_G/SVG_TEXT/SVG_TSPAN/SVG_TSPAN/SVG_TSPAN ), "class", "PlaceholderText");
+        assertXPathContent(svgDoc, MAKE_PATH_STRING( /SVG_SVG/SVG_DEFS[9]/SVG_G[2]/SVG_G[2]/SVG_G[5]/SVG_G/SVG_TEXT/SVG_TSPAN/SVG_TSPAN/SVG_TSPAN ), "<time>");
+        // Slide Name Field
+        assertXPath(svgDoc, MAKE_PATH_STRING( /SVG_SVG/SVG_DEFS[9]/SVG_G[2]/SVG_G[2]/SVG_G[6] ), "class", "com.sun.star.drawing.TextShape");
+        assertXPath(svgDoc, MAKE_PATH_STRING( /SVG_SVG/SVG_DEFS[9]/SVG_G[2]/SVG_G[2]/SVG_G[6]/SVG_G/SVG_TEXT/SVG_TSPAN/SVG_TSPAN/SVG_TSPAN ), "class", "PlaceholderText");
+        assertXPathContent(svgDoc, MAKE_PATH_STRING( /SVG_SVG/SVG_DEFS[9]/SVG_G[2]/SVG_G[2]/SVG_G[6]/SVG_G/SVG_TEXT/SVG_TSPAN/SVG_TSPAN/SVG_TSPAN ), "<slide-name>");
+        // Slide Number Field
+        assertXPath(svgDoc, MAKE_PATH_STRING( /SVG_SVG/SVG_DEFS[9]/SVG_G[2]/SVG_G[2]/SVG_G[7] ), "class", "com.sun.star.drawing.TextShape");
+        assertXPath(svgDoc, MAKE_PATH_STRING( /SVG_SVG/SVG_DEFS[9]/SVG_G[2]/SVG_G[2]/SVG_G[7]/SVG_G/SVG_TEXT/SVG_TSPAN/SVG_TSPAN/SVG_TSPAN ), "class", "PlaceholderText");
+        assertXPathContent(svgDoc, MAKE_PATH_STRING( /SVG_SVG/SVG_DEFS[9]/SVG_G[2]/SVG_G[2]/SVG_G[7]/SVG_G/SVG_TEXT/SVG_TSPAN/SVG_TSPAN/SVG_TSPAN ), "<number>");
+    }
+
     CPPUNIT_TEST_SUITE(SdSVGFilterTest);
     CPPUNIT_TEST(testSVGExportTextDecorations);
     CPPUNIT_TEST(testSVGExportJavascriptURL);
-    CPPUNIT_TEST(testSVGExporSlidetCustomBackground);
+    CPPUNIT_TEST(testSVGExportSlideCustomBackground);
+    CPPUNIT_TEST(testSVGExportTextFieldsInMasterPage);
     CPPUNIT_TEST_SUITE_END();
 };
 
diff --git a/sd/qa/unit/data/odp/text-fields.odp b/sd/qa/unit/data/odp/text-fields.odp
new file mode 100644
index 000000000000..3c5d057ba2f0
Binary files /dev/null and b/sd/qa/unit/data/odp/text-fields.odp differ
commit aa142a7ec1cf3275f6e65ce93a59e1a9c9277f09
Author:     Marco Cecchetti <marco.cecchetti at collabora.com>
AuthorDate: Sun Jan 17 23:38:57 2021 +0100
Commit:     Andras Timar <andras.timar at collabora.com>
CommitDate: Sun Jan 24 15:39:47 2021 +0100

    filter: svg: js engine: further improving text fields handling
    
    Added support for slide name text field on master page
    
    Change-Id: I969bd3b2d030cf117f4c7022716b55152538f846
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109497
    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 d0d0a0b60db7..f6a42c4c0223 100644
--- a/filter/source/svg/presentation_engine.js
+++ b/filter/source/svg/presentation_engine.js
@@ -4434,6 +4434,7 @@ var aOOOAttrUsePositionedChars = 'use-positioned-chars';
 
 var aOOOAttrSlide = 'slide';
 var aOOOAttrMaster = 'master';
+var aOOOAttrDisplayName = 'display-name';
 var aOOOAttrSlideDuration = 'slide-duration';
 var aOOOAttrHasTransition = 'has-transition';
 var aOOOAttrHasCustomBackground = 'has-custom-background';
@@ -4460,6 +4461,7 @@ var aFooterClassName = 'Footer';
 var aHeaderClassName = 'Header';
 var aDateClassName = 'Date';
 var aTimeClassName = 'Time';
+var aSlideNameClassName='SlideName';
 
 // Creating a namespace dictionary.
 var NSS = {};
@@ -5016,6 +5018,8 @@ function MetaSlide( sMetaSlideId, aMetaDoc )
     else
         this.nSlideNumber= -1;
 
+    this.slideName = this.element.getAttributeNS( NSS['ooo'], aOOOAttrDisplayName );
+
     // Each slide element is double wrapped by <g> elements.
     // The outer <g> element is responsible for
     // the slide element visibility. In fact the visibility attribute has
@@ -5085,6 +5089,7 @@ function MetaSlide( sMetaSlideId, aMetaDoc )
     this.aTextFieldContentProviderSet[aHeaderClassName]        = this.initFixedTextFieldContentProvider( aOOOAttrHeaderField );
     this.aTextFieldContentProviderSet[aDateClassName]          = this.theMetaDoc.aCurrentDateProvider;
     this.aTextFieldContentProviderSet[aTimeClassName]          = this.theMetaDoc.aCurrentTimeProvider;
+    this.aTextFieldContentProviderSet[aSlideNameClassName]     = new FixedTextProvider( this.slideName );
 
     // We init the slide duration when automatic slide transition is enabled
     this.fDuration = this.initSlideDuration();
@@ -5240,7 +5245,7 @@ initDateTimeFieldContentProvider : function( aOOOAttrDateTimeField )
         var sClassName = getClassAttribute( aTextFieldElem );
         if( sClassName == 'FixedDateTimeField' )
         {
-            aTextField = new FixedTextProvider( aTextFieldElem );
+            aTextField = new FixedTextByElementProvider( aTextFieldElem );
             this.bIsDateTimeVariable = false;
         }
         else if( sClassName == 'VariableDateTimeField' )
@@ -5270,7 +5275,7 @@ initFixedTextFieldContentProvider : function( aOOOAttribute )
     {
         var aTextFieldElem = document.getElementById( sTextFieldId );
         this.theMetaDoc.aTextFieldContentProviderSet[ nIndex ]
-            = new FixedTextProvider( aTextFieldElem );
+            = new FixedTextByElementProvider( aTextFieldElem );
     }
     return this.theMetaDoc.aTextFieldContentProviderSet[ nIndex ];
 },
@@ -5364,6 +5369,8 @@ function getTextFieldType ( elem )
                 sFieldType = aDateClassName;
             else if (sContent === '<time>')
                 sFieldType = aTimeClassName;
+            else if (sContent === '<slide-name>')
+                sFieldType = aSlideNameClassName;
         }
     }
     return sFieldType;
@@ -5373,7 +5380,8 @@ function isTextFieldByClassName ( sClassName )
 {
     return sClassName === aDateTimeClassName || sClassName === aFooterClassName
         || sClassName === aHeaderClassName || sClassName.startsWith( aSlideNumberClassName )
-        || sClassName.startsWith( aDateClassName ) || sClassName.startsWith( aTimeClassName );
+        || sClassName.startsWith( aDateClassName ) || sClassName.startsWith( aTimeClassName )
+        || sClassName.startsWith( aSlideNameClassName );
 }
 
 /** Class MasterPage
@@ -5820,13 +5828,9 @@ MasterPageView.prototype.createElement = function()
                                                    aTextFieldHandlerSet, sMasterSlideId );
                 }
             }
-            else if( sId.startsWith( aDateClassName ) )
-            {
-                this.initTextFieldHandler( sId, aPlaceholderShapeSet,
-                                           aTextFieldContentProviderSet, aDefsElement,
-                                           aTextFieldHandlerSet, sMasterSlideId );
-            }
-            else if( sId.startsWith( aTimeClassName ) )
+            else if( sId.startsWith( aDateClassName )
+                || sId.startsWith( aTimeClassName )
+                || sId.startsWith( aSlideNameClassName ) )
             {
                 this.initTextFieldHandler( sId, aPlaceholderShapeSet,
                                            aTextFieldContentProviderSet, aDefsElement,
@@ -6058,25 +6062,32 @@ SlideNumberFieldHandler.prototype.update = function( nPageNumber )
  *      The svg element that contains the text content for one or more
  *      master slide text field.
  */
-function TextFieldContentProvider( aTextFieldContentElement )
+function TextFieldContentProvider()
 {
-    // This id is used as key for the theMetaDoc.aTextFieldHandlerSet object.
-    if( aTextFieldContentElement )
-        this.sId = aTextFieldContentElement.getAttribute( 'id' );
+    this.sId = TextFieldContentProvider.getUniqueId();
 }
 
+/*** private methods ***/
+
+TextFieldContentProvider.CURR_UNIQUE_ID = 0;
+
+TextFieldContentProvider.getUniqueId = function()
+{
+    ++TextFieldContentProvider.CURR_UNIQUE_ID;
+    return TextFieldContentProvider.CURR_UNIQUE_ID;
+};
+
 /** Class FixedTextProvider
  *  This class handles text field with a fixed text.
  *  The text content is provided by the 'text' property.
  *
- *  @param aTextFieldContentElement
- *      The svg element that contains the text content for one or more
- *      master slide text field.
+ *  @param aText
+ *      a string containing the text to be substituted.
  */
-function FixedTextProvider( aTextFieldContentElement )
+function FixedTextProvider( aText )
 {
-    FixedTextProvider.superclass.constructor.call( this, aTextFieldContentElement );
-    this.text = aTextFieldContentElement.textContent;
+    FixedTextProvider.superclass.constructor.call( this );
+    this.text = aText;
 }
 extend( FixedTextProvider, TextFieldContentProvider );
 
@@ -6094,6 +6105,20 @@ FixedTextProvider.prototype.update = function( aFixedTextField )
     aFixedTextField.setTextContent( this.text );
 };
 
+/** Class FixedTextByElementProvider
+ *  This class handles text field with a fixed text.
+ *  The text content is provided by the 'text' property.
+ *
+ *  @param aTextFieldContentElement
+ *      The svg element that contains the text content for one or more
+ *      master slide text field.
+ */
+function FixedTextByElementProvider( aTextFieldContentElement )
+{
+    FixedTextByElementProvider.superclass.constructor.call( this, aTextFieldContentElement.textContent );
+}
+extend( FixedTextByElementProvider, FixedTextProvider );
+
 /** Class CurrentDateTimeProvider
  *  Provide the text content to a date/time field by generating the current
  *  date/time in the format specified by the 'dateTimeFormat' property.
@@ -6110,7 +6135,6 @@ function CurrentDateTimeProvider( aTextFieldContentElement, sDateTimeFormat )
     else
     {
         this.dateTimeFormat = sDateTimeFormat;
-        this.sId = 'DateTimeProvider.' + sDateTimeFormat;
     }
 }
 extend( CurrentDateTimeProvider, TextFieldContentProvider );
@@ -6151,7 +6175,7 @@ CurrentDateTimeProvider.prototype.createDateTimeText = function()
  */
 function SlideNumberProvider( nInitialSlideNumber, sPageNumberingType )
 {
-    SlideNumberProvider.superclass.constructor.call( this, null );
+    SlideNumberProvider.superclass.constructor.call( this );
     this.nInitialSlideNumber = nInitialSlideNumber;
     this.pageNumberingType = sPageNumberingType;
 
diff --git a/filter/source/svg/svgexport.cxx b/filter/source/svg/svgexport.cxx
index 938d833c1275..094dfe2a884d 100644
--- a/filter/source/svg/svgexport.cxx
+++ b/filter/source/svg/svgexport.cxx
@@ -88,6 +88,7 @@ static const char    aOOOElemTextField[] = NSPREFIX "text_field";
 static const char    aOOOAttrSlide[] = NSPREFIX "slide";
 static const char    aOOOAttrMaster[] = NSPREFIX "master";
 static const char    aOOOAttrHasCustomBackground[] = NSPREFIX "has-custom-background";
+static const char    aOOOAttrDisplayName[] = NSPREFIX "display-name";
 static const char    aOOOAttrBackgroundVisibility[] = NSPREFIX "background-visibility";
 static const char    aOOOAttrMasterObjectsVisibility[] = NSPREFIX "master-objects-visibility";
 static const char    aOOOAttrSlideDuration[] = NSPREFIX "slide-duration";
@@ -1151,6 +1152,12 @@ void SVGFilter::implGenerateMetaData()
 
                     if( xPropSet.is() )
                     {
+                        OUString sDisplayName;
+                        if (xPropSet->getPropertyValue("LinkDisplayName") >>= sDisplayName)
+                        {
+                            mpSVGExport->AddAttribute( XML_NAMESPACE_NONE, aOOOAttrDisplayName, sDisplayName);
+                        }
+
                         bool bBackgroundVisibility                = true;     // default: visible
                         bool bBackgroundObjectsVisibility         = true;     // default: visible
 
diff --git a/filter/source/svg/svgwriter.cxx b/filter/source/svg/svgwriter.cxx
index 2e4c00b7fbf8..71f3581b7a15 100644
--- a/filter/source/svg/svgwriter.cxx
+++ b/filter/source/svg/svgwriter.cxx
@@ -1184,7 +1184,8 @@ bool SVGTextWriter::nextTextPortion()
                             }
                         }
                         if( sFieldName == "DateTime" || sFieldName == "Header"
-                                || sFieldName == "Footer" || sFieldName == "PageNumber" )
+                                || sFieldName == "Footer" || sFieldName == "PageNumber"
+                                || sFieldName == "PageName" )
                         {
                             mbIsPlaceholderShape = true;
                         }


More information about the Libreoffice-commits mailing list