×
Namespaces

Variants
Actions

Archived:Using application-specific custom fonts in Symbian C++

From Nokia Developer Wiki
Jump to: navigation, search

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

Article Metadata
Code Example
Source file: Media:EditorEx.zip
Tested with
Devices(s): All (S60)
Compatibility
Platform(s): S60 3rd Edition
S60 3rd Edition, FP1
S60 3rd Edition, FP2
S60 5th Edition
Symbian^3
Symbian^3
S60 5th Edition
S60 3rd Edition FP2
S60 3rd Edition FP1
S60 3rd Edition (initial release)
Article
Keywords: CFbsTypefaceStore
Created: User:Technical writer 1 (05 Dec 2008)
Last edited: hamishwillee (19 Sep 2012)

Description

Custom fonts can be added with CFbsTypefaceStore or through the screen device (CWsScreenDevice) instance provided by the application framework control environment. The installation path for the font files must be selected carefully if the fonts are not meant to be shared.

Solution

Application-specific fonts (such as TTF or GDR files) can be installed to the screen device typeface store as follows:

CFont* font;
TInt fontFileID;
_LIT( fontFullName, "C:\\system\\fonts\\VodafoneRg.ttf"); // Default font path has been set.
CWsScreenDevice* device = CEikonEnv::Static()->ScreenDevice();
CFbsTypefaceStore* fontStore = CFbsTypefaceStore::NewL( device );
TInt error = fontStore->AddFile( fontFullName, fontFileID);
_LIT(KFontName, "Vodafone Rg"); //Proper font name needs to be passed
const TInt KFontSize = 1000; // Height of the typeface in twips
TFontSpec fontSpec(KFontName, KFontSize);
CGraphicsDevice* screenDevice = CEikonEnv::Static()->ScreenDevice();
screenDevice->GetNearestFontInTwips(font, fontSpec);

Unload the font file in destructor:

CEikonEnv::Static()->ScreenDevice()->ReleaseFont(font);
CEikonEnv::Static()->ScreenDevice()->RemoveFile(fontFileID);

Note that AddFile() will use a reference-counted list of fonts - the reference count is decremented automatically when a client is destroyed and the typeface is removed when the count is zero. Alternatively, a client can remove a font file explicitly by calling RemoveFile() with the font file ID as a parameter.

After successfully adding a font file, new fonts can be found with GetNearestFont...() functions from CFbsTypefaceStore.

This page was last modified on 19 September 2012, at 00:30.
42 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.

×