Creating and loading custom fonts in Symbian
This article contains instructions for creating and loading custom fonts in Symbian.
This article needs to be updated: If you found this article useful, please fix the problems below then delete the {{ArticleNeedsUpdate}} template from the article to remove this warning.
Reasons: hamishwillee (25 Jan 2012)
The article is slightly confusing and out of date.
Reasons: hamishwillee (25 Jan 2012)
The article is slightly confusing and out of date.
- its not clear what the differences are between 2nd and 3rd edition - perhaps the first section is for 2nd edition ... who knows!
- This creates and uses gdr files. Symbian can use open font files from v9 - ie monotype or ttf depending on plugin support and you'd author those in their own native tools
- the second example (3rd edition) looks like it is loading a system font - how is this a custom font?
- the second example should explain what it is trying to do with the custom font
Article Metadata
Main steps
Here are the steps for creating a custom fonts for your Symbian 2nd edition & 3rd Edition phones.
- First get/download the .ttf file of the font which you want to use in your mobile.You can also use the .ttf files of your Windows operation system go to Control Panel > Fonts or C:\WINDOWS\Fonts and select the .ttf file of the font.
- Get a copy of Easy GDR creator from www.symbian-freak.com, which is a freeware application used for converting a .ttf to a .gdr.
- After creating the .gdr file, you can place the .gdr file at any location in your mobile (say for example c:\system\myfolder\abc.gdr).
- Load the font file with the Draw() function.
CGraphicsDevice* iDevice = iCoeEnv->ScreenDevice();
TFileName iFileName;
iFileName.Copy(_L("c:\\system\\myfolder\\abc.gdr"));
CWsScreenDevice* iScrDevice =iCoeEnv->ScreenDevice();
TInt aid =10001;//use any value
iScrDevice->AddFile(iFileName,aid);
TFontSpec myFontSpec;
iDevice->GetNearestFontInTwips(myFont,myFontSpec);
gc.UseFont(myFont);
gc.SetPenColor(KRgbBlack);
gc.DrawText(_L("hello"),TPoint(5,20));
- Unload the font file.
-
iScrDevice->ReleaseFont(myFont);
iScrDevice->RemoveFile(aid);
-
Custom fonts for Symbian 3rd editon
#include <aknutils.h>
LIBRARY gdi.lib
LIBRARY fbscli.lib
CFont* iFont;
TInt iFontUid;
CEikonEnv::Static()->ScreenDevice()->AddFile(_L("c:\\system\\fonts\\GARABD.gdr"),
iFontUid);
const CFont* logical_font =
AknLayoutUtils::FontFromId(EAknLogicalFontSecondaryFont);
//Using those two lines will loose everything but the height from the system font
//So you would end up with no anti-alias on your custom font for instance
//TFontSpec font_spec = logical_font->FontSpecInTwips();
//TFontSpec myFontSpec(_L("Garamond"),font_spec.iHeight);
//Only customize the typeface, keep things like anti-alias settings for instance
TFontSpec myFontSpec = logical_font->FontSpecInTwips();
myFontSpec.iTypeface.iName=_L("Garamond");
CEikonEnv::Static()->ScreenDevice()->GetNearestFontToDesignHeightInTwips(iFont,
myFontSpec);
- Unloading the font
-
CEikonEnv::Static()->ScreenDevice()->ReleaseFont(iFont);
CEikonEnv::Static()->ScreenDevice()->RemoveFile(iFontUid);
-


08 Sep
2009
Using custom fonts is most frequent requirement of GUI applications. Basically device supports system fonts and logical fonts, which may not fulfill requiremnt of end user. For example by default device does not support font "Monotype Corsiva", in that case user need to use custom fonts. In symbian custom fonts can be created in two ways, either using .gdr file or using .ttf file.
This article demonstrates how to create custom fonts using .gdr files. Step by step explanation of source code simplifies understanding, a beginners quickly understand how it works. This source code can be easily extended to create fonts using .ttf files. Rendering fonts of custom language, for example arabic script or indic script, is also possible using this code example.