You are viewing extension docs in chrome via the 'file:' scheme: are you expecting to see local changes when you refresh? You'll need run chrome with --allow-file-access-from-files.
WARNING: This is the BETA documentation. It may not work with the stable release of Chrome.
WARNING: This is unofficial documentation. It may not work with the current release of Chrome.

Google Chrome Extensions (Labs)

chrome.experimental.fontSettings

For information on how to use experimental APIs, see the chrome.experimental.* APIs page.

The Font Settings API allows you to manage Chrome's font settings.

Manifest

The Font Settings API is currently experimental, so you must declare the "experimental" permission to use it. For example:

{
  "name": "My Font Settings Extension",
  "description": "Customize your fonts",
  "version": "0.2",
  "permissions": ["experimental"]
}

Generic Font Families and Scripts

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 based on ISO 15924 script codes 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 Hangul (ISO 15924 script code "Hang") when a webpage specifies Korean language, and uses this font not just for Hangul script but for everything the font covers, such as Hanja.

Although ISO 15924 provides script codes like "Japn" for Japanese and "Kore" for Korean, these codes are newer than "Hrkt" and "Hang" which Chrome continues to use for compatibility purposes.

Examples

The following code gets the standard font for Arabic.

chrome.experimental.fontSettings.getFontName(
  { genericFamily: 'standard', script: 'Arab' },
  function(details) { console.log(details.fontName); }
);

The next snippet sets the sans-serif font for Japanese.

chrome.experimental.fontSettings.setFontName(
  { genericFamily: 'sansserif', script: 'Hrkt', fontName: 'IPAPGothic' }
);

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.

API reference: chrome.experimental.fontSettings

Methods

getDefaultFixedFontSize

chrome.experimental.fontSettings.getDefaultFixedFontSize(object details, function callback)

Gets the default size for fixed width fonts.

Parameters

details
( optional object )
This parameter is currently unused.
callback
( optional function )
Undocumented.

Callback function

If you specify the callback parameter, it should specify a function that looks like this:

function(object details) {...};
details
( object )
Undocumented.
pixelSize
( integer )
The font size in pixels.

getDefaultFontSize

chrome.experimental.fontSettings.getDefaultFontSize(object details, function callback)

Gets the default font size.

Parameters

details
( optional object )
This parameter is currently unused.
callback
( optional function )
Undocumented.

Callback function

If you specify the callback parameter, it should specify a function that looks like this:

function(object details) {...};
details
( object )
Undocumented.
pixelSize
( integer )
The font size in pixels.

getFontList

chrome.experimental.fontSettings.getFontList(function callback)

Gets a list of fonts on the system.

Parameters

callback
( function )
Undocumented.

Callback function

The callback parameter should specify a function that looks like this:

function(array of FontName results) {...};
results
( array of FontName )
Undocumented.

getFontName

chrome.experimental.fontSettings.getFontName(object details, function callback)

Gets the font name of the current setting for a given script and generic font family.

Parameters

details
( object )
Undocumented.
script
( optional enumerated string ["Arab", "Armn", "Beng", "Cans", "Cher", "Cyrl", "Deva", "Ethi", "Geor", "Grek", "Gujr", "Guru", "Hang", "Hans", "Hant", "Hebr", "Hrkt", "Knda", "Khmr", "Laoo", "Mlym", "Mong", "Mymr", "Orya", "Sinh", "Taml", "Telu", "Thaa", "Thai", "Tibt", "Yiii"] )
The ISO 15924 script code for which the font setting should be retrieved. If omitted, the global script font setting is retrieved.
genericFamily
( enumerated string ["standard", "sansserif", "serif", "fixed", "cursive", "fantasy"] )
The CSS generic font family for which the font setting should be retrieved.
callback
( optional function )
Undocumented.

Callback function

If you specify the callback parameter, it should specify a function that looks like this:

function(object details) {...};
details
( object )
Undocumented.
fontName
( string )
The font name. Rather than the literal font name preference value, this may be the name of the font that the system resolves the preference value to. The empty string signifies fallback to the global script font setting.

getMinimumFontSize

chrome.experimental.fontSettings.getMinimumFontSize(object details, function callback)

Gets the minimum font size.

Parameters

details
( optional object )
This parameter is currently unused.
callback
( optional function )
Undocumented.

Callback function

If you specify the callback parameter, it should specify a function that looks like this:

function(object details) {...};
details
( object )
Undocumented.
pixelSize
( integer )
The font size in pixels.

setDefaultFixedFontSize

chrome.experimental.fontSettings.setDefaultFixedFontSize(object details, function callback)

Sets the default size for fixed width fonts.

Parameters

details
( object )
Undocumented.
pixelSize
( integer )
The font size in pixels.
callback
( optional function )
Undocumented.

Callback function

If you specify the callback parameter, it should specify a function that looks like this:

function() {...};

setDefaultFontSize

chrome.experimental.fontSettings.setDefaultFontSize(object details, function callback)

Sets the default font size.

Parameters

details
( object )
Undocumented.
pixelSize
( integer )
The font size in pixels.
callback
( optional function )
Undocumented.

Callback function

If you specify the callback parameter, it should specify a function that looks like this:

function() {...};

setFontName

chrome.experimental.fontSettings.setFontName(object details, function callback)

Sets the font name of the current setting for a given script and generic font family.

Parameters

details
( object )
Undocumented.
script
( optional enumerated string ["Arab", "Armn", "Beng", "Cans", "Cher", "Cyrl", "Deva", "Ethi", "Geor", "Grek", "Gujr", "Guru", "Hang", "Hans", "Hant", "Hebr", "Hrkt", "Knda", "Khmr", "Laoo", "Mlym", "Mong", "Mymr", "Orya", "Sinh", "Taml", "Telu", "Thaa", "Thai", "Tibt", "Yiii"] )
The ISO 15924 script code for which the font setting should be set. If omitted, the global script font setting is set.
genericFamily
( enumerated string ["standard", "sansserif", "serif", "fixed", "cursive", "fantasy"] )
The CSS generic font family for which the font setting should be set.
fontName
( string )
The font name. If a script is specified, the empty string means to fallback to the global script font setting.
callback
( optional function )
Undocumented.

Callback function

If you specify the callback parameter, it should specify a function that looks like this:

function() {...};

setMinimumFontSize

chrome.experimental.fontSettings.setMinimumFontSize(object details, function callback)

Sets the minimum font size.

Parameters

details
( object )
Undocumented.
pixelSize
( integer )
The font size in pixels.
callback
( optional function )
Undocumented.

Callback function

If you specify the callback parameter, it should specify a function that looks like this:

function() {...};

Types

FontName

( object )
Represents a font name.
fontName
( string )
The font name.
localizedName
( string )
The font name localized for the current locale.