filter/source/svg/presentation_engine.js |   37 +++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

New commits:
commit e87d8bb20267b83ba6ef665aabc70a3e26307fd9
Author:     Marco Cecchetti <marco.cecche...@collabora.com>
AuthorDate: Tue Nov 15 10:56:15 2022 +0100
Commit:     Andras Timar <andras.ti...@collabora.com>
CommitDate: Wed Nov 16 21:45:37 2022 +0100

    svg export filter: when a text field is too small, its content is wrong
    
    When the text field width is too small, the placeholder text spans
    several lines.
    That stopped the js engine to substitute the text field placeholder
    with the right content.
    This is a workaround but it should work in the majority of cases.
    A complete solution needs to support svg text wrapping.
    
    Change-Id: Ide52e08acd35b3764b8abc600e4b467acea0a248
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142794
    Tested-by: Andras Timar <andras.ti...@collabora.com>
    Reviewed-by: Andras Timar <andras.ti...@collabora.com>

diff --git a/filter/source/svg/presentation_engine.js 
b/filter/source/svg/presentation_engine.js
index cf49ba565192..dbfe2ab0f914 100644
--- a/filter/source/svg/presentation_engine.js
+++ b/filter/source/svg/presentation_engine.js
@@ -5401,6 +5401,29 @@ function getTextFieldType ( elem )
             else if (sContent === '<header>')
                 sFieldType = aHeaderClassName;
         }
+
+        if( sFieldType )
+            return sFieldType;
+
+        var aTextPortionElement = getElementByClassName( elem, 'TextPortion' );
+        if( aTextPortionElement )
+        {
+            var sContent = aTextPortionElement.textContent
+            if( sContent.indexOf( '<number>' ) != -1 )
+                sFieldType = aSlideNumberClassName;
+            else if( sContent.indexOf( '<date/time>' ) != -1 )
+                sFieldType = aDateTimeClassName;
+            else if( sContent.indexOf( '<date>' ) != -1 )
+                sFieldType = aDateClassName;
+            else if( sContent.indexOf( '<time>' ) != -1 )
+                sFieldType = aTimeClassName;
+            else if( sContent.indexOf( '<slide-name>' ) != -1 )
+                sFieldType = aSlideNameClassName;
+            else if( sContent.indexOf( '<footer>' ) != -1 )
+                sFieldType = aFooterClassName;
+            else if( sContent.indexOf( '<header>' ) != -1 )
+                sFieldType = aHeaderClassName;
+        }
     }
     return sFieldType;
 }
@@ -5610,6 +5633,20 @@ PlaceholderShape.prototype.init = function()
         var aTextElem = getElementByClassName( aTextFieldElement, 
'SVGTextShape' );
         if( aTextElem )
         {
+            var aTextParagraphSet = getElementsByClassName( aTextElem, 
'TextParagraph' );
+            // When the text field width is too small, the placeholder text 
spans several lines.
+            // We remove all text lines but the first one which is used as a 
placeholder.
+            // This is a workaround but it should work in the majority of 
cases.
+            // A complete solution needs to support svg text wrapping.
+            if( aTextParagraphSet.length > 1 )
+            {
+                var i = aTextParagraphSet.length;
+                while( i > 1 )
+                {
+                    aTextElem.removeChild(aTextParagraphSet[i-1]);
+                    --i;
+                }
+            }
             var aPlaceholderElement = getElementByClassName(aTextElem, 
'PlaceholderText');
             if( aPlaceholderElement )
             {

Reply via email to