[Fontconfig] How to block glyph fallback in a QT application?

Raimund Steger rs at mytum.de
Sun Jan 19 08:35:54 PST 2014


Hi,

in case this is still of some concern to you, I have now had the 
opportunity to try this with Qt 5.2.0:

Janusz S. Bien wrote:
> Quote/Cytat - "Janusz S. Bien" <jsbien at mimuw.edu.pl> (Mon 06 Jan 2014
> 04:58:44 PM CET):
>
>>> Gucharmap has an option to turn off fallback, and so does Pango, but for
>>> a Qt application you will need a Qt solution.
>
> For archive, I've found
>
> http://harmattan-dev.nokia.com/docs/platform-api-reference/xml/daily-docs/libqt4/qfont.html
>
>
> "QFont::NoFontMerging    0x8000    If the font selected for a certain
> writing system does not contain a character requested to draw, then Qt
> automatically chooses a similar looking font that contains the
> character. The NoFontMerging flag disables this feature. Please note
> that enabling this flag will not prevent Qt from automatically picking a
> suitable font when the selected font does not support the writing system
> of the text."
>
> and
>
> https://bugreports.qt-project.org/browse/QTBUG-9816
>
> "Add style strategy to QFont to turn off automatic font resolution
> completely
>
> The QFont::NoFontMerging flag turns off font merging within a single
> script item, but still allows automatically picking different fonts for
> each script item if the currently selected font does not support the
> script in question."
>
> I would appreciate very much your comments to the quoted passages: what
> is the meaning of "script" or "writing system" in this context? How the

If I understand [1] correctly, Qt splits every piece of text according 
to its QFontDatabase::WritingSystem [2] value. This behavior cannot be 
changed with QFont::NoFontMerging. Only the behavior later in the 
rendering chain (if the selected font misses a glyph despite it being in 
the correct "writing system") can be changed.

However, what I've found is that I cannot even reproduce the example in 
[1], i. e. QTBUG-1732, although its follow-up bug (QTBUG-9816) is still 
marked as "unresolved".

When I try this code:

     QFont fn("DejaVu Sans");
     fn.setStyleStrategy(QFont::NoFontMerging);
     QChar testChar(0x3042);
     QString str;
     str += testChar;
     ui.label->setFont(fn);
     ui.label->setText(str);

...Qt shows an empty box instead of \u3042 despite the character very 
likely not being in any writing system supported by DejaVu Sans.

Only if I remove the call to setStyleStrategy from the code above, Qt 
performs glyph fallback and renders the character with a fallback font.

Maybe something got changed in the implementation inbetween -- after all 
there's this other bug that Akira dug up a couple of weeks ago which 
suggested that the merging behavior was broken for some time in Qt 4.8 
[3]? Or it's a platform issue, and Qt behaves differently for 
fontconfig-based platforms...

Anyway. Qt's "charactermap" example (in 
qtbase/examples/widgets/widgets/charactermap/) seems to use 
QFont::NoFontMerging too.

So I suppose that could work in the end.

-Raimund


[1] 
https://bugreports.qt-project.org/browse/QTBUG-1732?focusedCommentId=113192&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-113192

[2] http://qt-project.org/doc/qt-5/qfontdatabase.html#WritingSystem-enum

[3] https://bugreports.qt-project.org/browse/QTBUG-32470


-- 
Worringer Str 31 Duesseldorf 40211 DE  home: <rs at mytum.de>
+49-179-2981632 icq 16845346           work: <rs at interface-ag.de>


More information about the Fontconfig mailing list