« | September 2025 | » | 日 | 一 | 二 | 三 | 四 | 五 | 六 | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | | | | | |
| 公告 |
 |
Welcome to Lin's Space !
Just enjoy yourself .
Contact me:

jerry585@gmail.com |
Blog信息 |
blog名称:Lin's Space 日志总数:20 评论数量:99 留言数量:0 访问次数:242029 建立时间:2007年5月15日 |

| |
[java]解决jfreechart中文字体模糊问题 软件技术
Great Void 发表于 2007/6/4 23:19:58 |
网上找到这片文章,自己以前也遇到这个问题,但没有去解决
现在正好尝试
JFreeChart Hacking那么为什么要Hacking JFreeChart呢?罪状一:中文Label显示模糊;罪状二:无简体中文LocalizationBundle.properties文件;罪状三:向下兼容性不好,官方说jdk1.2+,其实是jdk1.4+; 兼容问题A:另存菜单输出PNG文件只能运行于jdk1.4+; 兼容问题B:另存菜单不能输出JPEG格式图片; 兼容问题C:jdk1.3-环境下中文ToolTips不能正常显示;如果一定要加一条罪状的话:目前开源免费的chart项目无出其右;十分感谢JFreeChart开发者的辛苦努力!虽然它现在还不完美。Ok,下面为Hacking做一些准备工作...1.下载jfreechart-1.0.0-pre2.zip解压;2.将\解压目录\source\下的源码加入任意project并配置jdk&lib;3.安装一个有批量文件查询/替换功能的工具,比如UtralEdit;Hacking Begin :1.解决中文Label显示模糊问题。 原因分析:JFreeChart默认字体对中文的支持不完善; 解决步骤:搜索\解压目录\source\下含有"new Font("的文件; 发现JFreeChart默认字体为 "foo" "Serif" "Dialog" "SansSerif" "Bitstream Vera Sans" 批量替换他们为任意中文字体(推荐"黑体"); 当然你也可以把字体写入properties文件, 但这里介绍的是最简单的方法; 然后重新编译你修改过的文件,Ok,搞定!2.无简体中文LocalizationBundle.properties文件 org\jfree\chart\LocalizationBundle.properties 主要用来显示右键功能菜单的文字,下面我们来汉化: 注意:LocalizationBundle.properties的编码不是Unicode, 简体中文要用GBK编码。 获得GBK编码的方法是: cd ***\j2sdk1.*.*\bin native2ascii -encoding GBK 1.txt 2.txt 注:1.txt放中文文本,2.txt输出GBK编码。 # org.jfree.chart.ChartPanel ResourceBundle properties file## Changes (from 31-Aug-2003)# --------------------------# 31-Aug-2003 : Initial version (AL);# 16-May-2005 : Add GBK version (FinalBone);# 16-May-2005 : Add JPG_Image_Files (FinalBone);#---------------EN---------------##Auto_Range=Auto Range#All_Axes=Both Axes#Chart_Properties=Chart Properties#Copy=Copy#Print...=Print...#Save_as...=Save as...#Properties...=Properties...#PNG_Image_Files=PNG Image Files#JPG_Image_Files=JPG Image Files#Domain_Axis=Domain Axis#Range_Axis=Range Axis#Zoom_In=Zoom In#Zoom_Out=Zoom Out#---------------GBK---------------#Auto_Range=\u81ea\u52a8\u8c03\u6574All_Axes=\u6240\u6709\u5750\u6807\u8f74Chart_Properties=\u56fe\u8868\u5c5e\u6027Copy=\u590d\u5236Print...=\u6253\u5370...Save_as...=\u53e6\u5b58\u4e3a...Properties...=\u5c5e\u6027...PNG_Image_Files=PNG\u56fe\u50cfJPG_Image_Files=JPG\u56fe\u50cfDomain_Axis=\u57df\u5750\u6807\u8f74Range_Axis=\u503c\u5750\u6807\u8f74Zoom_In=\u653e\u5927Zoom_Out=\u7f29\u5c0f另外还有两个同名文件,希望大家有时间也汉化一下。org\jfree\chart\ui\LocalizationBundle.propertiesorg\jfree\chart\plot\LocalizationBundle.properties3.兼容性问题 a.PNG输出问题 b.无JPEG输出菜单 原因分析:javax.imageio.ImageIO这个类只有jdk1.4+才有。 解决步骤:1.打开org.jfree.chart.ChartPanel, 查看doSaveAs()方法,了解其结构; 2.改写doSaveAs()方法,重新编译; 3.如果运行环境是jdk1.3- 打开org.jfree.chart.encoders.SunPNGEncoderAdapter 注释掉javax.imageio.ImageIO,重新编译。 /** * Updated by FinalBone 2005-5-16 PNG --> JPEG * * Opens a file chooser and gives the user an opportunity * to save the chart in JPEG format. * * @throws IOException if there is an I/O error. */ public void doSaveAs() throws IOException { JFileChooser fileChooser = new JFileChooser(); ExtensionFileFilter filter = new ExtensionFileFilter( localizationResources.getString("JPG_Image_Files"), ".jpg" ); fileChooser.addChoosableFileFilter(filter); int option = fileChooser.showSaveDialog(this); if (option == JFileChooser.APPROVE_OPTION) { String filename = fileChooser.getSelectedFile().getPath(); if (isEnforceFileExtensions()) { if (!filename.endsWith(".jpg")) { filename = filename + ".jpg"; } } ChartUtilities.saveChartAsJPEG( new File(filename), this.chart, getWidth(), getHeight() ); } } c.中文ToolTips不能正常显示(显示为小方框) 原因分析:相关字体找不到。 解决步骤:1.打开org.jfree.chart.block.LabelBlock 查看其构造函数public LabelBlock(String label); 2.修改构造函数的字体定义,重新编译。 /** * Creates a new label block. * * @param label the label. */ public LabelBlock(String label) { /** * Updated by FinalBone 2005-05-16 * "Bitstream Vera Sans" --> "黑体" * For Chinese-Simplified ToolTips * JDK 1.3- Environment */ this(label, new Font("黑体", Font.PLAIN, 11)); }Hacking 结束,这时的 JFreeChart 才是真正jdk1.2+兼容,完美支持中文。希望下一版本的 JFreeChart 的字体定义写入properties文件,并且不同路经下的properties文件最好不要重名。 |
|
回复:解决jfreechart中文字体模糊问题 软件技术
HELLO,WORLD(游客)发表评论于2008/6/27 18:20:31 |
c.中文ToolTips不能正常显示(显示为小方框)
原因分析:相关字体找不到。
这个问题,即使改为黑体也会出现找不到字体的问题.有没有更好的办法? |
|
回复:解决jfreechart中文字体模糊问题 软件技术
HELLO,WORLD(游客)发表评论于2008/6/27 18:20:21 |
c.中文ToolTips不能正常显示(显示为小方框)
原因分析:相关字体找不到。
这个问题,即使改为黑体也会出现找不到字体的问题.有没有更好的办法? |
|
» 1 »
|