PasteHtml missing alignement when it is left

Report a bug:

If a document has justify/left/center text alignment, when using the plugin PasteHtml , it ignores the html alignement if it is left.

For instance, I create a document using DocBuilder:

var oDocument = Api.GetDocument();
var oParaPr = oDocument.GetDefaultParaPr();
oParaPr.SetJc("both");

From the plugin API,

window.Asc.plugin.executeMethod(
			"PasteHtml",
			['<p style="text-align: left;">text</p>'],
			function(){}
		);

The inserted text is justify instead of left.

The problem comes from the file sdkjs/common/wordcopypaste.js where the function _applyTextAlign assumes that the default alignment of the document is left.
To fix it, I modified the function to:

var _applyTextAlign = function () {
			let text_align;
			if (node.style && node.align && !node.style.textAlign) {
				//some editors(LO) put old attr -> align, and skip text-align
				text_align = node.align;
			} else {
				text_align = t._getStyle(node, computedStyle, "text-align");
			}
			if (text_align) {
				//Может приходить -webkit-right
				let Jc = null;
				if (-1 !== text_align.indexOf('left')) { /* Avoid assumption of left aligment */
					Jc = align_Left;
				}else if (-1 !== text_align.indexOf('center')) {
					Jc = align_Center;
				} else if (-1 !== text_align.indexOf('right')) {
					Jc = align_Right;
				} else if (-1 !== text_align.indexOf('justify')) {
					Jc = align_Justify;
				}
				if (null != Jc) {
					Para.Set_Align(Jc, false);
				}
			}
		};

Best,

Document Server version: 7.4 / 7.5

hey @humbol

Thank you for the information :hugs:
We are checking the situation.
I will let you know when I get something.

Great thanks.

Actually I found a new problem that is related to it.
In this case is for the FontFamily.
For instance:

window.Asc.plugin.callCommand(
	function(){
		var oDocument = Api.GetDocument();
		var oNormalStyle = oDocument.GetDefaultStyle("paragraph");
		var oTextPr = oNormalStyle.GetTextPr();
		oTextPr.SetFontFamily("Times New Roman");
		oTextPr.SetBold(true);
		oTextPr.SetFontSize(48);
	}
	false,
	true,
	function(){
		var htmlContent = "<p>Test</p>";
		window.Asc.plugin.executeMethod(
			"PasteHtml",
			[htmlContent],
			function(){
				callback();
			}
		);
	}
);

It insert the paragraph “Test” where the bold and the size are respected from the default style but it is not the case for the fontFamily.

The problem come from the function Api.prototype["pluginMethod_PasteHtml"] where the element pmpastehtml is created to do the copy.
However, when create the element, some styles from the document are assigned (FontSize, Bold, Italic, etc) but not the FontFamily.

I just added the following to make it work:

if (undefined !== textPr.TextPr.FontFamily.Name)
     _elem.style.fontFamily = textPr.TextPr.FontFamily.Name;

Thanks,

1 Like

Hello @humbol :wave:

I apologize for the delayed response.

We have reproduced the issues you mentioned and will notify you as soon as the fixes are implemented:

  • The text inserted using the executeMethod("PasteHtml") does not inherit the Normal FontFamily style.

  • The executeMethod("PasteHtml") sets a global ParaPr instead of text-align: left.