Skip to main content

Using fonts which are not installed in Windows

Ibex normally uses fonts which are installed in Windows and locates these fonts using the registry. However it is possible to use a pass fonts to Ibex which have been read from some another location and are not installed in the registry.

This process involves reading the font file into memory and passing it to Ibex, together with some parameters which specify the font name and other details.

Usage

The basic approach is to create an FODocument object, then read fonts into memory and pass them to Ibex like this:

FODocument doc = new FODocument();

// read the font data
byte[] font_data = getFont(@".\fonts\vineritc.ttf");

// give ibex the font data
doc.loadFontFromMemory("chicken", false, false, font_data );

The last parameter to the loadFontFromMemory() call is the font data read from a TrueType font file. You should implement this yourself to read the data from wherever the font files are. This gives you the flexibility to ship fonts files on disk or as resources built into your application. Example code to read the font data from a file on disk is:

public static byte[] getFont(string file_name)
{
if (file_name == null || file_name.Length == 0 )
{
Console.WriteLine("getFont() file name is required" );
return null;
}

try
{
FileStream stream = new FileStream(file_name, FileMode.Open, FileAccess.Read);
byte[] bytes = new byte[stream.Length];
using (stream)
{
stream.Read(bytes, 0, bytes.Length);
}

return bytes;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
return null;
}

The method loadFontFromMemory() on the FODocument object is used to pass Ibex the font data. Each call identifies a particular font by the name used in the Fo file and associates it with an identifier.

The parameters are:

NameTypeDescription
font namestringThe name by which the font is referred to in the FO file, such as "arial", this should be the basic font name without ay reference to bold or italic
boldboolWhether the font is bold or not
italicboolWhether the font is italic or not
font_databyte[]The contents of a TrueType font file