Free Support Forum - aspose.com

Hebrew&english text and BIDI settings

Hi support,

I’ve looked over the forum and noticed similar issues regarding Hebrew and English text on same line, but couldn’t resume them all into an straight answer. So here it is :

I have both Hebrew and English text within same line. I want all text to be right to left aligned, so I’ve set :
docBuilder.getParagraphFormat().setBidi(true);

For having the text arranged properly, I’ve set :
docBuilder.getFont().setBidi(true);

And here are the minuses :
1. Either the cursor is within English or Hebrew text, I have “Arabic” information regarding the current Language.
2. If I set the docBuilder.getParagraphFormat().setBidi(true), the icon that specifies the right alignment is highlighted. Shouldn’t be the left alignment icon set in here ? If not, what is the difference between calling this method and calling the paragraph alignment method with the right alignment parameter ?
3. If I set docBuilder.getFont().setLocaleIdBi(1037) and comment docBuilder.getParagraphFormat().setBidi(true), pressing the right keyboard arrow in the output document moves the cursor to left, which is correct. But if I delete the comment of the docBuilder.getParagraphFormat().setBidi(true) method, it moves to right, and this is not correct. It would be correct to have the reversed cursor movement behavior only when it is situated in the Hebrew text, and when the cursor is within English text, to have the movement straight.
Can you please give a feedback regarding the enumerated issues ?

Regards,
Milan

Hi support,

Please provide your point regarding my observations.

Thank you,
Milan

Hi Milan,

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request and sorry for dallied response.

1. This might occur because you missed to specify LocaleId for English text. For example take a look at 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.

// For the list of locale identifiers see http://www.microsoft.com/globaldev/reference/lcid-all.mspx

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");

2. When you specify ParagraphFormat.bidi property, you also specify direction of the paragraph. Please see the attached screenshot.

3. I managed to reproduce this problem on my side. Your request has been linked to the appropriate issue. You will be notified as soon as it is resolved.

As a workaround, you can specify only ParagraphFormat.Bidi, but do not specify Font.Bidi:

DocumentBuilder builder = new DocumentBuilder();

// Signal to Microsoft Word that this paragraph contains right-to-left text.

builder.getParagraphFormat().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.

// For the list of locale identifiers see http://www.microsoft.com/globaldev/reference/lcid-all.mspx

builder.getFont().setLocaleIdBi(1025);

// Insert some Arabic text.

builder.write("مرحبًا");

// Save output.

builder.getDocument().save("C:\\Temp\\out.doc");

Best regards.

Hi Alexey,

For the point 3 :
The Language tooltip shows English, not Arabic, like it should.

Milan

Hi Milan,

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional information. I also observed this behavior, this occurs because Font.Bidi is not set. But at least direction of the text is correct. We will let you know once the original issue is resolved.

Best regards.

More, if I add an English text, the cursor movement is still reversed. I run the code below (I’ve removed the Arabic characters because they are not directly supported in my test environment) :

DocumentBuilder builder = new DocumentBuilder();
// Signal to Microsoft Word that this paragraph contains right-to-left text.
builder.getParagraphFormat().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.
// For the list of locale identifiers see http://www.microsoft.com/globaldev/reference/lcid-all.mspx
builder.getFont().setLocaleIdBi(1025);
// Insert some Arabic text.
builder.write("text one ");

// Specify the locale so Microsoft Word recognizes this text as English
builder.getFont().setLocaleIdBi(1033);
// Insert some Arabic text.
builder.write(“TEXT TWO”);

// Save output.
builder.getDocument().save(“C:\Temp\out.doc”);

Regards,
Milan

Hi Milan,

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional information. I added this information into the defect description. We will keep it in mind when we work on the issue.

Best regards.