Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 3.0 License, and code samples are licensed under the BSD License.
©2012 Google
The Font Settings API allows you to manage Chrome's font settings.
To use the Font Settings API, you must declare the "fontSettings" permission in the extension manifest. For example:
{ "name": "My Font Settings Extension", "description": "Customize your fonts", "version": "0.2", "permissions": ["fontSettings"] }
Chrome allows for some font settings to depend on certain generic font families and language scripts. For example, the font used for sans-serif Simplified Chinese may be different than the font used for serif Japanese.
The generic font families supported by Chrome are based on CSS generic font families and are listed in the API reference below. When a webpage specifies a generic font family, Chrome selects the font based on the corresponding setting. If no generic font family is specified, Chrome uses the setting for the "standard" generic font family.
When a webpage specifies a language, Chrome selects the font based on the setting for the corresponding language script. If no language is specified, Chrome uses the setting for the default, or global, script.
The supported language scripts are specified by ISO 15924 script code and listed in the API reference below. Technically, Chrome settings are not strictly per-script but also depend on language. For example, Chrome chooses the font for Cyrillic (ISO 15924 script code "Cyrl") when a webpage specifies the Russian language, and uses this font not just for Cyrillic script but for everything the font covers, such as Latin.
The following code gets the standard font for Arabic.
chrome.fontSettings.getFont( { genericFamily: 'standard', script: 'Arab' }, function(details) { console.log(details.fontId); } );
The next snippet sets the sans-serif font for Japanese.
chrome.fontSettings.setFont( { genericFamily: 'sansserif', script: 'Jpan', fontId: 'MS PGothic' } );
You can find a sample extension using the Font Settings API in the examples/api/fontSettings directory. For other examples and for help in viewing the source code, see Samples.
Clears the font set by this extension, if any.
If you specify the callback parameter, it should specify a function that looks like this:
function() {...};
Gets the font for a given script and generic font family.
If you specify the callback parameter, it should specify a function that looks like this:
function(object details) {...};
setFont
, if, for example, the font is not available on the system. The empty string signifies fallback to the global script font setting. Sets the font for a given script and generic font family.
If you specify the callback parameter, it should specify a function that looks like this:
function() {...};
Gets a list of fonts on the system.
Gets the default font size.
If you specify the callback parameter, it should specify a function that looks like this:
function(object details) {...};
Gets the default size for fixed width fonts.
If you specify the callback parameter, it should specify a function that looks like this:
function(object details) {...};
Gets the minimum font size.
If you specify the callback parameter, it should specify a function that looks like this:
function(object details) {...};
Fired when a font setting changes.
Fired when the default font size setting changes.
Fired when the default fixed font size setting changes.
Fired when the minimum font size setting changes.