Question

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?

Was it helpful?

Solution

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.

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