7

I have a Qt-embedded application that I develop in OpenSuse 11.4 where I need to load a TTF font file. However when I call int QFontDatabase::addApplicationFont() function, it's returning -1.

Upon reading the documentation, I found out that adding application fonts on Unix/X11 platforms without fontconfig is currently not supported.

I checked through YaST whether I have fontconfig installed, and it is installed - but I don't think it's related coz I'm using a qt-embedded library. I'm thinking I gotta have fontconfig support qt-embedded library, but how do I do that?

Does fontconfig even support qt-embedded? Can anybody tell me what's going on?

tro
  • 6,152
  • 5
  • 42
  • 63
Owen
  • 3,793
  • 15
  • 53
  • 75
  • 1
    Can you confirm with "fc-list" command that your font is actually listed by fontconfig. – O.C. Aug 16 '11 at 12:14
  • what if it isn't in the list? what's the next step? :) – Owen Aug 17 '11 at 02:47
  • 1
    find a suitable font in the list, or install the font from yast. you can even add font paths to the running X and reload it using xrdb. so man xset and man xrdb will tell yu the details. – Peter Varga Aug 17 '11 at 04:17
  • by the way, I'm building this app using a 4.5.3 qt-embedded library. And not the QT that came pre-installed in OpenSuse. – Owen Aug 17 '11 at 05:33
  • If it is not in the list then qt can not load it ! It is explicitly documented that QT uses fontconfig database to load fonts. I don't think using qt-embedded makes any difference. – O.C. Aug 17 '11 at 06:01
  • Does fontconfig support qt-embedded? – Owen Aug 17 '11 at 07:04

1 Answers1

5

You can use QPA or Qt Platform Abstraction (formerly known as Lighthouse). You need to create an implementation (could be made as a plugin or just being used directly) of QPlatformIntegration which exposes a custom QPlatformFontDatabase. The trick here is to reuse much of Qt's existing implementation of QFontconfigDatabase (which is just as subclass of QBasicUnixFontDatabase).

This is exactly the technique we use for PhantomJS so that it works headlessly (without X11) on Linux while still leveraging Fontconfig (and thus also FreeType) for text rendering.

Unfortunately I think Qt 4.5 is too old to run Lighthouse. Either move to 4.8 which officialy supports QPA or try to backport Lighthouse.

Ariya Hidayat
  • 12,391
  • 3
  • 44
  • 39