Enumeration FontLoadingStatus

The result of a font loading request or the loading status of a font.

This result is obtained from a call to FontLoaderInterface.loadFont and FontInterfaces inside a FontLoaderInterface.getRegisteredFonts request.

/** 
* 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);
};

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

// font loading is used wheen loading annotations

// 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');

const waitForResult = async () : Promise<void> =>
{
// 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');
// wait for loading to complete
await lFontLoader.asyncWaitForFontsLoaded();
// fonts are now loaded => what do we do ?
// perhaps some gui code ?
// 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);
};

waitForResult();

Please refer to FontLoaderInterface for more information.


3D Rendering

Enumeration Members

FLS_FontError: 5

The previous call to FontLoaderInterface.loadFont failed.

There is no way to update the buffer or url of a given font, just unregister and register the font again with correct parameters.

FLS_FontMissing: 4

The given font was not found.

FLS_Loaded: 1

The font is already loaded.

FLS_Loading: 2

The font is loading.

FLS_LoadingStarted: 3

The font loading procedure has just started.

FLS_NotLoaded: 0

The font is not loaded and no pending loading request is ongoing.