3

My target system is:

  • linux 3.3.7,
  • Qt Embedded (open source edition) 4.8,
  • Droid fonts (taken from fonts-droid_20111207+git-1_all.deb Debian package and copied into /usr/lib/fonts directory),
  • Linux Framebuffer for main Qt GUI application,
  • everything is build by Buildroot package.

My test application is very simple: just one dialog box with a few static QLabel on it (one for Chinese, one for Arabic, one for Cyrillic, etc).

When I run it on my linux desktop, all labels are shown correctly. But when it runs on my target system some text disappears.

After some research, I'd found this difference in the behavior of Qt framework: QFontDatabase class reports that there is only 4 Droid font families on my desktop system:

Droid Sans [unknown]
Droid Sans [monotype]
Droid Sans Mono
Droid Serif

But the same QFontDatabase class reports that there are lots of separated font families on my target system:

Droid Arabic Naskh
Droid Sans
Droid Sans Armenian
Droid Sans Ethiopic
Droid Sans Fallback
Droid Sans Georgian
Droid Sans Hebrew
Droid Sans Japanese
Droid Sans Mono
Droid Sans Thai
Droid Serif

As the result, if I change "default" font family for my application (via -fn command line option or manually via calling setFont() inside my application) some text labels are shown but other are not (for example, when I use "Droid Sans Hebrew" font family, Korean text is missing but Hebrew/Arabic are ok).

So, my questions are: what is proper way to output multilingual text in a Qt Embedded application? Why did the "Droid Sans" family become separated? Is there any way to combine them together?

Thanks.

qehgt
  • 2,972
  • 1
  • 22
  • 36
  • Apparently the question is "why Qt doesn't load all Droid font's", not "what is proper way to output multilingual text in a Qt Embedded application?" Did you execute fc-cache after font installation? – divanov Jan 02 '13 at 16:42
  • @divanov There is no `fc-cache` on the target system. Is it necessary to use `fontconfig` package for such functionality? – qehgt Jan 02 '13 at 17:09
  • According to the documentation Qt finds fonts through fontconfig http://doc-snapshot.qt-project.org/4.8/qfontdatabase.html#addApplicationFont. Another option to try is to load fonts directly from file http://doc-snapshot.qt-project.org/4.8/qfontdatabase.html#addApplicationFontFromData – divanov Jan 02 '13 at 20:29
  • @divanov Thank you for pointing me in the right direction, I hope it's a root of the issue. – qehgt Jan 02 '13 at 21:34
  • @divanov Sorry for this long delay, I had no time to work on this issue. Btw, you were absolute right, the real root of this problem is missing `fontconfig` package in my root file system. After adding it, adding `65-droid-sans-fonts.conf`, and running `fc-cache` all font files from Droid family became united family. Please, reformat your first comment as answer to let me accept it. – qehgt Jan 22 '13 at 01:01
  • I'm trying to do a very similar thing, is your qt compiled with -embedded flag and -fontconfig flag? I thought -fontconfig was not supported on Qt Embedded – erelender Nov 21 '13 at 13:44
  • @erelender, Qt was compiled with `-embedded` and without `-fontconfig`. But this issue is not related to "font config", see my answer below. – qehgt Nov 21 '13 at 15:49
  • I see, i have another question, was all your fonts included in a single ttf file, or multiple files? – erelender Nov 21 '13 at 15:54
  • @erelender, multiple. 9 TTF files. – qehgt Nov 21 '13 at 15:59
  • Could you please send me an e-mail (it's in my profile)? Looks like you can help me solve my agonizing problem :) – erelender Nov 21 '13 at 16:02
  • @erelender, hmmm.... Can't find it. – qehgt Nov 21 '13 at 16:05
  • Sorry, it's ender.erel at icterra.com – erelender Nov 21 '13 at 16:06

3 Answers3

4

I've created a small test application, which loads font from a file and then uses it in GUI.

#include <QtGui>

int main(int argc, char** argv)
{
    QApplication app(argc, argv);

    /* Load font data from file in the same directory as executable */
    QFile fontFile("BaroqueScript.ttf");
    if (!fontFile.open(QIODevice::ReadOnly)) {
        qCritical() << "failed to open font file";
    }
    QByteArray fontData = fontFile.readAll();

    /* Register font to the QFontDatabase */
    if (QFontDatabase::addApplicationFontFromData(fontData) == -1) {
        qCritical() << "failed to add a font";
    }

    /* Create font object and verify font family */
    QFont font("Baroque Script", 10, QFont::Bold);
    QFontInfo fontInfo(font);
    qDebug() << "Expected:" <<  font.family() << "Real:" << fontInfo.family();

    /* Produce GUI which uses loaded font */
    QLabel label("Hello, world");
    label.setFont(font);
    label.show();

    return app.exec();
}
divanov
  • 6,173
  • 3
  • 32
  • 51
  • Try to use text in Thai, Arabic, Chinese at the same time (in different `QLabel`s). You'll see that text output is not handled properly. – qehgt Jan 10 '13 at 17:49
  • BaroqueScript.ttf contains glyphs only for ASCII symbols, so this is kind of expected. But, for example, Droid Sans Fallback font contains 43449 glyphs and has quite a good coverage. Otherwise one should use different fonts for labels with different character sets. – divanov Jan 10 '13 at 20:23
  • That's exactly what I try to avoid. I don't want to analyze text and switch from one font file to another. Also, this solution will not work for mixed text. – qehgt Jan 10 '13 at 23:28
  • Fallback fonts are good, but too ugly. I need to use *font family* to make my application looks good. – qehgt Jan 10 '13 at 23:30
  • 1
    This is not possible to show all charset symbols with a font, which doesn't have glyphs for these symbols. In practice, there is rare need to show multi-language within the same label. If there are multilanguage labels in the app like Wikipedia, for example, has, bool QFontMetrics::inFont(QChar ch) could be used to select proper font from a pool of fonts. – divanov Jan 13 '13 at 14:52
2

Well, looks like the solution is found at last.

There is a bug in Qt Embedded Rendering Engine: for some reasons it uses "QPF2" Font Engine (QFontEngineQPF) for rendering text in "broken" scripts (Hebrew/Arabic/Thai/Korean in my case).

To avoid/fix this issue, just need to run an application with QWS_NO_SHARE_FONTS=1 environment variable (and with -fn "Droid Sans" command line parameter as well).

After that all text in all languages is displayed without any issue.

qehgt
  • 2,972
  • 1
  • 22
  • 36
1

@qehgt can you please give your CJK and arabic font file sizes? I have faced similar issue... the problem is due to limitation on font cache size. I think its approximately 3MB. So Increasing font cache size is one possibility or you got to dynamically load font files based on the language selected. Hope this helps.. :)

  • @srikanth-4m How to change the font cache size? Btw, we found a workaround for this issue: we use Droid ttf fonts _and_ qpf fonts for some languages. – qehgt Jul 22 '13 at 19:42