Chromium 中chrome.fontSettings扩展接口定义c++

news/2024/11/2 15:51:07/

一、chrome.fontSettings

使用 chrome.fontSettings API 管理 Chrome 的字体设置。

权限

fontSettings

要使用 Font Settings API,您必须在扩展程序中声明 "fontSettings" 权限 清单。例如:

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

概念和用法

Chrome 允许某些字体设置取决于特定的常规字体系列和语言 脚本。例如, sans-serif 简体中文使用的字体可能与该字体不同 用于 serif 日语。

Chrome 支持的通用字体系列基于 CSS 通用字体系列, GenericReference下列出。当网页指定了通用字体系列时,Chrome 会选择 根据相应设置调整字体。如果未指定通用字体系列,则 Chrome 会使用 “包量”规则的通用字体系列。

当网页指定了语言时,Chrome 会根据 相应的语言脚本。如果未指定语言,则 Chrome 会使用默认设置 或全局、脚本。

支持的语言脚本由 ISO 15924 脚本代码指定,并列在下方 ScriptCode。从技术上讲,Chrome 设置并不是严格按脚本进行设置,还取决于 语言。例如,当 网页指定了俄语,并且该字体不仅用于西里尔文字, 字体覆盖的所有内容(如拉丁文)。

示例

以下代码可获取阿拉伯语标准字体。

chrome.fontSettings.getFont({ genericFamily: 'standard', script: 'Arab' },function(details) { console.log(details.fontId); }
);

下一个代码段用于设置日语的 sans-serif 字体。

chrome.fontSettings.setFont({ genericFamily: 'sansserif', script: 'Jpan', fontId: 'MS PGothic' }
);

若要试用此 API,请安装 chrome-extension-samples 中的 fontSettings API 示例 存储库

更多参考:chrome.fontSettings  |  API  |  Chrome for Developers

二、chrome.fontSettings c++接口定义:

1、font_settings.json 接口描述文件:

// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.[{"namespace": "fontSettings","description": "Use the <code>chrome.fontSettings</code> API to manage Chrome's font settings.","types": [{"id": "FontName","type": "object","description": "Represents a font name.","properties": {"fontId": {"type": "string","description": "The font ID."},"displayName": {"type": "string","description": "The display name of the font."}}},{"id": "ScriptCode","type": "string","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", "Zyyy" ],"description": "An ISO 15924 script code. The default, or global, script is represented by script code \"Zyyy\"."},{"id": "GenericFamily","type": "string","enum": ["standard", "sansserif", "serif", "fixed", "cursive", "fantasy", "math"],"description": "A CSS generic font family."},{"id": "LevelOfControl","description": "One of<br><var>not_controllable</var>: cannot be controlled by any extension<br><var>controlled_by_other_extensions</var>: controlled by extensions with higher precedence<br><var>controllable_by_this_extension</var>: can be controlled by this extension<br><var>controlled_by_this_extension</var>: controlled by this extension","type": "string","enum": ["not_controllable", "controlled_by_other_extensions", "controllable_by_this_extension", "controlled_by_this_extension"]}],"functions": [{"name": "clearFont","description": "Clears the font set by this extension, if any.","parameters": [{"name": "details","type": "object","properties": {"script": {"$ref": "ScriptCode","description": "The script for which the font should be cleared. If omitted, the global script font setting is cleared.","optional": true},"genericFamily": {"$ref": "GenericFamily","description": "The generic font family for which the font should be cleared."}}}],"returns_async": {"name": "callback","optional": true,"parameters": []}},{"name": "getFont","description": "Gets the font for a given script and generic font family.","parameters": [{"name": "details","type": "object","properties": {"script": {"$ref": "ScriptCode","description": "The script for which the font should be retrieved. If omitted, the font setting for the global script (script code \"Zyyy\") is retrieved.","optional": true},"genericFamily": {"$ref": "GenericFamily","description": "The generic font family for which the font should be retrieved."}}}],"returns_async": {"name": "callback","optional": true,"parameters": [{"name": "details","type": "object","properties": {"fontId": {"type": "string","description": "The font ID. Rather than the literal font ID preference value, this may be the ID of the font that the system resolves the preference value to. So, <var>fontId</var> can differ from the font passed to <code>setFont</code>, if, for example, the font is not available on the system. The empty string signifies fallback to the global script font setting."},"levelOfControl": {"$ref": "LevelOfControl","description": "The level of control this extension has over the setting."}}}]}},{"name": "setFont","description": "Sets the font for a given script and generic font family.","parameters": [{"name": "details","type": "object","properties": {"script": {"$ref": "ScriptCode","description": "The script code which the font should be set. If omitted, the font setting for the global script (script code \"Zyyy\") is set.","optional": true},"genericFamily": {"$ref": "GenericFamily","description": "The generic font family for which the font should be set."},"fontId": {"type": "string","description": "The font ID. The empty string means to fallback to the global script font setting."}}}],"returns_async": {"name": "callback","optional": true,"parameters": []}},{"name": "getFontList","description": "Gets a list of fonts on the system.","parameters": [],"returns_async": {"name": "callback","parameters": [{"name": "results","type": "array","items": { "$ref": "FontName" }}]}},{"name": "clearDefaultFontSize","description": "Clears the default font size set by this extension, if any.","parameters": [{"name": "details","type": "object","optional": true,"description": "This parameter is currently unused.","properties": {}}],"returns_async": {"name": "callback","optional": true,"parameters": []}},{"name": "getDefaultFontSize","description": "Gets the default font size.","parameters": [{"name": "details","type": "object","optional": true,"description": "This parameter is currently unused.","properties": {}}],"returns_async": {"name": "callback","optional": true,"parameters": [{"name": "details","type": "object","properties": {"pixelSize": {"type": "integer","description": "The font size in pixels."},"levelOfControl": {"$ref": "LevelOfControl","description": "The level of control this extension has over the setting."}}}]}},{"name": "setDefaultFontSize","description": "Sets the default font size.","parameters": [{"name": "details","type": "object","properties": {"pixelSize": {"type": "integer","description": "The font size in pixels."}}}],"returns_async": {"name": "callback","optional": true,"parameters": []}},{"name": "clearDefaultFixedFontSize","description": "Clears the default fixed font size set by this extension, if any.","parameters": [{"name": "details","type": "object","optional": true,"description": "This parameter is currently unused.","properties": {}}],"returns_async": {"name": "callback","optional": true,"parameters": []}},{"name": "getDefaultFixedFontSize","description": "Gets the default size for fixed width fonts.","parameters": [{"name": "details","type": "object","optional": true,"description": "This parameter is currently unused.","properties": {}}],"returns_async": {"name": "callback","optional": true,"parameters": [{"name": "details","type": "object","properties": {"pixelSize": {"type": "integer","description": "The font size in pixels."},"levelOfControl": {"$ref": "LevelOfControl","description": "The level of control this extension has over the setting."}}}]}},{"name": "setDefaultFixedFontSize","description": "Sets the default size for fixed width fonts.","parameters": [{"name": "details","type": "object","properties": {"pixelSize": {"type": "integer","description": "The font size in pixels."}}}],"returns_async": {"name": "callback","optional": true,"parameters": []}},{"name": "clearMinimumFontSize","description": "Clears the minimum font size set by this extension, if any.","parameters": [{"name": "details","type": "object","optional": true,"description": "This parameter is currently unused.","properties": {}}],"returns_async": {"name": "callback","optional": true,"parameters": []}},{"name": "getMinimumFontSize","description": "Gets the minimum font size.","parameters": [{"name": "details","type": "object","optional": true,"description": "This parameter is currently unused.","properties": {}}],"returns_async": {"name": "callback","optional": true,"parameters": [{"name": "details","type": "object","properties": {"pixelSize": {"type": "integer","description": "The font size in pixels."},"levelOfControl": {"$ref": "LevelOfControl","description": "The level of control this extension has over the setting."}}}]}},{"name": "setMinimumFontSize","description": "Sets the minimum font size.","parameters": [{"name": "details","type": "object","properties": {"pixelSize": {"type": "integer","description": "The font size in pixels."}}}],"returns_async": {"name": "callback","optional": true,"parameters": []}}],"events": [{"name": "onFontChanged","description": "Fired when a font setting changes.","parameters": [{"type": "object","name": "details","properties": {"fontId": {"type": "string","description": "The font ID. See the description in <code>getFont</code>."},"script": {"$ref": "ScriptCode","description": "The script code for which the font setting has changed.","optional": true},"genericFamily": {"$ref": "GenericFamily","description": "The generic font family for which the font setting has changed."},"levelOfControl": {"$ref": "LevelOfControl","description": "The level of control this extension has over the setting."}}}]},{"name": "onDefaultFontSizeChanged","description": "Fired when the default font size setting changes.","parameters": [{"type": "object","name": "details","properties": {"pixelSize": {"type": "integer","description": "The font size in pixels."},"levelOfControl": {"$ref": "LevelOfControl","description": "The level of control this extension has over the setting."}}}]},{"name": "onDefaultFixedFontSizeChanged","description": "Fired when the default fixed font size setting changes.","parameters": [{"type": "object","name": "details","properties": {"pixelSize": {"type": "integer","description": "The font size in pixels."},"levelOfControl": {"$ref": "LevelOfControl","description": "The level of control this extension has over the setting."}}}]},{"name": "onMinimumFontSizeChanged","description": "Fired when the minimum font size setting changes.","parameters": [{"type": "object","name": "details","properties": {"pixelSize": {"type": "integer","description": "The font size in pixels."},"levelOfControl": {"$ref": "LevelOfControl","description": "The level of control this extension has over the setting."}}}]}]}
]

