11

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.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
erelender
  • 6,175
  • 32
  • 49
  • can you combine the fonts at runtime and pass it into [addApplicationFontFromData](http://qt-project.org/doc/qt-5.0/qtgui/qfontdatabase.html#addApplicationFontFromData), this way you don't distribute a combined font (IANAL) – ratchet freak Nov 15 '13 at 13:39
  • Have you checked the fontconfig manual? AFAIK you should be able to configure system-wide (or per user) fallbacks when a certain glyph in a font isn't found. – peppe Nov 15 '13 at 17:53
  • The feature is called "font fallback" in Qt and should work if you use fontconfig. (don't know about configuration details though). There's code in Qt for the non-fontconfig case but that seems currently broken (as of Qt 5.1/5.2) – Frank Osterfeld Nov 15 '13 at 19:12
  • I think you are missing the point. I don't need "font fallback", i need "glyph fallback". Fontconfig supports font fallback but glyph fallback has to be handled at the application level. – erelender Nov 20 '13 at 07:57
  • @ratchetfreak I don't think that would be such a trivial method. I'd have to parse each font file and merge them into a single ttf formatted data, and then pass it to Qt, which is a lot of work in my opinion. – erelender Nov 20 '13 at 07:59
  • Also, fontconfig is not supported on QtEmbedded – erelender Nov 22 '13 at 12:41
  • FontConfig is supported on QtEmbedded: http://doc.qt.io/qt-5/qt-embedded-fonts.html – Silex Oct 04 '16 at 13:45

3 Answers3

1

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.

nim
  • 2,345
  • 14
  • 13
  • Our Qt version does not use fontconfig, and sadly all the suggestions rely on it. Just to be clear, fontconfig can do this on a glyph basis right? Also, can anyone point me to a good example that shows how to do this glyph substitution? I can't find one :( – erelender Nov 19 '13 at 12:11
  • Fontconfig is much smarter than that, it has a database of the codepoints necessary for most common locales, and will auto-substitute a font appropriate for a given locale if the current font is not sufficient to display the requested text. And you can configure font priorities, locale-specific overrides, etc. So not only it will substitute but it will try to avoid switching fonts every two letters (like most naïve substitution engines do). It's quite complete but you do need to read the provided example ruleset to understand how it works. – nim Nov 20 '13 at 08:38
  • I see, the problem is that our current Qt config does not use fontconfig and it will take me a lot of time to get it deployed with fontconfig, so i want to make sure that it can be done before trying it out. Could you point me to an example that does what you mentioned? – erelender Nov 20 '13 at 09:13
1

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
Community
  • 1
  • 1
qehgt
  • 2,972
  • 1
  • 22
  • 36
0

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.

Marek R
  • 32,568
  • 6
  • 55
  • 140