Question

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.

Was it helpful?

Solution 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.

OTHER TIPS

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();
}

@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.. :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top