Qt's Text Engine
Qt 3 comes with a completely redesigned text processing and layout
engine that is used throughout the whole library.
It has support for most writing systems that are used throughout the
world, including
- Arabic
- Chinese
- Cyrillic (Russian)
- Greek
- Hebrew
- Japanese
- Korean
- Latin languages (e.g. English and many other European languages)
- Thai
- Vietnamese
Many of these writing systems exhibit special features:
- Special line breaking behaviour. Some of the Asian languages are
written without spaces between words. Line breaking can occur either
after every character (with exceptions) as in Chinese, Japanese and
Korean, or after logical word boundaries as in Thai.
- Bidirectional writing. Arabic and Hebrew are written from right to
left, except for numbers and embedded English text which is written
left to right. The exact behaviour is defined in the Unicode Technical Report
#9.
- Non spacing or diacritical marks (accents or umlauts in European
languages). Some languages such as Vietnamese make extensive use of
these marks and some characters can have a few marks at the same time
to clarify pronunciation.
- Ligatures. In special contexts, some characters following each
other directly get replaced by a combined glyph forming a
ligature. Common examples are the ff and fi ligatures used in
typesetting US and European books.
Except for ligatures which are currently only supported for the special
case of Arabic, Qt tries to take care of all the special features
listed above. You will usually never have to worry about these
features as long as you use Qt's input (e.g. QLineEdit, QTextView
or derived classes) and displaying controls (e.g. QLabel).
Support for these writing systems is transparent to the programmer
and completely encapsulated in Qt's text engine. This implies that
you don't need to have any knowledge about the writing system used in
a particular language, except for a couple of small things listed below.
- QPainter::drawText( int x, int y, const QString &str ) will always
draw the string with it's left edge at the position specified with
the x, y parameters. This will usually give you left aligned strings.
Arabic and Hebrew application strings are usually right
aligned, so for these languages use the version of drawText() that
takes a QRect since this will align in accordance with the language.
- When you write your own text input controls, use QFontMetrics::charWidth() to determine the width of a character in a
string. In some langauges (mainly Arabic), the width and shape of a
glyph changes depending on the surrounding characters. Writing input
controls usually requires a certain knowledge of the scripts it is
going to be used in. Usually the easiest way is to subclass QLineEdit
or QTextView.