Using custom fonts in Symbian (/Qt)

Current releases of Qt contain a gap in the Symbian port, which makes it impossible to use custom font files (unless they’re deployed to \resources\fonts). The gap will be filled in Qt 4.7.2 version, but while waiting the following snippet should be useful. Once 4.7.2 is out for Symbian you should just use QFontDatabase.

Now a few words about deploying font files on Symbian which will be relevant on Qt 4.7.2 and onwards. Don’t deploy them to \resources\fonts. Deploying them there causes the OS to load them during boot and keep the font files locked. This will make uninstalling of your application fail unless you make a small executable that will be executed in the beginning of the uninstall process which unloads the fonts you deployed. Nice, huh? A good place to deploy your fonts might be \resources\<your app UID>\fonts. Don’t deploy to your applications private directory as the Symbian Font and Bitmap Server process doesn’t have enough capabilities to access the private directories.

The usage should be pretty simple (see the comments in the snippet). I lumped all the code to the header file as inline implementations for convenience. And don’t forget to add that line mentioned in the comments to your application’s .pro file so that you’ll link against the required Symbian libraries.

This entry was posted in Programming and tagged , , . Bookmark the permalink.

9 Responses to Using custom fonts in Symbian (/Qt)

  1. Ekrem says:

    Hello,
    Thanks for the post sir, I am having this problem and this should help me.
    After I tried this code with Qt 4.7.1 with S60 5th sdk v1.0 I can compile and install application but it always cause my application crash on that load line in main function, I have tried to copy and load both gdr and ttf file in my phone memory resources\APPID\ folder. Not sure what is causing the problem, I am using N97 device.

    • elpuri says:

      That’s odd. Did you try the Lato font from Google font directory? Just to rule out that there’s some problem in the font. I don’t have any 5th ed devices nearby (works on S^3), but I’ll take a look when I can find one.

  2. Vesa says:

    Hi,
    Can you share more details how I do this: “This will make uninstalling of your application fail unless you make a small executable that will be executed in the beginning of the uninstall process which unloads the fonts you deployed.”
    I just did the thing I was not supposed to do… :( I.e. put the fonts in c:\resource\fonts… Not able to uninstall the app or to remove the font file.

    • elpuri says:

      Actually now that I looked CTypefaceStore more closely I don’t know if there’s a way to forcefully ‘release’ the font. I don’t know who has the handle to it (I guess FBS). But if you figure out a way make an exe that does it and then place the exe in a sis file with FILERUN attribute (http://bit.ly/fACjkL). BTW what a nice feature for malware makers this is :) I think the easiest way for you is just to back up your device and do the *#7370# ritual (formats the device’s c: drive and initializes it with factory data).

  3. Deluded says:

    Many thanks for the code – I’ve tried loads of things to get Qt Symbian to load fonts, and your’s is the first solution that works.

    One problem though is that most fonts display incorrectly. Lato works fine, but most of the others from Google and other places don’t.

    It seems like Symbian assumes a certain character order in the font, so displays the wrong characters.. Windows 7 does a similar thing when generating a thumbnail for the font – some have ABG, others have mathematical symbols instead.

    Any idea how to fix this? Or reorder the symbols inside the ttf font to the expected order?

    • kmori says:

      In case your app is QML, try FontLoader. I had the same issue with several ttf with the code above. Later, I tried QML FontLoader and it worked just fine. No wrong mapping of glyphs. I’m using Qt 4.7.3 on N8.

      • Juha Turunen says:

        Yes FontLoader works now that Qt has a proper font loading support on Symbian (which wasn’t the case in 4.7.0) and this hack isn’t necessary anymore.

  4. Roseanne says:

    I see you share interesting content here, you can earn some extra cash, your blog has big potential,
    for the monetizing method, just type in google – K2
    advices how to monetize a website

  5. Pat says:

    You share interesting things here. I think that your website can go viral easily, but you must give it initial boost and i know
    how to do it, just search in google for – wcnu traffic increase

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>