filter/source/svg/presentation_engine.js | 37 +++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)
New commits: commit 81a3e33aa203e852b9810fb8e9b17c1930269606 Author: Marco Cecchetti <marco.cecche...@collabora.com> AuthorDate: Tue Nov 15 10:56:15 2022 +0100 Commit: Gökay ŞATIR <gokaysa...@collabora.com> CommitDate: Fri Nov 18 09:56:22 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/+/142760 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Ashod Nakashian <a...@collabora.com> diff --git a/filter/source/svg/presentation_engine.js b/filter/source/svg/presentation_engine.js index e08689d4901d..41efc71e899b 100644 --- a/filter/source/svg/presentation_engine.js +++ b/filter/source/svg/presentation_engine.js @@ -5395,6 +5395,29 @@ function getTextFieldType ( elem ) else if (sContent === '<slide-name>') sFieldType = aSlideNameClassName; } + + 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; } @@ -5604,6 +5627,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 ) {