发表于:2010-06-10 | 3 个回复
WordEditor2 中编辑器的初期字体被配置到 config 目录下的配置文件中,默认为“宋体”文字大小默认为“14”。系统初期化时从配置文件中读取并以 Style 的方式设置为编辑器的默认值。WordEditor2 的编辑器是继承自 JTextPane ,所以它拥有解析 html 代码的能力。为了能够设置编辑器的全局字体,我在这里的处理是为编辑器追加 body 的 css 配置。
StringBuffer style = new StringBuffer(); style.append("body {"); style.append("font-size:"); style.append(wep.get("editor.font.size")); style.append(";font-family:"); style.append(wep.get("editor.font.family")); style.append(";margin:"); style.append(wep.get("editor.margin")); style.append(";background:"); style.append(wep.get("editor.background")); style.append(";"); this.doc.getStyleSheet().addRule(style.toString());