Creating a Linked Typeface

The API that allows the linked typeface to be specified is for use by device creators. It is primarily designed for the creation of device system fonts. The platform security capability ECapabilityWriteDeviceData is required to register linked typefaces. ECapabilityReadDeviceData is required to fetch linked typeface information from the Font and Bitmap Server.

Target audience: Device creators.

This topic builds on the material in the Linked Fonts Guide.

Once a linked typeface has been created any client may get a linked font back in response to a request for the nearest font. When the Font Store searches for the best match to the requested font specification, linked fonts are considered alongside normal bitmap and open fonts. If a linked font represents the best match, it is returned. As far as the client is concerned, the fact that it is a linked font is invisible.

Example code

The following code example shows how to create, specify and then register a linked typeface.

// Create a typeface specification
CLinkedTypefaceSpecification *typefaceSpec;
    
// This is the name of the new linked typeface.
_LIT(KLinkedTypeface, "LinkedTypefaceTT") ;  
            
typefaceSpec = CLinkedTypefaceSpecification::NewLC( KLinkedTypeface );
    
// Create at least one linked typeface group.
// Each typeface in the linked font must be assigned to a group.
// The group specifies font characteristics.
const TUint KGroup1Id = 1 ; // group ID
CLinkedTypefaceGroup* group1 = CLinkedTypefaceGroup::NewLC( KGroup1Id ); 
     
// Italic angle is specified as a percentage. 
group1->SetItalicAngle( 30 ); 
group1->SetBaselineShift( ENoBaselineShift ); 
    
// Add the group to the typeface specification
typefaceSpec->AddLinkedTypefaceGroupL( *group1 );
CleanupStack::Pop(); // group1.
    
// Add additional groups...
const TUint KGroup2Id = 2; 
    
...
    
// Add first typeface by creating an element specification. 
// This must be the name of a font in the font store.
_LIT( KLinkedTypeface1, "LinkedFont1TT" );  
    
CLinkedTypefaceElementSpec *elementSpec1;
elementSpec1 = CLinkedTypefaceElementSpec::NewLC( KLinkedTypeface1, KGroup1Id );
    
// One typeface (not necessarily the first) must be set as the canonical typeface.
elementSpec1->SetCanonical( ETrue );
    
// Add the element to the typeface.
typefaceSpec->AddTypefaceAtBackL( *elementSpec1 );
CleanupStack::Pop() ;  // elementSpec1.
    
// Create and add additional element specifications.
    
...
    
elementSpecX = CLinkedTypefaceElementSpec::NewLC( KLinkedTypefaceX, KGroupNId );
    
...
    
typefaceSpec->AddTypefaceAtBackL( *elementSpecX );
    
...
    
// Register the linked typeface with the Typeface store.
// iDev is a previously created CFbsDevice.
CFbsTypefaceStore* typefaceStore = CFbsTypefaceStore::NewL( iDev ); 
CleanupStack::PushL( typefaceStore );
    
typefaceSpec->RegisterLinkedTypefaceL( *typefaceStore  );
CleanupStack::PopAndDestroy( 2, store );

The following code example shows one way of getting the nearest font to a specified font specification.

TFontSpec fontSpec;
fontSpec.iTypeface.iName = KRequiredTypeface;
fontSpec.iHeight = 20;
fontSpec.iFontStyle.SetBitmapType(EAntiAliasedGlyphBitmap);
    
// CFbsTypefaceStore
CFont* myFont;
tfstore->GetNearestFontToMaxHeightInPixelsL(myFont, fontSpec);
    
// CFbsBitGc
gc->UseFont(myFont);
...

Multiple linked typefaces

You can create any number of linked typefaces (subject to device resource limitations) as long as they all have different names. You can:

  • use the same typeface as a component typeface in multiple linked typefaces

  • create the same linked font multiple times in multiple clients

  • create multiple linked fonts, with different specifications, from the same linked typeface

  • create multiple linked fonts from different linked typefaces

  • create linked typefaces that can contain nested linked typefaces, if supported by the font rasterizer.

The following constraints apply:

  • The typefaces composing a linked typeface must be open typefaces. Bitmaps fonts are not supported.

  • The linked typeface name must be unique.

  • The typefaces in a linked typeface must be present when the linked typeface is registered.

  • Linked typefaces cannot be deleted.