一叶梧桐 2011-09-24
做项目中用到了jfreechart用来显示统计课程排行的结果,但是在xp下显示正常,但是在linux下显示中文乱码类似口口口之类的
在网上搜了些,一开始由于对linux不太熟悉,也就没有解决问题,现在学习了一段fedora后,重新解决了这个问题
首先将xp下的simsun.ttc字体拷贝到linux下,放在linux的%JAVA_HOME%/jre/lib/fonts目录下然后修改目录下的fonts.dir文件将首行的数字+1比如122变为123,然后在最后一行加上:
simsun.ttc-SungtiLGB-medium-r-normal--0-0-0-0-c-0-gb2312.1988-0
然后保存,如果是只读文件的话要强制保存:w!
最后在含有jfreechat的程序中设置如下:
CategoryPlotplot=this.chart.getCategoryPlot()
plot.setForegroundAlpha(0.6F);
chart.setTitle(newTextTitle(chart.getTitle().getText(),newFont("宋体",1,13)));
CategoryAxisdomainAxis=plot.getDomainAxis();
domainAxis.setLabelFont(newFont("宋体",1,12));
domainAxis.setTickLabelFont(newFont("宋体",0,10));
NumberAxisnumberaxis=(NumberAxis)plot.getRangeAxis();
numberaxis.setTickLabelFont(newFont("宋体",0,12));
numberaxis.setLabelFont(newFont("宋体",0,12));
domainAxis.setLowerMargin(0.01D);
domainAxis.setUpperMargin(0.01D);
示例2
1.在/usr/share/fonts/zh_CN/TrueType下
添加文件C:\WINDOWS\Fonts\simsun.ttc
2.在jdk/jre/lib下
添加font.properties.zh.Redhat1.0
3.若用tomcat
在tomcat/bin/setclasspath.sh中增加
CATALINA_OPTS="-Djava.awt.headless=true"
exportCATALINA_OPTS
font.properties.zh.Redhat1.0文件如下:
#@(#)font.properties.ja.linux1.702/03/07
#
#Copyright2002SunMicrosystems,Inc.Allrightsreserved.
#
#ComponentFontMappingsForRedhatLinux8.0/zh_CN
#
serif.0=-b&h-lucidabright-medium-r-normal--*-%d-*-*-p-*-iso8859-1
serif.1=-misc-simsun18030-medium-r-normal--*-%d-*-*-c-*-iso10646-1
serif.italic.0=-b&h-lucidabright-medium-i-normal--*-%d-*-*-p-*-iso8859-1
serif.italic.1=-misc-simsun18030-medium-r-normal--*-%d-*-*-c-*-iso10646-1
serif.bold.0=-b&h-lucidabright-demibold-r-normal--*-%d-*-*-p-*-iso8859-1
serif.bold.1=-misc-simsun18030-medium-r-normal--*-%d-*-*-c-*-iso10646-1
serif.bolditalic.0=-b&h-lucidabright-demibold-i-normal--*-%d-*-*-p-*-iso8859-1
serif.bolditalic.1=-misc-simsun18030-medium-r-normal--*-%d-*-*-c-*-iso10646-1
sansserif.0=-b&h-lucidasans-medium-r-normal-sans-*-%d-*-*-p-*-iso8859-1
sansserif.1=-misc-simsun18030-medium-r-normal--*-%d-*-*-c-*-iso10646-1
sansserif.italic.0=-b&h-lucidasans-medium-i-normal-sans-*-%d-*-*-p-*-iso8859-1
sansserif.italic.1=-misc-simsun18030-medium-r-normal--*-%d-*-*-c-*-iso10646-1
sansserif.bold.0=-b&h-lucidasans-bold-r-normal-sans-*-%d-*-*-p-*-iso8859-1
sansserif.bold.1=-misc-simsun18030-medium-r-normal--*-%d-*-*-c-*-iso10646-1
sansserif.bolditalic.0=-b&h-lucidasans-bold-i-normal-sans-*-%d-*-*-p-*-iso8859-1
sansserif.bolditalic.1=-misc-simsun18030-medium-r-normal--*-%d-*-*-c-*-iso10646-1
monospaced.0=-b&h-lucidatypewriter-medium-r-normal-sans-*-%d-*-*-m-*-iso8859-1
monospaced.1=-misc-simsun18030-medium-r-normal--*-%d-*-*-c-*-iso10646-1
monospaced.italic.0=-b&h-lucidatypewriter-medium-i-normal-sans-*-%d-*-*-m-*-iso8859-1
monospaced.italic.1=-misc-simsun18030-medium-r-normal--*-%d-*-*-c-*-iso10646-1
monospaced.bold.0=-b&h-lucidatypewriter-bold-r-normal-sans-*-%d-*-*-m-*-iso8859-1
monospaced.bold.1=-misc-simsun18030-medium-r-normal--*-%d-*-*-c-*-iso10646-1
monospaced.bolditalic.0=-b&h-lucidatypewriter-bold-i-normal-sans-*-%d-*-*-m-*-iso8859-1
monospaced.bolditalic.1=-misc-simsun18030-medium-r-normal--*-%d-*-*-c-*-iso10646-1
dialog.0=-b&h-lucidasans-medium-r-normal-sans-*-%d-*-*-p-*-iso8859-1
dialog.1=-misc-simsun18030-medium-r-normal--*-%d-*-*-c-*-iso10646-1
dialog.italic.0=-b&h-lucidasans-medium-i-normal-sans-*-%d-*-*-p-*-iso8859-1
dialog.italic.1=-misc-simsun18030-medium-r-normal--*-%d-*-*-c-*-iso10646-1
dialog.bold.0=-b&h-lucidasans-bold-r-normal-sans-*-%d-*-*-p-*-iso8859-1
dialog.bold.1=-misc-simsun18030-medium-r-normal--*-%d-*-*-c-*-iso10646-1
dialog.bolditalic.0=-b&h-lucidasans-bold-i-normal-sans-*-%d-*-*-p-*-iso8859-1
dialog.bolditalic.1=-misc-simsun18030-medium-r-normal--*-%d-*-*-c-*-iso10646-1
dialoginput.0=-b&h-lucidatypewriter-medium-r-normal-sans-*-%d-*-*-m-*-iso8859-1
dialoginput.1=-misc-simsun18030-medium-r-normal--*-%d-*-*-c-*-iso10646-1
dialoginput.italic.0=-b&h-lucidatypewriter-medium-i-normal-sans-*-%d-*-*-m-*-iso8859-1
dialoginput.italic.1=-misc-simsun18030-medium-r-normal--*-%d-*-*-c-*-iso10646-1
dialoginput.bold.0=-b&h-lucidatypewriter-bold-r-normal-sans-*-%d-*-*-m-*-iso8859-1
dialoginput.bold.1=-misc-simsun18030-medium-r-normal--*-%d-*-*-c-*-iso10646-1
dialoginput.bolditalic.0=-b&h-lucidatypewriter-bold-i-normal-sans-*-%d-*-*-m-*-iso8859-1
dialoginput.bolditalic.1=-misc-simsun18030-medium-r-normal--*-%d-*-*-c-*-iso10646-1
#MissingGlyphCharacter
#
default.char=274f
#ComponentFontCharacterEncodings
#
fontcharset.serif.0=sun.io.CharToByteISO8859_1
fontcharset.serif.1=sun.io.CharToByteUnicodeBigUnmarked
fontcharset.sansserif.0=sun.io.CharToByteISO8859_1
fontcharset.sansserif.1=sun.io.CharToByteUnicodeBigUnmarked
fontcharset.monospaced.0=sun.io.CharToByteISO8859_1
fontcharset.monospaced.1=sun.io.CharToByteUnicodeBigUnmarked
fontcharset.dialog.0=sun.io.CharToByteISO8859_1
fontcharset.dialog.1=sun.io.CharToByteUnicodeBigUnmarked
fontcharset.dialoginput.0=sun.io.CharToByteISO8859_1
fontcharset.dialoginput.1=sun.io.CharToByteUnicodeBigUnmarked
#ExclusionRanges
#
#XFontSetInformation
#
fontset.serif.plain=
-b&h-lucidabright-medium-r-normal--*-%d-*-*-p-*-iso8859-1,
-isas-songti-medium-r-normal--*-%d-*-*-c-*-gb2312.1980-0
fontset.serif.italic=
-b&h-lucidabright-medium-i-normal--*-%d-*-*-p-*-iso8859-1,
-isas-songti-medium-r-normal--*-%d-*-*-c-*-gb2312.1980-0
fontset.serif.bold=
-b&h-lucidabright-demibold-r-normal--*-%d-*-*-p-*-iso8859-1,
-isas-songti-medium-r-normal--*-%d-*-*-c-*-gb2312.1980-0
fontset.serif.bolditalic=
-b&h-lucidabright-demibold-i-normal--*-%d-*-*-p-*-iso8859-1,
-isas-songti-medium-r-normal--*-%d-*-*-c-*-gb2312.1980-0
fontset.sansserif.plain=
-b&h-lucida-medium-r-normal-sans-*-%d-*-*-p-*-iso8859-1,
-isas-songti-medium-r-normal--*-%d-*-*-c-*-gb2312.1980-0
fontset.sansserif.italic=
-b&h-lucida-medium-i-normal-sans-*-%d-*-*-p-*-iso8859-1,
-isas-songti-medium-r-normal--*-%d-*-*-c-*-gb2312.1980-0
fontset.sansserif.bold=
-b&h-lucida-bold-r-normal-sans-*-%d-*-*-p-*-iso8859-1,
-isas-songti-medium-r-normal--*-%d-*-*-c-*-gb2312.1980-0
fontset.sansserif.bolditalic=
-b&h-lucida-bold-i-normal-sans-*-%d-*-*-p-*-iso8859-1,
-isas-songti-medium-r-normal--*-%d-*-*-c-*-gb2312.1980-0
fontset.monospaced.plain=
-b&h-lucidatypewriter-medium-r-normal-sans-*-%d-*-*-m-*-iso8859-1,
-isas-songti-medium-r-normal--*-%d-*-*-c-*-gb2312.1980-0
fontset.monospaced.italic=
-b&h-lucidatypewriter-medium-r-normal-sans-*-%d-*-*-m-*-iso8859-1,
-isas-songti-medium-r-normal--*-%d-*-*-c-*-gb2312.1980-0
fontset.monospaced.bold=
-b&h-lucidatypewriter-bold-r-normal-sans-*-%d-*-*-m-*-iso8859-1,
-isas-songti-medium-r-normal--*-%d-*-*-c-*-gb2312.1980-0
fontset.monospaced.bolditalic=
-b&h-lucidatypewriter-bold-r-normal-sans-*-%d-*-*-m-*-iso8859-1,
-isas-songti-medium-r-normal--*-%d-*-*-c-*-gb2312.1980-0
fontset.dialog.italic=
-b&h-lucida-medium-i-normal-sans-*-%d-*-*-p-*-iso8859-1,
-isas-songti-medium-r-normal--*-%d-*-*-c-*-gb2312.1980-0
fontset.dialog.bold=
-b&h-lucida-bold-r-normal-sans-*-%d-*-*-p-*-iso8859-1,
-isas-songti-medium-r-normal--*-%d-*-*-c-*-gb2312.1980-0
fontset.dialog.bolditalic=
-b&h-lucida-bold-i-normal-sans-*-%d-*-*-p-*-iso8859-1,
-isas-songti-medium-r-normal--*-%d-*-*-c-*-gb2312.1980-0
fontset.dialog.plain=
-b&h-lucida-medium-r-normal-sans-*-%d-*-*-p-*-iso8859-1,
-isas-songti-medium-r-normal--*-%d-*-*-c-*-gb2312.1980-0
fontset.dialoginput.italic=
-b&h-lucidatypewriter-medium-r-normal-sans-*-%d-*-*-m-*-iso8859-1,
-isas-songti-medium-r-normal--*-%d-*-*-c-*-gb2312.1980-0
fontset.dialoginput.bold=
-b&h-lucidatypewriter-bold-r-normal-sans-*-%d-*-*-m-*-iso8859-1,
-isas-songti-medium-r-normal--*-%d-*-*-c-*-gb2312.1980-0
fontset.dialoginput.bolditalic=
-b&h-lucidatypewriter-bold-r-normal-sans-*-%d-*-*-m-*-iso8859-1,
-isas-songti-medium-r-normal--*-%d-*-*-c-*-gb2312.1980-0
fontset.dialoginput.plain=
-b&h-lucidatypewriter-medium-r-normal-sans-*-%d-*-*-m-*-iso8859-1,
-isas-songti-medium-r-normal--*-%d-*-*-c-*-gb2312.1980-0
fontset.default=
-b&h-lucida-medium-r-normal-sans-*-%d-*-*-p-*-iso8859-1,
-isas-songti-medium-r-normal--*-%d-*-*-c-*-gb2312.1980-0
filename.-misc-simsun18030-medium-r-normal--*-%d-*-*-c-*-iso10646-1=/usr/share/fonts/zh_CN/TrueType/simsun.ttc