Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ICU Layout sample renders text differently than Microsoft Notepad and Word

I have a bidirectional text

1002   -ابو ماجد الانصاري

Most editors notepad++, notepad etc. show the text as it is shown here. But when I get this text processed through ICU the number is shifted to the right then spaces and hyphen and then Arabic. ICU's sample application layout.exe also shows the number on the right. I have modified paragraphlayout.cpp and set all possible reordering modes but result is still the same:

See Problem Text here

Can someone help to configure ICU to provide output as other display engines do.

like image 560
MOE Avatar asked Nov 16 '17 10:11

MOE


1 Answers

If I understand correctly, your text 'begins' with the numeric, which is followed by the hyphen and text. Notepad and other editors let you choose the 'writing direction'. If you choose right-to-left, you get the same result as your screenshot,

RTL screenshot

If you want to maintain left-to-right writing direction, you can set it explicitly

ubidi_setPara(para, "1002   -ابو ماجد الانصاري", ‭25, UBIDI_LTR, NULL, pErrorCode);

or you can embed a UNICODE flag U+202A (LEFT-TO-RIGHT EMBEDDING) into your string that will enforce this direction. If your code is in C++, you can write something like

icu::UnicodeString string_to_layout = "\x202a";
string_to_layout += "1002   -ابو ماجد الانصاري";

and not you can use string_to_layout as input parameter for renderParagraph() (see http://icu-project.org/apiref/icu4c-latest/ubidi_8h.htm).

like image 107
Alex Cohn Avatar answered Oct 07 '22 14:10

Alex Cohn