Ckeditor 自定义字体编辑器
我正在尝试添加自定义字体,但无法添加。我得到以下代码错误,字体名称是添加在下拉列表中,但它没有改变 我的代码是 config.js:Ckeditor 自定义字体编辑器,ckeditor,Ckeditor,我正在尝试添加自定义字体,但无法添加。我得到以下代码错误,字体名称是添加在下拉列表中,但它没有改变 我的代码是 config.js: CKEDITOR.editorConfig = function( config ) { config.contentsCss = 'fonts.css'; config.font_names = 'Dekers/dekers_true' + config.font_names; } fonts.css: @font-face { font-family:
CKEDITOR.editorConfig = function( config )
{
config.contentsCss = 'fonts.css';
config.font_names = 'Dekers/dekers_true' + config.font_names;
}
fonts.css:
@font-face {
font-family: "dekers_true", serif;
src: url(fonts/Dekers_light.eot ); /* IE */
src: local("Dekers"), url("fonts/Dekers_light.ttf") format("truetype"); /*non-IE*/
}
自定义CSS文件必须包含CKEditor主体的基本样式。CKEditor仅使用此CSS文件加载iframe
@font-face {
font-family: "dekers_true"; /* font name for the feature use*/
src: url(fonts/Dekers_light.eot ); /* IE */
src: local("Dekers"), url("fonts/Dekers_light.ttf") format("truetype"); /*non-IE*/
}
body {
font: normal 13px/1.2em dekers_true, serif;
color: #333;
}
p {
font: normal 13px/1.2em dekers_true, serif;
margin-top: 0;
margin-bottom: 0.5em
}
...
然后将字体声明也添加到主站点的CSS文件中
Upd:替代型。
您可以声明您的自定义样式,例如
config.stylesSet = [
{ name : 'Pretty font face', element : 'span', attributes : { 'class' : 'pretty_face' } },
...
];
因此,将应用class.pretty_face
,然后您可以根据自己的意愿设置样式。如果要在rte中立即预览,还需要在contentsCSS文件中设置此类样式。或在config.js中
config.font_names = 'Arial/Arial, Helvetica, sans-serif;' +
'Comic Sans MS/Comic Sans MS, cursive;' +
'Courier New/Courier New, Courier, monospace;' +
'Georgia/Georgia, serif;' +
'Lucida Sans Unicode/Lucida Sans Unicode, Lucida Grande, sans-serif;' +
'Tahoma/Tahoma, Geneva, sans-serif;' +
'Times New Roman/Times New Roman, Times, serif;' +
'Trebuchet MS/Trebuchet MS, Helvetica, sans-serif;' +
'Verdana/Verdana, Geneva, sans-serif;' +
**'Dekers/dekers_true';**
然后是你的CSS。
上面将其放置在样式下拉列表中,而不是字体中。如果您使用的是托管字体,并且有一个相对简单的用例,您可以直接将样式表添加到
config.contentCss
:
config.contentsCss=['/css/mysitestyles.css','https://fonts.googleapis.com/css?family=Roboto']
其中第一个文件定义您的样式(例如,.title{font-family:'Roboto',sans-serif;
),第二个文件是包含字体定义的远程样式表
如果您已在config.styleSet
中定义了可选样式,则自定义字体现在应显示在下拉菜单和编辑器中:
config.styleSet=[{'name':'Title','element':'h1','attributes':{'class':'Title'}]
我使用CKEditor Django插件对此进行了测试,该插件的语法与上面的略有不同,但我看不出它不翻译的原因。非常感谢您的快速回复。在我声明自定义样式的地方,我尝试了CKEditor\plugins\styles\styles\default.js,但没有在下拉列表中获得样式,您能给出小的cod吗例如,只需在js中添加一个字体和大小。请是ckeditor的新手。遇到bug…帮助我请阅读有关自定义样式的更多信息注意:不要将核心代码更改为
ckeditor\plugins\styles\styles\default.js
,ckeditor配置非常灵活。同样,ckeditor也有,因此您可以在编辑器加载后调用回调函数。Awesome!这对我很有用。我在我的主css
和ckeditor内容中添加了css
我字体的字体规则,它就像一个符咒!为什么需要添加Dekers/呢,有必要写src:local(“Dekers”)?