Framework / Graphics / Fonts
In This Topic

    Fonts

    In This Topic

    Nevron Open Vision (NOV) fully supports the TrueType font specification (fonts with the extension of ".ttf" or ".ttc"). Such fonts can be installed and uninstalled from the NOV font service at runtime, provided that you can obtain a stream object to the font data. The following sections will teach you how to install fonts.

     Font Service and Font Cache

    NOV provides a font service, which can be used to load fonts, add new fonts, generate preview thumbnails of font names for the font name combo box and so on. The font service generates thumnails of all font names and caches them in memory until the application is closed. By default the font cache is not saved to disk. The size of the font cache is less than 1MB in a typical Windows installation. If you want to save it to disk, set the CacheFontNameThumbnails of the font service to true:

    Enable writing font cache
    Copy Code
    NApplication.FontService.CacheFontNameThumbnails = true;
    
     Installed Fonts

    By default the NOV framework comes with the following built-in fonts - Arial, Source Code Pro, Symbol Neu and Font Awesome.

    In addition, depending on the environment NOV will automatically determine which fonts are accessible and automatically register them in the font service:

    Environment Installed Fonts
    Windows (WinForm of WPF) Built-in fonts and all TrueType fonts present in the Windows\Fonts directory.
    macOS Built-in fonts and all system fonts.
    Blazor WebAssembly Built-in fonts only.

    When you request a font the system will automatically search for it in the list of registered fonts and if present it will use that font. Otherwise, depending on the request it will perform a fallback to the font that most closely matches the requested font.

     Installing Fonts

    In order to install a font you need to be able to provide a stream based access to the font binary data. NOV provides several classes that facilitate the most common font sources:

    Class Description
    NOTFileInstalledFont Represents a font that resides in a hard drive - for example "c:\windows\fonts\arial.ttf"
    NOTMemoryInstalledFont Represents a font that resides in memory (byte array)
    NOTResourceInstalledFont Represents a font that resides in a resource

     

    The following code snippet shows how to install a font from different sources:

    Installing fonts
    Copy Code
    // Installing font from memory
    NApplication.FontService.InstalledFontsMap.InstallFont(new NOTMemoryInstalledFont(someByteArray));
    
    // Installing font from file
    NApplication.FontService.InstalledFontsMap.InstallFont(new NOTFileInstalledFont(@"c:\windows\fonts\arial.ttf"));
    
    // Installing font from resource
    NApplication.FontService.InstalledFontsMap.InstallFont(new NOTResourceInstalledFont(someEmbeddedResource));