首先,此解决方案假定您使用的是 CKEditor 的 Google Web Font 插件:http://ckeditor.com/addon/ckeditor-gwf-plugin
您可以订阅 CKEditor 更改,然后为 google 字体系列解析生成的 html。这是使用插件页面中的基本示例的示例:
var editor = CKEDITOR.replace( 'editor1',{
toolbar: [
['Font', 'FontSize']
],
startupFocus: true,
fillEmptyBlocks: false,
autoParagraph: false,
resize_enabled: false
});
editor.on('change', function(event){
console.log(event.editor.getData());
});
对于一个示例输入,我为不同的文本选择了两种网络字体,它将以下内容输出为 html 字符串:
<span style="font-family:actor;">Hello world</span> <span style="font-family:allerta stencil;">It's nice to meet you. </span>
<link href="https://fonts.googleapis.com/css?family=Actor" rel="stylesheet" type="text/css" />
<link href="https://fonts.googleapis.com/css?family=Allerta Stencil" rel="stylesheet" type="text/css" />
值得注意的是,数据似乎已经包含到正在使用的字体系列的必要链接但是,可以很容易地解析该 html 字符串以获取 ['Actor', 'Allerta Stencil'] 以保持和动态加载通过 Web Font Loader 加载首页。这是一个从输出字符串返回字体系列名称数组的小提琴:https://jsfiddle.net/v4tnynu2/
查看 Google 和 Typekit 提供的 Web Font Loader:https://developers.google.com/fonts/docs/webfont_loader
它允许您在页面加载后动态加载网页字体:
WebFont.load({
google: {
families: ['Actor', 'Allerta Stencil']
}
});