2、font_settings.json生成的c++文件:

out\Debug\gen\chrome\common\extensions\api\font_settings.h

out\Debug\gen\chrome\common\extensions\api\font_settings.cc

3、font_settings api接口定义文件:

chrome\browser\extensions\api\font_settings\font_settings_api.h

chrome\browser\extensions\api\font_settings\font_settings_api.cc

namespace content {
class BrowserContext;
}namespace extensions {class FontSettingsEventRouter;// The profile-keyed service that manages the font_settings extension API.
// This is not an EventRouter::Observer (and does not lazily initialize) because
// doing so caused a regression in perf tests. See crbug.com/163466.
class FontSettingsAPI : public BrowserContextKeyedAPI {public:explicit FontSettingsAPI(content::BrowserContext* context);~FontSettingsAPI() override;// BrowserContextKeyedAPI implementation.static BrowserContextKeyedAPIFactory<FontSettingsAPI>* GetFactoryInstance();private:friend class BrowserContextKeyedAPIFactory<FontSettingsAPI>;// BrowserContextKeyedAPI implementation.static const char* service_name() {return "FontSettingsAPI";}static const bool kServiceIsNULLWhileTesting = true;std::unique_ptr<FontSettingsEventRouter> font_settings_event_router_;
};// fontSettings.clearFont API function.
class FontSettingsClearFontFunction : public ExtensionFunction {public:DECLARE_EXTENSION_FUNCTION("fontSettings.clearFont", FONTSETTINGS_CLEARFONT)protected:// RefCounted types have non-public destructors, as with all extension// functions in this file.~FontSettingsClearFontFunction() override {}// ExtensionFunction:ResponseAction Run() override;
};// fontSettings.getFont API function.
class FontSettingsGetFontFunction : public ExtensionFunction {public:DECLARE_EXTENSION_FUNCTION("fontSettings.getFont", FONTSETTINGS_GETFONT)protected:~FontSettingsGetFontFunction() override {}// ExtensionFunction:ResponseAction Run() override;
};// fontSettings.setFont API function.
class FontSettingsSetFontFunction : public ExtensionFunction {public:DECLARE_EXTENSION_FUNCTION("fontSettings.setFont", FONTSETTINGS_SETFONT)protected:~FontSettingsSetFontFunction() override {}// ExtensionFunction:ResponseAction Run() override;
};// fontSettings.getFontList API function.
class FontSettingsGetFontListFunction : public ExtensionFunction {public:DECLARE_EXTENSION_FUNCTION("fontSettings.getFontList",FONTSETTINGS_GETFONTLIST)protected:~FontSettingsGetFontListFunction() override {}// ExtensionFunction:ResponseAction Run() override;private:void FontListHasLoaded(base::Value::List list);ResponseValue CopyFontsToResult(const base::Value::List& fonts);
};// Base class for extension API functions that clear a browser font pref.
class ClearFontPrefExtensionFunction : public ExtensionFunction {protected:~ClearFontPrefExtensionFunction() override {}// ExtensionFunction:ResponseAction Run() override;// Implementations should return the name of the preference to clear, like// "webkit.webprefs.default_font_size".virtual const char* GetPrefName() = 0;
};// Base class for extension API functions that get a browser font pref.
class GetFontPrefExtensionFunction : public ExtensionFunction {protected:~GetFontPrefExtensionFunction() override {}// ExtensionFunction:ResponseAction Run() override;// Implementations should return the name of the preference to get, like// "webkit.webprefs.default_font_size".virtual const char* GetPrefName() = 0;// Implementations should return the key for the value in the extension API,// like "pixelSize".virtual const char* GetKey() = 0;
};// Base class for extension API functions that set a browser font pref.
class SetFontPrefExtensionFunction : public ExtensionFunction {protected:~SetFontPrefExtensionFunction() override {}// ExtensionFunction:ResponseAction Run() override;// Implementations should return the name of the preference to set, like// "webkit.webprefs.default_font_size".virtual const char* GetPrefName() = 0;// Implementations should return the key for the value in the extension API,// like "pixelSize".virtual const char* GetKey() = 0;
};// The following are get/set/clear API functions that act on a browser font
// pref.class FontSettingsClearDefaultFontSizeFunction: public ClearFontPrefExtensionFunction {public:DECLARE_EXTENSION_FUNCTION("fontSettings.clearDefaultFontSize",FONTSETTINGS_CLEARDEFAULTFONTSIZE)protected:~FontSettingsClearDefaultFontSizeFunction() override {}// ClearFontPrefExtensionFunction:const char* GetPrefName() override;
};class FontSettingsGetDefaultFontSizeFunction: public GetFontPrefExtensionFunction {public:DECLARE_EXTENSION_FUNCTION("fontSettings.getDefaultFontSize",FONTSETTINGS_GETDEFAULTFONTSIZE)protected:~FontSettingsGetDefaultFontSizeFunction() override {}// GetFontPrefExtensionFunction:const char* GetPrefName() override;const char* GetKey() override;
};class FontSettingsSetDefaultFontSizeFunction: public SetFontPrefExtensionFunction {public:DECLARE_EXTENSION_FUNCTION("fontSettings.setDefaultFontSize",FONTSETTINGS_SETDEFAULTFONTSIZE)protected:~FontSettingsSetDefaultFontSizeFunction() override {}// SetFontPrefExtensionFunction:const char* GetPrefName() override;const char* GetKey() override;
};class FontSettingsClearDefaultFixedFontSizeFunction: public ClearFontPrefExtensionFunction {public:DECLARE_EXTENSION_FUNCTION("fontSettings.clearDefaultFixedFontSize",FONTSETTINGS_CLEARDEFAULTFIXEDFONTSIZE)protected:~FontSettingsClearDefaultFixedFontSizeFunction() override {}// ClearFontPrefExtensionFunction:const char* GetPrefName() override;
};class FontSettingsGetDefaultFixedFontSizeFunction: public GetFontPrefExtensionFunction {public:DECLARE_EXTENSION_FUNCTION("fontSettings.getDefaultFixedFontSize",FONTSETTINGS_GETDEFAULTFIXEDFONTSIZE)protected:~FontSettingsGetDefaultFixedFontSizeFunction() override {}// GetFontPrefExtensionFunction:const char* GetPrefName() override;const char* GetKey() override;
};class FontSettingsSetDefaultFixedFontSizeFunction: public SetFontPrefExtensionFunction {public:DECLARE_EXTENSION_FUNCTION("fontSettings.setDefaultFixedFontSize",FONTSETTINGS_SETDEFAULTFIXEDFONTSIZE)protected:~FontSettingsSetDefaultFixedFontSizeFunction() override {}// SetFontPrefExtensionFunction:const char* GetPrefName() override;const char* GetKey() override;
};class FontSettingsClearMinimumFontSizeFunction: public ClearFontPrefExtensionFunction {public:DECLARE_EXTENSION_FUNCTION("fontSettings.clearMinimumFontSize",FONTSETTINGS_CLEARMINIMUMFONTSIZE)protected:~FontSettingsClearMinimumFontSizeFunction() override {}// ClearFontPrefExtensionFunction:const char* GetPrefName() override;
};class FontSettingsGetMinimumFontSizeFunction: public GetFontPrefExtensionFunction {public:DECLARE_EXTENSION_FUNCTION("fontSettings.getMinimumFontSize",FONTSETTINGS_GETMINIMUMFONTSIZE)protected:~FontSettingsGetMinimumFontSizeFunction() override {}// GetFontPrefExtensionFunction:const char* GetPrefName() override;const char* GetKey() override;
};class FontSettingsSetMinimumFontSizeFunction: public SetFontPrefExtensionFunction {public:DECLARE_EXTENSION_FUNCTION("fontSettings.setMinimumFontSize",FONTSETTINGS_SETMINIMUMFONTSIZE)protected:~FontSettingsSetMinimumFontSizeFunction() override {}// SetFontPrefExtensionFunction:const char* GetPrefName() override;const char* GetKey() override;
};}  // namespace extensions

