@eclipse-scout/core
Version:
Eclipse Scout runtime
99 lines • 5.02 kB
TypeScript
/// <reference types="jquery" />
export interface FontDescriptor {
family: string;
style?: string;
testString?: string;
testFonts?: string;
}
export interface FontPreloadOptions {
/**
* A single string or object (or an array of them) specifying which fonts should be preloaded.
* A string is interpreted as font-family.
* If the style is relevant too, an object with the properties 'family' and 'style' should be provided.
* Alternatively, the style can be specified in the string after the font name, separated by a pipe character ('|').
* The property {@link testString} (or a third component in a '|' separated string) may be specified to set the characters to measure for this specific font (can be useful for icon fonts).
*/
fonts: string | string[] | FontDescriptor | FontDescriptor[];
/**
* Mandatory function to be called when all of the specified fonts have been loaded or if a timeout occurs. If this option is omitted, the call to this method returns immediately.
* @param success indicate whether loading was completed successfully or execution was interrupted by a timeout.
* @param badFonts The bad fonts
*/
onComplete?: (success: boolean, badFonts: string[]) => void;
/**
* Optional timeout in milliseconds. If fonts could not be loaded within this time, loading is stopped and the {@link onComplete} method is called with argument 'false'.
* Defaults to {@link TEST_TIMEOUT}.
*/
timeout?: number;
/**
* Optional. Test fonts (string separated by commas) to used as baseline when checking if the specified fonts have been loaded. Defaults to {@link TEST_FONTS}.
*/
testFonts?: string;
/**
* Optional. The test string to use when checking if the specified fonts have been loaded. Should not be empty, because the empty string has always the width 0.
* The default is {@link TEST_STRING}. The test string may also be specified individually per font.
*/
testString?: string;
}
export declare const fonts: {
_deferred: JQuery.Deferred<any, any, any>;
/**
* Indicates whether all fonts have been loaded successfully. Check this variable before
* waiting for the promise object returned by preloader().
*/
loadingComplete: boolean;
/**
* Start preloading the specified fonts. If no fonts are specified, the list of fonts
* to preload is automatically calculated from the available CSS "@font-face" definitions.
* To disable preloading entirely, pass an empty array to this function.
*
* @param fontArr (optional) array of fonts
* @returns promise that is resolved when all fonts are loaded
*/
bootstrap(fontArr: FontDescriptor[]): JQuery.Promise<void>;
/**
* @returns a promise object that is notified when the font preloading was completed.
* Important: Before waiting for this promise, always check that value of
* loadingComplete first! Do not wait for the promise when loadingComplete
* is true, because the promise will never be resolved.
*/
preloader(): JQuery.Promise<void>;
TEST_FONTS: string;
/**
* Test string used for font measurements. Used to detect when a font is fully loaded
* and available in the browser.
*
* Custom characters may be added to this test string if a font is not detected correctly
* because it does not contain any of the default characters.
*
* U+E000 = Start of Unicode private use zone (e.g. scoutIcons)
* U+F118 = Font Awesome: "smile"
*/
TEST_STRING: string;
/**
* Time in milliseconds to wait for the fonts to be loaded.
*/
TEST_TIMEOUT: number;
/**
* Loads the specified fonts in a hidden div, forcing the browser to load them.
* Examples:
* preload({fonts: 'Sauna Pro'});
* preload({fonts: 'Sauna Pro|font-style:italic'});
* preload({fonts: 'Sauna Pro|font-style:italic|The quick brown fox jumps over the lazy dog'});
* preload({fonts: 'Sauna Pro | font-style: italic; font-weight: 700'});
* preload({fonts: 'Sauna Pro', onComplete: handleLoadFinished});
* preload({fonts: ['Sauna Pro', 'Dolly Pro']});
* preload({fonts: {family:'Sauna', style: 'font-style:italic; font-weight:700', testString: 'MyString012345'}, timeout: 999});
* preload({fonts: ['Fakir-Black', {family:'Fakir-Italic', style:'font-style:italic'}], timeout: 2500, onComplete: function() { setCookie('fakir','loaded') }});
*
* Inspired by Zenfonts (https://github.com/zengabor/zenfonts, public domain).
*/
preload(options?: FontPreloadOptions): void;
measureSize($div: JQuery): string;
/**
* Reads all "@font-face" CSS rules from the current document and returns an array of
* font definition objects, suitable for passing to the preload() function (see above).
*/
autoDetectFonts(): FontDescriptor[];
};
//# sourceMappingURL=fonts.d.ts.map