/** * Sample to illustrate the Loading of fonts. */ import { FontLoaderInterface, InfiniteFactory, FontLoaderInterfaceSignal, InfiniteEvent, FontLoadingStatus, FontInterface } from'generated/documentation/appinfiniteapi';
// font loading is used wheen loading annotations
// what to do when fonts are loaded letlFontLoaded : (pEvent : InfiniteEvent) =>void; // get the font loader, no need to create it, all the time available (singleton) constlFontLoader : FontLoaderInterface = InfiniteFactory.GetInfiniteApiController().getFontLoader(); // register font Open Sans normal (no bold, no italic) by its url constlFontRegistered : 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 constlLoadStatus : 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 constlFonts : Array<FontInterface> = []; lFontLoader.getRegisteredFonts(lFonts); leti : number; letlErrorCount : number = 0; for (i = 0; i < lFonts.length; ++i) { if (lFonts[i].error !== undefined) { ++lErrorCount; } } 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 refer to the [FontLoaderInterface](../interfaces/FontLoaderInterface.html) for more information.
The FontLoaderInterfaceSignal lists all the signals that may be sent by the FontLoaderInterface.
These signals are emitted by the FontLoaderInterface has finished loading.
The FontLoaderInterface may fire the following signals :
Please refer to the [FontLoaderInterface](../interfaces/FontLoaderInterface.html) for more information.
See
FontLoaderInterface