三、总结:


http://www.ppmy.cn/news/1543903.html

相关文章

.NET Core WebApi第7讲:项目的发布与部署

一、理解 前端跟后端拿数据&#xff0c;然后在前端页面中展示&#xff0c;就是我们要完成的事情。 把前端跟后端开发好之后&#xff0c;我们需要落地部署&#xff0c;这个时候就需要一个服务器。 服务器就是一台电脑&#xff0c;只要windows里面有一个叫IIS的管理器。 二、项目…

基于 Python 的 Django 框架开发的电影推荐系统

项目简介&#xff1a;本项目是基于 Python 的 Django 框架开发的电影推荐系统&#xff0c;主要功能包括&#xff1a; 电影信息爬取&#xff1a;获取并更新电影数据。数据展示&#xff1a;提供电影数据的列表展示。推荐系统&#xff1a;基于协同过滤算法实现个性化推荐。用户系…

【Matlab】基础操作汇总

一、函数 1、定积分/不定积分函数&#xff1a;int int(f&#xff0c;[r&#xff0c;[x0&#xff0c;[x1]]]) f&#xff1a;所要积分的表达式&#xff1b; r&#xff1a;积分变量 若为定积分&#xff0c;则x0与x1为积分上下限。 2、求解非刚性微分方程&#xff1a;ode45 [t,y…

