Interface FontInterface

The memory representation of a font in the FontLoaderInterface.

FontInterface are retrieved through FontLoaderInterface.getRegisteredFonts.

/** 
* Sample to illustrate the loading of fonts.
*/
import { FontLoaderInterface, InfiniteFactory, FontLoaderInterfaceSignal, InfiniteEvent, FontLoadingStatus, FontInterface } from 'generated_files/documentation/appinfiniteapi';

// font loading is used wheen loading annotations

// what to do when fonts are loaded
let lFontLoaded : (pEvent : InfiniteEvent) => void;
// get the font loader, no need to create it, all the time available (singleton)
const lFontLoader : FontLoaderInterface = InfiniteFactory.GetInfiniteApiController().getFontLoader();
// register font Open Sans normal (no bold, no italic) by its url
const lFontRegistered : boolean = lFontLoader.registerFont('Open Sans', false, false, 'resources/fonts/OpenSans-Regular.otf');
console.assert(lFontRegistered, 'font should be registered');

// what to do when fonts is loaded ?
lFontLoader.addEventListener(FontLoaderInterfaceSignal.FontsLoaded, lFontLoaded);
// load explicitly font, if not, font will be loaded if required when loading annotations
const lLoadStatus : FontLoadingStatus = lFontLoader.loadFont('Open Sans', false, false);
console.assert(lLoadStatus === FontLoadingStatus.FLS_LoadingStarted, 'Font loading should be started');

// when fonts are loaded => what do we do ?
// perhaps some gui code ?
lFontLoaded = (_pEvent : InfiniteEvent) : void =>
{
// get all registered fonts and their status
const lFonts : Array<FontInterface> = [];
lFontLoader.getRegisteredFonts(lFonts);
let i : number;
let lErrorCount : number = 0;
for (i = 0; i < lFonts.length; i += 1)
{
if (lFonts[i].error !== undefined)
{
lErrorCount += 1;
}
}
console.assert(lErrorCount === 0, 'There should be no font in error');
// when font is loaded, we unload it, but perhaps we should make some gui code ? :)
lFontLoader.unregisterFont('Open Sans', false, false);
};

Please make sure the destination browser supports promises before using async calls.
3D Rendering

interface FontInterface {
    bold: boolean;
    error?: InfiniteError;
    familyName: string;
    italic: boolean;
    loadStatus: FontLoadingStatus;
}

Properties

bold: boolean

Tells if the font is a bold one.

The error (if any) of the font.

familyName: string

The family name of the given font (lowercase).

italic: boolean

Tells if the font is an italic one.

loadStatus: FontLoadingStatus

The loading status of the font.