It will gives a wrong result when handling Bidi- English characters and punctuation combined in one paragraph with some font properties setting

Hi folks,

I’m trying to write some bidi word doc by using aspose lib in JAVA. It seems that there is some defects when handling Bidi and English charaters mixed situations with font property settings in one paragraph. I attached my source code and the output result. You can see the different in the word doc. Do you have plan to fix this issue? Or is there any other known Bidi-English mixed issue in aspose word?

Edward

Hello

Thanks for your request. It seems you are using an old version of Aspose.Words. The latest version of Aspose.Words is 10.4.0; you can download this version from here:

https://downloads.aspose.com/words/java

Could you please try using the latest version of Aspose.Words and let me know how it goes on your side.

Best regards,

Thanks for these information. I’ll check the our latest Aspose.words version.

Hi Andrey,

I have checked in Aspose.words 10.4, the problem still exist. Could you help figure out the issue and give me a feedback?

Edward
Best & Regards

Hi

Thanks for your request. To insert mixed RTL and LTR text you should insert part of these text in different Run nodes, i.e. RTL text should be inserted with Bidi option enables and LTR with Bidi option disables. In your case The string contains both RTL and LTR text and you insert this string into Run with Bidi option enabled.

Have you tried to split the string into two parts one for RTL and another for LTR text and insert them into different Run nodes? I think, this should help you to resolve the problem.

Best regards,

Alexey,
Thanks for your reply first. I’m not clear which section code in my provided java file you point. Could you give me a sample?

And what’s my concern is why once there is a BoldBi setting for the same content, the result will not the same as we see without BoldBi setting. You can see my code below. Both line 1 and line 2 are RTL. In line 1, I set the the first text to Bold, and in line 2, I keep it as normal. The line 2 result is the expect RTL output.

The code like:

String val1 = "English Chars: "; //$NON-NLS-1$
String val2 = "This is english content";//$NON-NLS-1$

//Line 1
builder.pushFont();
builder.getFont().setBoldBi( true);
builder.getFont().setBidi( true);
builder.getParagraphFormat().setBidi( true);
builder.write(val1);
builder.popFont();

builder.pushFont();
builder.getFont().setBidi( true);
builder.getParagraphFormat().setBidi( true);
builder.write( val2);
builder.popFont();

//Line 2
builder.writeln();
builder.pushFont();
// builder.getFont().setBoldBi( true);
builder.getFont().setBidi( true);
builder.getParagraphFormat().setBidi( true);
builder.write(val1);
builder.popFont();

builder.pushFont();
builder.getFont().setBidi( true);
builder.getParagraphFormat().setBidi( true);
builder.write( val2);
builder.popFont();

Edward

Hi

Thanks for your request. Please see the following code:

DocumentBuilder builder = new DocumentBuilder();
// Signal to Microsoft Word that this run of text contains right-to-left text.
builder.getFont().setBidi(true);
// Specify the font to be used for the right-to-left text.
builder.getFont().setNameBi("Andalus");
// Specify the locale so Microsoft Word recognizes this text as Arabic - Saudi Arabia.
builder.getFont().setLocaleIdBi(1025);
// Insert some Arabic text.
builder.write("مرحبًا");
// now insert english text.
builder.getFont().setBidi(false);
// Specify the locale so Microsoft Word recognizes this text as English - US.
builder.getFont().setLocaleId(1033);
// Insert some English text.
builder.write("Hello World!!");
// and one more time insert arabic text.
builder.getFont().setBidi(true);
builder.getFont().setNameBi("Andalus");
builder.getFont().setLocaleIdBi(1025);
builder.write("مرحبًا");
// Save output.
builder.getDocument().save("C:\\Temp\\out.doc");

As you can see Bidi property is true for RTL text and is false for LTR text.

Best regards,

Alexey,

Thanks for you sample code to explain the english and arabic mixed situation.

But my concern is in my previous test code. Why if I set the english chars to bold in Line 1, the output result is not the same as the english chars not set to bold in Line 2. Although all of the chars are English, I also hope the result will RTL direction. The Line 1 and Line 2 use the same approach, but the direction is not same. I’m not sure where is my mistake in below code.

String val1 = "English Chars: "; //$NON-NLS-1$
String val2 = "This is english content";//$NON-NLS-1$

//Line 1
builder.pushFont();
//Set the val1 font to Bold
builder.getFont().setBoldBi( true);
builder.getFont().setBidi( true);
builder.getParagraphFormat().setBidi( true);
builder.write(val1);
builder.popFont();

builder.pushFont();
builder.getFont().setBidi( true);
builder.getParagraphFormat().setBidi( true);
builder.write( val2);
builder.popFont();

//Line 2
builder.writeln();
builder.pushFont();
// builder.getFont().setBoldBi( true);
builder.getFont().setBidi( true);
builder.getParagraphFormat().setBidi( true);
builder.write(val1);
builder.popFont();

builder.pushFont();
builder.getFont().setBidi( true);
builder.getParagraphFormat().setBidi( true);
builder.write( val2);
builder.popFont();

Edward

Hi

Thanks for your request. But it is not quite clear for me how the expected output should look. Could you please create the expected output in MS Word and attach it here? I will compare it with the output document produced by Aspose.Words and provide you more information.

Best regards,

Alexery,

I have attached the java file and output result in my first message. You can find the difference in the attached word output.

Edward.

Hi Edward,

Thank you for additional information. I saw the document you have attached in your first post. But what I asked for is the expected output. You can correct the output produced by Aspose.Words in MS Word and attached it here. In this case, I will see what problem you mean.

Best regards,

Alexey,
The output is attached. The first line is wrong. The last line is correct.

Edward.

Hi

Thank you for additional information. The only difference I see is that in the “wrong line” English text is bold. Is this the problem? If so, simply do not set Bold property when insert the value.

Best regards,

Alexey,

Thanks for your comments. But I also want to know, why the result is not same when the font is set to bold. By my understanding, The font setting(bold for the English text) should not affect the direction. So I think this should be a defect. And indeed some times, we need to define font settings for some part of text.

Edward

Hi Edward,

Thank you for additional information. If you need to define different formatting for parts of text, these parts should be in separate Run nodes, as I already mentioned above. i.e. you insert some text using Write method, then change formatting and insert other portion of text. The same applies for inserting RTL and LRT text as well for inserting text with different formatting.

Best regards,

Alexy,

Thanks. Could you give me a simple sample code in separate Run nodes in RTL direction like my code?

Edward

Hi Edward,

Thanks for your request. You can find the code examples in the documentation:
https://reference.aspose.com/words/java/com.aspose.words/documentbuilder#pushFont()

Once you change some font formatting options, DocumentBuilder starts a new Run. You can open your output document using DocumentExplorer (Aspose.Words demo application) to explore an internal document structure.

Best regards,