項目中包含了一項生成JPG圖片的功能,該功能需要使用JAVA的Graphics2D動態生成圖片中的文字,原來在Windows平台中沒有發現問題,但是遷移至Linux平台后發現生成的中文變成了亂碼。
百度發現是因為Linux下沒有相應的字體引起的,解決辦法如下:
1、找到Windows平台下的字體文件;
常規路徑為:C:\Windows\Fonts
宋體文件為:simsun.ttc
楷體文件為:simkai.ttf
2、找到Linux平台下JDK的字體目錄;
本系統路徑為:/opt/IBM/WebSphere/AppServer/java_1.7_64/jre/lib/fonts
該路徑下存儲了默認的字體。
[root@appsrv01 fonts]# pwd /opt/IBM/WebSphere/AppServer/java_1.7_64/jre/lib/fonts [root@appsrv01 fonts]# [root@appsrv01 fonts]# ll total 31460 -rwxr-xr-x 1 root root 4041 Mar 24 2014 fonts.dir -rwxr-xr-x 1 root root 75144 Mar 24 2014 LucidaBrightDemiBold.ttf -rwxr-xr-x 1 root root 75124 Mar 24 2014 LucidaBrightDemiItalic.ttf -rwxr-xr-x 1 root root 80856 Mar 24 2014 LucidaBrightItalic.ttf -rwxr-xr-x 1 root root 344908 Mar 24 2014 LucidaBrightRegular.ttf -rwxr-xr-x 1 root root 317896 Mar 24 2014 LucidaSansDemiBold.ttf -rwxr-xr-x 1 root root 698236 Mar 24 2014 LucidaSansRegular.ttf -rwxr-xr-x 1 root root 234068 Mar 24 2014 LucidaTypewriterBold.ttf -rwxr-xr-x 1 root root 242700 Mar 24 2014 LucidaTypewriterRegular.ttf
3、將需要的字體拷貝至此目錄即可。
[root@appsrv01 fonts]# ll total 31460 -rwxr-xr-x 1 root root 4041 Mar 24 2014 fonts.dir -rwxr-xr-x 1 root root 75144 Mar 24 2014 LucidaBrightDemiBold.ttf -rwxr-xr-x 1 root root 75124 Mar 24 2014 LucidaBrightDemiItalic.ttf -rwxr-xr-x 1 root root 80856 Mar 24 2014 LucidaBrightItalic.ttf -rwxr-xr-x 1 root root 344908 Mar 24 2014 LucidaBrightRegular.ttf -rwxr-xr-x 1 root root 317896 Mar 24 2014 LucidaSansDemiBold.ttf -rwxr-xr-x 1 root root 698236 Mar 24 2014 LucidaSansRegular.ttf -rwxr-xr-x 1 root root 234068 Mar 24 2014 LucidaTypewriterBold.ttf -rwxr-xr-x 1 root root 242700 Mar 24 2014 LucidaTypewriterRegular.ttf -rwxrwxr-x 1 root root 11785184 Nov 29 03:12 simkai.ttf -rw-r--r-- 1 root root 18259888 Nov 29 03:15 simsun.ttc
4、重啟應用程序服務器后驗證功能,發現已恢復正常。
