/** * 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 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 += 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.
The memory representation of a font in the FontLoaderInterface.
FontInterface are retrieved through FontLoaderInterface.getRegisteredFonts.
Please make sure the destination browser supports promises before using async calls.
See
FontLoaderInterface