Linux環境下"Font font = new Font("黑體", Font.BOLD, 18)"[BufferedImage~Graphics~drawString]中文亂碼

Linux環境下"Font font = new Font("黑體", Font.BOLD, 18)"[BufferedImage~Graphics~drawString]中文亂碼,windows下不會亂碼,但在linux下nginx和tomcat部署後出現亂碼、方框、問號等等,不能認清楚!!!


先說說系統:

Microsoft Windows [版本 10.0.10586]
(c) 2015 Microsoft Corporation。保留所有權利。

----------------------------------------------------------------------

CentOS release 6.5 (Final)
Kernel \r on an \m

----------------------------------------------------tomcat 8.0.28

好了,說怎麼解決的吧步驟:

1:查看CentOS下”/usr/share/fonts“目錄,查看新的系統則爲空目錄;無目錄可手動創建fonts。

2:打開”C:\Windows\WinSxS\amd64_microsoft-windows-font-truetype-simsunb_31bf3856ad364e35_10.0.10586.0_none_1d80224ec6470747“等目錄下,找到自己需要的字體的目錄,那個文件夾也是見名知意了;

3:之後把挑選的字體,可以建個文件夾,一次傳到Xftp等上傳到服務器的”/usr/share/fonts“的目錄下;

4:進入"cd /usr/share/fonts/windowsFonts"文件夾,注:windowsFonts爲我挑選字體目錄:

注:如果沒有fonts目錄可以手動創建,“windowsFonts”爲自定義文件夾名稱。

有楷體,黑體,簡宋體,微軟雅黑等,最後附上!

5:最後在此目錄下,執行"#fc-cache -fv",掃描字體目錄並生成字體信息的緩存,然後應用程序就可以"立即"使用這些新安裝的字體;

6:最終還是要重啓web sever,例如:tomcat,字體生效!

注:在ubuntu中需要安裝:apt-get install fontconfig,侯執行以下命令!

執行命令 fc-cache -fv

[root@timespacexstar windowsFonts]# fc-cache -fv
/usr/share/fonts: caching, new cache contents: 0 fonts, 1 dirs
/usr/share/fonts/windowsFonts: caching, new cache contents: 8 fonts, 0 dirs
/usr/share/X11/fonts/Type1: skipping, no such directory
/usr/share/X11/fonts/TTF: skipping, no such directory
/usr/local/share/fonts: skipping, no such directory
/root/.fonts: skipping, no such directory
/var/cache/fontconfig: cleaning cache directory
/root/.fontconfig: not cleaning non-existent cache directory
fc-cache: succeeded

root@iZ234iuy39uZ:/usr/share/fonts/windowsFonts# fc-cache -fv
/usr/share/fonts: caching, new cache contents: 0 fonts, 2 dirs
/usr/share/fonts/truetype: caching, new cache contents: 0 fonts, 1 dirs
/usr/share/fonts/truetype/dejavu: caching, new cache contents: 6 fonts, 0 dirs
/usr/share/fonts/windowsFonts: caching, new cache contents: 8 fonts, 0 dirs
/usr/local/share/fonts: caching, new cache contents: 0 fonts, 0 dirs
/root/.local/share/fonts: skipping, no such directory
/root/.fonts: skipping, no such directory
/usr/share/fonts: caching, new cache contents: 0 fonts, 2 dirs
/usr/local/share/fonts: caching, new cache contents: 0 fonts, 0 dirs
/root/.local/share/fonts: skipping, no such directory
/root/.fonts: skipping, no such directory
/var/cache/fontconfig: cleaning cache directory
/root/.cache/fontconfig: not cleaning non-existent cache directory
/root/.fontconfig: not cleaning non-existent cache directory
fc-cache: succeeded

包涵字體:

[root@timespacexstar windowsFonts]# ll
total 77796
-rw-r--r-- 1 root root 16299048 Jan 31 17:43 msyhbd.ttc
-rw-r--r-- 1 root root 23608184 Jan 31 17:43 msyh.ttc
-rw-r--r-- 1 root root  9751720 Jan 31 17:45 simhei.ttf
-rw-r--r-- 1 root root 11785184 Jan 31 17:46 simkai.ttf
-rw-r--r-- 1 root root 18209004 Jan 31 17:47 simsun.ttc

windowsFonts字體

發佈了155 篇原創文章 · 獲贊 872 · 訪問量 136萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章