Qt Use Multiple Fonts at the Same Time

2019-04-20 15:22发布

I have three fonts i want to use in my software:

  • FontA: contains Latin, Greek, Cryllic characters
  • FontB: contains Korean characters
  • FontC: contains Japanese, Chinese characters

These fonts have no overlap.

I want to setup my application such that all of these fonts are used at once since characters from different languages may appear in the same context in my software.

If a character is found in FontA, use it. Otherwise, look at FontB, if found use it. Look at FontC as last resort, if found, use it, otherwise do nothing.

How can i setup Qt to function that way?

(My environment is embedded linux, Qt 4.8)

P.S.: I tried QFont::insertSubstitution, but it is used in case FontA is not installed on the system so that doesn't really help in my case.
P.P.S.: Merging these fonts into a single font is out of the question since they are proprietry fonts.

3条回答
ら.Afraid
2楼-- · 2019-04-20 16:02

Like others said – if your QT version uses fontconfig do it through fontconfig, its sole function is to manage smart font substitions. And if your version does not use fontconfig you're out of luck since I doubt anyone invested much time in getting it to work now that fontconfig is widely available.

查看更多
小情绪 Triste *
3楼-- · 2019-04-20 16:02

Try to use this approach: How to (properly) output multilingual text in Qt-Embedded?

It works with lots of languages simultaneously (Cyrillic, European, Thai, Japanese, etc).

  • Put Droid Fonts (not necessary, it should work with other fonts too) into a directory where Qt can find it,
  • Export special environment variable: export QWS_NO_SHARE_FONTS=1
  • Run your application with -fn "Droid Sans" parameter
查看更多
\"骚年 ilove
4楼-- · 2019-04-20 16:04

Qt has a fallback machinsim for such situations. In Qt4 documentation I've found you can customize this fallback mechanism. Looks very promising and should solve your problem.

In Qt5 I don't see direct link to QPlatformFontDatabase class. Only this. It looks like you should write some plugin. Also this page suggest that QPlatformFontDatabase apeared in Qt 5.2 so it should work in Qt5. For some reason there is no documentation about it for Qt5.

You should try it and see or at least take a pick in sources.

查看更多
登录 后发表回答