chrome.fontSettings
Description: |
Use the chrome.fontSettings API to manage Chrome's font settings.
|
Availability: |
Since Chrome 35.
|
Permissions: |
"fontSettings"
|
Manifest
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" ], ... }
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 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.
Examples
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.
Summary
Types | |
---|---|
FontName | |
ScriptCode | |
GenericFamily | |
LevelOfControl | |
Methods | |
clearFont −
chrome.fontSettings.clearFont(object details, function callback)
| |
getFont −
chrome.fontSettings.getFont(object details, function callback)
| |
setFont −
chrome.fontSettings.setFont(object details, function callback)
| |
getFontList −
chrome.fontSettings.getFontList(function callback)
| |
clearDefaultFontSize −
chrome.fontSettings.clearDefaultFontSize(object details, function callback)
| |
getDefaultFontSize −
chrome.fontSettings.getDefaultFontSize(object details, function callback)
| |
setDefaultFontSize −
chrome.fontSettings.setDefaultFontSize(object details, function callback)
| |
clearDefaultFixedFontSize −
chrome.fontSettings.clearDefaultFixedFontSize(object details, function callback)
| |
getDefaultFixedFontSize −
chrome.fontSettings.getDefaultFixedFontSize(object details, function callback)
| |
setDefaultFixedFontSize −
chrome.fontSettings.setDefaultFixedFontSize(object details, function callback)
| |
clearMinimumFontSize −
chrome.fontSettings.clearMinimumFontSize(object details, function callback)
| |
getMinimumFontSize −
chrome.fontSettings.getMinimumFontSize(object details, function callback)
| |
setMinimumFontSize −
chrome.fontSettings.setMinimumFontSize(object details, function callback)
| |
Events | |
onFontChanged | |
onDefaultFontSizeChanged | |
onDefaultFixedFontSizeChanged | |
onMinimumFontSizeChanged |
Types
FontName
properties | ||
---|---|---|
string | fontId |
The font ID. |
string | displayName |
The display name of the font. |
ScriptCode
Enum |
---|
"Afak" ,
"Arab" ,
"Armi" ,
"Armn" ,
"Avst" ,
"Bali" ,
"Bamu" ,
"Bass" ,
"Batk" ,
"Beng" ,
"Blis" ,
"Bopo" ,
"Brah" ,
"Brai" ,
"Bugi" ,
"Buhd" ,
"Cakm" ,
"Cans" ,
"Cari" ,
"Cham" ,
"Cher" ,
"Cirt" ,
"Copt" ,
"Cprt" ,
"Cyrl" ,
"Cyrs" ,
"Deva" ,
"Dsrt" ,
"Dupl" ,
"Egyd" ,
"Egyh" ,
"Egyp" ,
"Elba" ,
"Ethi" ,
"Geor" ,
"Geok" ,
"Glag" ,
"Goth" ,
"Gran" ,
"Grek" ,
"Gujr" ,
"Guru" ,
"Hang" ,
"Hani" ,
"Hano" ,
"Hans" ,
"Hant" ,
"Hebr" ,
"Hluw" ,
"Hmng" ,
"Hung" ,
"Inds" ,
"Ital" ,
"Java" ,
"Jpan" ,
"Jurc" ,
"Kali" ,
"Khar" ,
"Khmr" ,
"Khoj" ,
"Knda" ,
"Kpel" ,
"Kthi" ,
"Lana" ,
"Laoo" ,
"Latf" ,
"Latg" ,
"Latn" ,
"Lepc" ,
"Limb" ,
"Lina" ,
"Linb" ,
"Lisu" ,
"Loma" ,
"Lyci" ,
"Lydi" ,
"Mand" ,
"Mani" ,
"Maya" ,
"Mend" ,
"Merc" ,
"Mero" ,
"Mlym" ,
"Moon" ,
"Mong" ,
"Mroo" ,
"Mtei" ,
"Mymr" ,
"Narb" ,
"Nbat" ,
"Nkgb" ,
"Nkoo" ,
"Nshu" ,
"Ogam" ,
"Olck" ,
"Orkh" ,
"Orya" ,
"Osma" ,
"Palm" ,
"Perm" ,
"Phag" ,
"Phli" ,
"Phlp" ,
"Phlv" ,
"Phnx" ,
"Plrd" ,
"Prti" ,
"Rjng" ,
"Roro" ,
"Runr" ,
"Samr" ,
"Sara" ,
"Sarb" ,
"Saur" ,
"Sgnw" ,
"Shaw" ,
"Shrd" ,
"Sind" ,
"Sinh" ,
"Sora" ,
"Sund" ,
"Sylo" ,
"Syrc" ,
"Syre" ,
"Syrj" ,
"Syrn" ,
"Tagb" ,
"Takr" ,
"Tale" ,
"Talu" ,
"Taml" ,
"Tang" ,
"Tavt" ,
"Telu" ,
"Teng" ,
"Tfng" ,
"Tglg" ,
"Thaa" ,
"Thai" ,
"Tibt" ,
"Tirh" ,
"Ugar" ,
"Vaii" ,
"Visp" ,
"Wara" ,
"Wole" ,
"Xpeo" ,
"Xsux" ,
"Yiii" ,
"Zmth" ,
"Zsym" ,
or "Zyyy"
|
GenericFamily
Enum |
---|
"standard" ,
"sansserif" ,
"serif" ,
"fixed" ,
"cursive" ,
or "fantasy"
|
LevelOfControl
Enum |
---|
"not_controllable" ,
"controlled_by_other_extensions" ,
"controllable_by_this_extension" ,
or "controlled_by_this_extension"
|
Methods
clearFont
chrome.fontSettings.clearFont(object details, function callback)
Clears the font set by this extension, if any.
Parameters | ||||||||
---|---|---|---|---|---|---|---|---|
object | details |
|
||||||
function | (optional) callback |
If you specify the callback parameter, it should be a function that looks like this: function() {...};
|
getFont
chrome.fontSettings.getFont(object details, function callback)
Gets the font for a given script and generic font family.
Parameters | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
object | details |
|
|||||||||
function | (optional) callback |
If you specify the callback parameter, it should be a function that looks like this: function(object details) {...};
|
setFont
chrome.fontSettings.setFont(object details, function callback)
Sets the font for a given script and generic font family.
Parameters | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
object | details |
|
|||||||||
function | (optional) callback |
If you specify the callback parameter, it should be a function that looks like this: function() {...};
|
getFontList
chrome.fontSettings.getFontList(function callback)
clearDefaultFontSize
chrome.fontSettings.clearDefaultFontSize(object details, function callback)
Clears the default font size set by this extension, if any.
Parameters | ||
---|---|---|
object | (optional) details |
This parameter is currently unused. |
function | (optional) callback |
If you specify the callback parameter, it should be a function that looks like this: function() {...};
|
getDefaultFontSize
chrome.fontSettings.getDefaultFontSize(object details, function callback)
Gets the default font size.
Parameters | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
object | (optional) details |
This parameter is currently unused. |
|||||||||
function | (optional) callback |
If you specify the callback parameter, it should be a function that looks like this: function(object details) {...};
|
setDefaultFontSize
chrome.fontSettings.setDefaultFontSize(object details, function callback)
Sets the default font size.
Parameters | |||||
---|---|---|---|---|---|
object | details |
|
|||
function | (optional) callback |
If you specify the callback parameter, it should be a function that looks like this: function() {...};
|
clearDefaultFixedFontSize
chrome.fontSettings.clearDefaultFixedFontSize(object details, function callback)
Clears the default fixed font size set by this extension, if any.
Parameters | ||
---|---|---|
object | (optional) details |
This parameter is currently unused. |
function | (optional) callback |
If you specify the callback parameter, it should be a function that looks like this: function() {...};
|
getDefaultFixedFontSize
chrome.fontSettings.getDefaultFixedFontSize(object details, function callback)
Gets the default size for fixed width fonts.
Parameters | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
object | (optional) details |
This parameter is currently unused. |
|||||||||
function | (optional) callback |
If you specify the callback parameter, it should be a function that looks like this: function(object details) {...};
|
setDefaultFixedFontSize
chrome.fontSettings.setDefaultFixedFontSize(object details, function callback)
Sets the default size for fixed width fonts.
Parameters | |||||
---|---|---|---|---|---|
object | details |
|
|||
function | (optional) callback |
If you specify the callback parameter, it should be a function that looks like this: function() {...};
|
clearMinimumFontSize
chrome.fontSettings.clearMinimumFontSize(object details, function callback)
Clears the minimum font size set by this extension, if any.
Parameters | ||
---|---|---|
object | (optional) details |
This parameter is currently unused. |
function | (optional) callback |
If you specify the callback parameter, it should be a function that looks like this: function() {...};
|
getMinimumFontSize
chrome.fontSettings.getMinimumFontSize(object details, function callback)
Gets the minimum font size.
Parameters | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
object | (optional) details |
This parameter is currently unused. |
|||||||||
function | (optional) callback |
If you specify the callback parameter, it should be a function that looks like this: function(object details) {...};
|
setMinimumFontSize
chrome.fontSettings.setMinimumFontSize(object details, function callback)
Sets the minimum font size.
Parameters | |||||
---|---|---|---|---|---|
object | details |
|
|||
function | (optional) callback |
If you specify the callback parameter, it should be a function that looks like this: function() {...};
|
Events
onFontChanged
Fired when a font setting changes.
addListener
chrome.fontSettings.onFontChanged.addListener(function callback)
Parameters | |||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
function | callback |
The callback parameter should be a function that looks like this: function(object details) {...};
|
onDefaultFontSizeChanged
Fired when the default font size setting changes.
addListener
chrome.fontSettings.onDefaultFontSizeChanged.addListener(function callback)
Parameters | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
function | callback |
The callback parameter should be a function that looks like this: function(object details) {...};
|
onDefaultFixedFontSizeChanged
Fired when the default fixed font size setting changes.
addListener
chrome.fontSettings.onDefaultFixedFontSizeChanged.addListener(function callback)
Parameters | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
function | callback |
The callback parameter should be a function that looks like this: function(object details) {...};
|
onMinimumFontSizeChanged
Fired when the minimum font size setting changes.
addListener
chrome.fontSettings.onMinimumFontSizeChanged.addListener(function callback)
Parameters | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
function | callback |
The callback parameter should be a function that looks like this: function(object details) {...};
|