Fonts in Lighthouse

Published Thursday September 2nd, 2010
7 Comments on Fonts in Lighthouse
Posted in Lighthouse

The font system in Lighthouse was more or less a straight copy from QWS. From time to time I use the browser example test Lighthouse, but I was pretty annoyed that Lighthouse didn’t pick up the fonts on my system, but used the fonts that was shipped with Qt. Also one thing that has been in the back of my head when thinking about fonts and Lighthouse is that QtGui was linking against (or including) FreeType. This is something we don’t want if we are going to port Lighthouse to some other platform with some other glyph rasterizer.

So last week I put something together:
QPlatformIntegration has a new accessor:
QPlatformFontDatabase *QPlatformIntegration::fontDatabase() const;

QPlatformFontDatabase has relatively small interface:

virtual void populateFontDatabase();
virtual QFontEngine *fontEngine(const QFontDef &fontDef, QUnicodeTables::Script script, void *handle);
virtual QStringList fallbacksForFamily(const QString family, const QFont::Style &style, const QUnicodeTables::Script &script) const;
virtual void addApplicationFont(const QByteArray &fontData, const QString &fileName);
virtual void releaseHandle(void *handle);

QPlatformIntegration is suppose to return one QPlatformFontDatabase, and its this class which is responsible to populate an internal db with font families.

I ended up pushing the creation of fontengines to the plugin as well. This way the fontengines don’t need to be part of QtGui, but can be pushed to the plugins.

Its a bit much to expect everyone who wants to write a Lighthouse plugin to write a QPlatformFontDatabase from scratch, so todays functionality++ is implemented and put inside the platforms plugins src directory:

When I made the patch Paul had one big objection: There is no default implementation. Do we need to have some include magic in the pro file, and have non cross platform code in the minimal plugin?

ARGH…. I thought. There is no way to have completely cross platform way of doing this…

Default implementation
However, there is. A few years ago Simon and Paul made a pre-rendered font format they ended up calling qpf2 (wild guess is that it stands for QtPre-renderedFont2). That font-engine was tightly coupled with Linux, but that was because of some ultra-fancy cross process glyph caching which QWS used. By just using the cross platform code the default implementation of QPlatformFontDatabase will pick up all qpf2 files in the prefix/lib/fonts dir and use them when rendering text. Sizes will be completely wrong, but hey a letter in the wrong size is much much better than an empty box?

Unix FontDatabases
I have no interest in xlfd so I have ignored these fonts. However using fontconfig to pickup fonts which I can rasterize with freetype is interesting. There are no X dependencies so it will work with the LinuxFb plugin or the DirectFb plugin. I ended up making 2 fontdatabases. QBasicUnixFontDatabase which is simmilar to what QWS did, and QFontconfigDatabase. However, choosing is a bit crap I think. So I made a QGenericUnixFontDatabase as well. It takes checks the Qt configuration and does the right thing based on that.

I decided that using these implementations needed to be as easy as possible, so all that is needed is to include the pri file and instansiate the fontdatabase in the platform integration. I have changed all the plugins in the repository to use QGenericUnixFontDatabase, so have a look in ie. directfb to see how to do this for your plugin.

Do you like this? Share it
Share on LinkedInGoogle+Share on FacebookTweet about this on Twitter

Posted in Lighthouse


QBasicUnixFontDatabase. It’s funny to see QBasic and Unix in the same identifier. 😉

michel_p says:

could someone give me a ref for an introduction to QWS? thanks a lot

Mikael Lindgren says:

Will Qt work without a font database?

Kacper says:


Sorry, this is off topic.
Does anyone know who the owner of the:

I can’t find it anywhere (folder/folder1) : (
These examples folder/folder1 are not present in the Gitorious.

Thanks and sorry for going off topic!

Jørgen Lind says:

@Mikael Lindgren: Depends on what you mean with font database. But if you don’t register any fonts then Qt does not know of any fonts and will end up drawing empty boxes

andyc says:

It’s a pity I can’t easily shut this change off. I have a platform plugin I’ve been developing for embedded Linux boxes. But to test the platform plugin, I have a little window viewer code that I run on my development machines (Mac/Windows/Linux). Which means that I like to compile QtLighthouse on Mac/Windows/Linux. Which unfortunately means that I now have just the lone default qpf2 font on Mac/Windows. So I’ve got a choice; take out this patch or implement font support for QtLighthouse for my development machines.

Jørgen Lind says:

@andyc: I’m a bit confused. The old fontdatabase was a the old Qt/Embedded fontdatabase, which to my knowledge was a pure linux font database. The BasicUnixFontdatabase is more or less the same code, so if the old fontdatabase worked for you, so should the BasicUnixFontdatabase. Also, this code makes it MUCH MUCH easier to port Lighthouse to new platforms like OS X and Windows. I hange out at qt-lighthouse on freenode so please drop by for a chat if you want 🙂

Commenting closed.

Get started today with Qt Download now