[Qt-interest] show QString with Arabic contents

Oliver.Knoll at comit.ch Oliver.Knoll at comit.ch
Thu Jan 15 09:56:52 CET 2009


Iurii Gordiienko wrote on Thursday, January 15, 2009 9:32 AM:

> Hi
> Thank you, but how can I know what my string is Arabic? A can't
> change layout's direction for non-Arabic strings...

Hmm, sorry, jumped right into this thread here, so I don't know from where you get your text. But it is obvious that it is not text which is under control by your application, so I assume you e.g. download this text from some web site and now need to know what kind of text it is (as to set the direction).

This is not so trivial, given the text alone, see for example http://www.robinlionheart.com/stds/html4/dir about "Text Direction" which also references http://www.unicode.org/unicode/reports/tr9/ ("Unicode Bidirectional Algorithm").

Apparently the "direction" is given by the specific alphabet, or in terms of "Unicode speak", the range of Unicode characters. So for example if you hit a text within the "arabic Unicode range", you'd know that you have to render it "right to left".

But then there are "direction neutral characters", e.g. numbers 1, 2, 3, 4, or punctuation, which clearly don't give you a clue. So in a web page, for example, you would make this information explicit with

  <span dir="ltr">The left-to-right text</span> or
  <span dir="rtl">The right-to-left text</span>

Alternatively you would allow your user to explicitly set the direction in your application when editing text, because only she can know what language she's going to type.

Summary: You HAVE to have the knowledge somewhere what kind of language the text you are processing is in, either by trying to "auto-detect" it (heuristically analyse the Unicode range, taking somehow into account the "direction neutral" characters), by explicitly setting it, or extracting it from additional "meta" data, such as the <span dir> given above (if you happen to download a webpage, for example).


Cheers, Oliver
--
Oliver Knoll
Dipl. Informatik-Ing. ETH
COMIT AG - ++41 79 520 95 22




More information about the Qt-interest-old mailing list