FontLoaderThe FontLoader detects and notifies when fonts of the specified font-families loaded and rendered by the browser. This, without using timeouts (when possible) to poll for element dimensions like it is done traditionally. Instead it utilizes the "scroll" event to receive an instantaneous event when element size is changed. In IE10 and lower it uses "onresize" event which brings a similar result. In addition it utilizes AdobeBlank1 font to eliminate known issues related to metric compatible fonts2.
More info on how the FontLoader works can be found here3.
UsageThe FontLoader receives an array of fonts and notifies the
completemethods when specific or all fonts were loaded respectively. The FontLoader does not load the fonts, the insertion of specified font-families into the document should be done elsewhere.
FontLoader(fonts, delegate, timeout)constructor receives three parameters:
font- array of font-family strings with optionally specified variations using FVD4 notation, or
delegate- the delegate object with following optional methods which are invoked in the context of the delegate object:
fontLoaded(font)- called when one of the specified fonts was loaded with the font itself passed as the
complete(error)- called when all specified fonts were loaded, in which case the
null. Or when the timeout was reached before all specified fonts were loaded, in which case
errorwill be an object with two fields - the
messagestring and the
notLoadedFontsarray with all the fonts that weren't loaded as
timeout- optional timeout in milliseconds, default is 3000. Pass
nullto disable the timeout.
FontLoadedwas instantiated, call
loadFontsmethod to begin watching for fonts to load. If some or all fonts were already loaded, the appropriate delegate methods will be invoked as expected.
FontDescriptorobject is an object with the following fields:
family- the font family (e.g.: 'Open Sans')
weight- the font weight (e.g.: 400)
style- the font style (e.g.: 'italic')
stretch- the font stretch (e.g.: 'condensed'), optional