ctfshow文件包含web78~81

目录 web78 方法一&#xff1a;filter伪协议 方法二&#xff1a;input协议 方法三&#xff1a;data协议 web79 方法一:input协议 方法二&#xff1a;data协议 web80 方法一&#xff1a;input协议 方法二&#xff1a;日志包含getshell web81 web78 if(isset($_GET[file]…

论文阅读:MultiUI 利用网页UI进行丰富文本的视觉理解

《HARNESSING WEBPAGE UIS FOR TEXT-RICH VISUAL UNDERSTANDING》 利用网页UI进行丰富文本的视觉理解 总结 grounding和QA部分的数据集占比较大、同时消融实验显示其作用相对较大&#xff0c;并且grounding部分作用和效果呈现scaling正相关提供了很多web数据处理成多模态训练…

[Control-Chaos] Heart Broken(心脏破裂) IOT逆向+BOF+故事交互解密

Heart Broken https://github.com/MartinxMax/Control-Chaos 故事背景 2025年1月6日 / 下午5:04 [阴天 / 大雨]&#xff1a; [电话响起] 一条消息到达手机… Ethan&#xff1a;John&#xff01;我有麻烦了&#xff01;我有事情要告诉你…我们8点在我们常去的地方见面吧&#…

Flink系列之:学习理解通过状态快照实现容错

Flink系列之&#xff1a;学习理解通过状态快照实现容错 状态后端检查点存储状态快照状态快照如何工作&#xff1f;确保精确一次&#xff08;exactly once&#xff09;端到端精确一次 状态后端 由 Flink 管理的 keyed state 是一种分片的键/值存储&#xff0c;每个 keyed state…

scrapy爬取名人名言

爬取名人名言&#xff1a;http://quotes.toscrape.com/ 1 创建爬虫项目&#xff0c;在终端中输入&#xff1a; scrapy startproject quotes2 创建之后&#xff0c;在spiders文件夹下面创建爬虫文件quotes.py&#xff0c;内容如下&#xff1a; import scrapy from scrapy.spi…