COpenFontRasterizer
Classes derived from COpenFontRasterizer
are used to recognise font files and create objects to manage them. To derive from COpenFontRasterizer
you need only provide an implementation of its pure virtual function NewFontFileL()
. The implementation of this function is discussed in the following section.
The derived class should also define the DLL's single exported function. This function is discussed further in the previous topic: The exported function.
In addition, rasterizer classes will often need to store an 'engine context'. For example, FreeType relies on a TT_Engine
object; this is kept in the CFreeTypeRasterizer
, in a CFreeTypeRasterizerContext
. The context is derived from COpenFontRasterizerContext
, a utility base class that provides functions that make it easier to write the glyph bitmap during rasterization.
The implementation must examine a specified file and, if it is of the correct type, attempt to create a COpenFontFile
derived object to open it. The function must return NULL if it cannot recognise the file. It may also leave if there is an error. The caller is responsible for deleting the COpenFontFile
object.
The function prototype is given below:
virtual COpenFontFile* NewFontFileL(TInt aUid,
const TDesC& aFileName, RFs& aFileSession) = 0;
aUid
is an ID to be used for the font file — the application framework requires that each typeface have a UID, so one is dynamically allocated for font files that are not Symbian-native. The ID must be passed to the COpenFontFile
derived class's constructor.
aFileName
is the full path and filename of the file that the rasterizer is attempting to open. This filename must also be passed to the COpenFontFile
derived class's constructor.
aFileSession
is the file session owned by the Font and Bitmap server. This reference should be used for any file access. If COpenFontFile
derived objects need to keep files open, aFileSession
should be stored in a place that is accessible to them.
The FreeType implementation of NewFontFileL()
is given below. It recognises the file only by its extension, relying on the construction of the font file object to perform stricter checking.
COpenFontFile* CFreeTypeRasterizer::NewFontFileL(TInt aUid,
const TDesC& aFileName,RFs& aFileSession)
{
TBool is_ttf = EFalse;
//Tests if the filename extension is ".ttf" or ".ttc".
if (aFileName.Length() > 4)
{
_LIT(KExtensionTTF,".ttf"); // Extension for truetype font file.
_LIT(KExtensionTTC,".ttc"); // Extension for truetype collection file.
TPtrC ext = aFileName.Right(4);
if ((ext.CompareF(KExtensionTTF) == 0) | (ext.CompareF(KExtensionTTC)==0))
is_ttf = ETrue;
}
// If the extension is not .ttf or .ttc then we can't read the file.
if (!is_ttf)
return NULL;
//If extension is .ttf then attempt to create the font file reader.
//return it to the caller.
return CFreeTypeFontFile::NewL(iContext,aUid,
aFileName,aFileSession);
}