×
Namespaces

Variants
Actions
Revision as of 06:34, 14 September 2012 by hamishwillee (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Creating and loading custom fonts in Symbian

From Nokia Developer Wiki
Jump to: navigation, search

This article contains instructions for creating and loading custom fonts in Symbian.

Needs-update.pngThis 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.

  • 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
I think this should clarify the above points and also explain the difference between a custom and system fonts on both platforms

Main steps

Here are the steps for creating a custom fonts for your Symbian 2nd edition & 3rd Edition phones.

  1. 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.
  2. 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.
  3. 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).
  4. 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));
  5. 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);

Version Hint

Windows Phone: [[Category:Windows Phone]]
[[Category:Windows Phone 7.5]]
[[Category:Windows Phone 8]]

Nokia Asha: [[Category:Nokia Asha]]
[[Category:Nokia Asha Platform 1.0]]

Series 40: [[Category:Series 40]]
[[Category:Series 40 1st Edition]] [[Category:Series 40 2nd Edition]]
[[Category:Series 40 3rd Edition (initial release)]] [[Category:Series 40 3rd Edition FP1]] [[Category:Series 40 3rd Edition FP2]]
[[Category:Series 40 5th Edition (initial release)]] [[Category:Series 40 5th Edition FP1]]
[[Category:Series 40 6th Edition (initial release)]] [[Category:Series 40 6th Edition FP1]] [[Category:Series 40 Developer Platform 1.0]] [[Category:Series 40 Developer Platform 1.1]] [[Category:Series 40 Developer Platform 2.0]]

Symbian: [[Category:Symbian]]
[[Category:S60 1st Edition]] [[Category:S60 2nd Edition (initial release)]] [[Category:S60 2nd Edition FP1]] [[Category:S60 2nd Edition FP2]] [[Category:S60 2nd Edition FP3]]
[[Category:S60 3rd Edition (initial release)]] [[Category:S60 3rd Edition FP1]] [[Category:S60 3rd Edition FP2]]
[[Category:S60 5th Edition]]
[[Category:Symbian^3]] [[Category:Symbian Anna]] [[Category:Nokia Belle]]

This page was last modified on 14 September 2012, at 06:34.
132 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×