2.9.16
Coherent GT
A modern user interface library for games
Loading UI fonts

By default during initialization the particular locations of fonts for the system the Coherent GT is run on are traversed gathering and caching info for each font. This may sometimes lead to unneeded delay. If the fonts used by the application are stored in a specific folder this path can be pointed as the only source of font data.

The following options are available for using specific fonts:

Coherent::UIGT::SystemSettings settings;
settings.LoadSystemFonts = false;
UISystem = InitializeUIGTSystem(COHERENT_UI_GT_LICENSE,
    settings,
    Coherent::LoggingGT::Debug,
    &LogHandler);
Note
Disabling loading of the system font folders means that unless you manually call Coherent::UIGT::UISystem::AddFontsFolder system fonts (such as Arial and Verdana) will be unavailable.
Warning
If you using GT in Asynchrous mode an extra step may be required in case of using @font-face. Loading the font will be done asynchronously and during that time GT will attempt to use a default font - usually Arial. Since Arial is missing the application may break.
  • Add folder(s) containing the necessary font data before usage but after the initialization step.
UISystem->AddFontsFolder("./SampleFonts");
  • Font data files are parsed lazily on demand before the first usage of the font. If any visual artifacts rendering a font are observed the first time it is used the font can be preloaded using the UISystem::AddFont method. The parameters require pointer pointing to buffer containing the read font file data and the total size of the data. It is important to note that the Coherent::UIGT::UISystem would not copy any file data therefore the lifetime of the font data buffer is entirely responsibility of the framework calling the method. Make sure that the buffer is NOT deleted until the font is still in use. The following is an example of how NOT to use the API, its purpose is only demonstration:
    std::ifstream fontInput("loaded_fonts/times.ttf", std::ios::binary);
    fontInput.seekg(0, std::ios::end);
    std::streamsize size = fontInput.tellg();
    fontInput.seekg(0, std::ios::beg);
    
    static std::vector<char> buffer(size);
    if (fontInput.read(buffer.data(), size))
    {
        UISystem->AddFont(buffer.data(), size);
    }
    
    fontInput.close();