[Interest] i18n - setting language hints when rendering text

Preet prismatic.project at gmail.com
Thu Apr 24 11:25:27 CEST 2014


Hi all,

When rendering text with QtQuick, there doesn't seem to be a way to
provide a language hint. I think this is sort of problematic:

1.
If you have an application with international text from multiple
languages in it you might want to provide a font fallback list
determined by language rather than leaving it up to Qt to choose for
you. For example, CJK specifically has character overlap, but the
characters are stylistically different between languages. So if I had
both a Japanese and Chinese font, and wanted to render some Japanese
text that happened to be composed of characters shared with CJK, it
seems like its possible that Qt would use the Chinese font as a
fallback.

The current workaround is to explicitly specify the font with the
language you want each time you draw some text. But that takes away
your ability to specify the font for any glyphs that exist with the
original (and not fallback) font. Say you had a mixed language label.
You can only do:

Text {
  font.family: "Beesknees"
  text: "blue 海"  // 'blue' gets drawn with your chosen font, but you
cant control '海'
}

Text {
  font.family: "MyJapaneseSpecificFont"
  text: "blue 海" // 'blue gets drawn with whatever latin glyphs are in
MyJ..Font, japanese glyph is rendered correctly"
}

2.
I took a quick look at QTextEngine::shapeTextWithHarfbuzzNG() and
noticed it doesn't provide a language for text shaping:

hb_segment_properties_t props = HB_SEGMENT_PROPERTIES_DEFAULT;
    props.direction = si.analysis.bidiLevel % 2 ? HB_DIRECTION_RTL :
HB_DIRECTION_LTR;
    props.script = hb_qt_script_to_script(QChar::Script(si.analysis.script));
    // ### props.language =
hb_language_get_default_for_script(props.script); // <-- commented
out!

Info on the Harfbuzz mailing lists explains that language affects text
shaping. See the screenshot here for example
https://github.com/arielm/Unicode/tree/master/Projects/LanguageFeatures.

In general detecting language from some input text is not always
possible, but with language hints at least that information can be
passed on to the text shaper. Overall it looks like a very tiny % of
commonly used languages would be affected but I thought it was worth
mentioning.


Preet



More information about the Interest mailing list