什么是GRAPE

WordEditor2 的全局字体的实现方法

10-06-10 | 3 Comments |

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());


按照以上方法设置后,编辑器的 html 代码中就会生成 body 的 css 配置。这样一来,就达到了我们改变编辑器全局字体的目的。

body { margin-right: 10px; font-family: 宋体; background-attachment: scroll; margin-bottom: 15px; background-color: #CCC8C8; margin-top: 5px; margin-left: 10px; font-size: 14; background-repeat: repeat }

五冠 Nokia/诺基亚 5230 5230XM 送证书V20版 内有港行 销数千台
1000.0元
批发 雷朋3025镜面反光太阳镜 太阳眼镜 19.9/副 顶级质量
19.9元
促销笔记本电脑 13.3英寸超薄N450无线网卡视频
1999.0元

  1. 其实默认字体就挺好的。

  2. 这个功能主要是为了实现编辑器的全局字体变换。

  3. 学习一下~~

留下您的脚印


«
»