filter/source/svg/presentation_engine.js | 37 +++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)
New commits: commit bbe4161818e2ec6652ec443a67951b318c9f0e21 Author: Marco Cecchetti <marco.cecche...@collabora.com> AuthorDate: Tue Nov 15 10:56:15 2022 +0100 Commit: Andras Timar <andras.ti...@collabora.com> CommitDate: Tue Nov 22 12:15:24 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> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143050 Tested-by: Jenkins 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 160f5515caf4..c7cef8edd87f 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 ) {