Linux 安装 windows 字体
2015-11-10 14:35
453 查看
做了一个项目,其中有一个图片合成的步骤,合成的过程中在图片上添加文字用到 微软雅黑 字体
在windows 下开发测试肯定是没有问题的,但把项目部署到Linux服务器上时,就会发现合成的图片上的汉字都是一个长方形乱码。
想了一下,应该是Linux上默认是没有Microsoft 的字体造成的,所以要把windows上的字库放到Linux上。
可以执行 fc-list :lang=zh-cn 命令,查看Linux下是否包含要使用的中文字体。
1. 复制字体
windows 的字体在 C:\Windows\Fonts 目录下
Linux 的字体一般在 /usr/share/fonts/ 目录下
可在/usr/share/fonts/ 下建立一个 winfonts 目录放要复制的windows 字体。
2. 导入字体
复制完成后,命令行下依次执行下面三条命令(root用户无须加sudo):
有可能在执行过程中提示 mkfontscale 没有安装,需要先安装 xfonts-utils 再使用,
下面是ubuntu的安装,导入成功后会提示fc-cache: succeeded
这时再执行fc-list :lang=zh-cn 就可以看到已导入的字体了。
已经部署的项目需要重新启动才生效,个人是部署在tomcat上,重启tomcat,再操作就不会出现乱码了。
Good luck!
Font f = new Font("Microsoft Yahei UI",Font.TRUETYPE_FONT ,20);
在windows 下开发测试肯定是没有问题的,但把项目部署到Linux服务器上时,就会发现合成的图片上的汉字都是一个长方形乱码。
想了一下,应该是Linux上默认是没有Microsoft 的字体造成的,所以要把windows上的字库放到Linux上。
可以执行 fc-list :lang=zh-cn 命令,查看Linux下是否包含要使用的中文字体。
fc-list :lang=zh-cn
1. 复制字体
windows 的字体在 C:\Windows\Fonts 目录下
Linux 的字体一般在 /usr/share/fonts/ 目录下
可在/usr/share/fonts/ 下建立一个 winfonts 目录放要复制的windows 字体。
2. 导入字体
复制完成后,命令行下依次执行下面三条命令(root用户无须加sudo):
sudo mkfontscale sudo mkfontdir sudo fc-cache -fv
有可能在执行过程中提示 mkfontscale 没有安装,需要先安装 xfonts-utils 再使用,
下面是ubuntu的安装,导入成功后会提示fc-cache: succeeded
这时再执行fc-list :lang=zh-cn 就可以看到已导入的字体了。
已经部署的项目需要重新启动才生效,个人是部署在tomcat上,重启tomcat,再操作就不会出现乱码了。
Good luck!
root@sdfsfsfsfs:/usr/share/fonts/windfonts# mkfontscale The program 'mkfontscale' is currently not installed. You can install it by typing: apt-get install xfonts-utils root@sdfsfsfsfs:/usr/share/fonts/windfonts# apt-get install xfonts-utils Reading package lists... Done Building dependency tree Reading state information... Done The following extra packages will be installed: libfontenc1 libxfont1 x11-common xfonts-encodings The following NEW packages will be installed: libfontenc1 libxfont1 x11-common xfonts-encodings xfonts-utils 0 upgraded, 5 newly installed, 0 to remove and 209 not upgraded. Need to get 881 kB of archives. After this operation, 2,136 kB of additional disk space will be used. Do you want to continue [Y/n]? Y Get:1 http://mirrors.aliyun.com/ubuntu/ precise/main libfontenc1 amd64 1:1.1.0-1 [15.4 kB] Get:2 http://mirrors.aliyun.com/ubuntu/ precise-security/main libxfont1 amd64 1:1.4.4-1ubuntu0.3 [134 kB] Get:3 http://mirrors.aliyun.com/ubuntu/ precise-updates/main x11-common all 1:7.6+12ubuntu2 [52.0 kB] Get:4 http://mirrors.aliyun.com/ubuntu/ precise/main xfonts-encodings all 1:1.0.4-1ubuntu1 [583 kB] Get:5 http://mirrors.aliyun.com/ubuntu/ precise/main xfonts-utils amd64 1:7.6+1 [96.4 kB] Fetched 881 kB in 0s (2,185 kB/s) Preconfiguring packages ... Selecting previously unselected package libfontenc1. (Reading database ... 54268 files and directories currently installed.) Unpacking libfontenc1 (from .../libfontenc1_1%3a1.1.0-1_amd64.deb) ... Selecting previously unselected package libxfont1. Unpacking libxfont1 (from .../libxfont1_1%3a1.4.4-1ubuntu0.3_amd64.deb) ... Selecting previously unselected package x11-common. Unpacking x11-common (from .../x11-common_1%3a7.6+12ubuntu2_all.deb) ... Selecting previously unselected package xfonts-encodings. Unpacking xfonts-encodings (from .../xfonts-encodings_1%3a1.0.4-1ubuntu1_all.deb) ... Selecting previously unselected package xfonts-utils. Unpacking xfonts-utils (from .../xfonts-utils_1%3a7.6+1_amd64.deb) ... Processing triggers for man-db ... Processing triggers for ureadahead ... ureadahead will be reprofiled on next reboot Processing triggers for fontconfig ... Setting up libfontenc1 (1:1.1.0-1) ... Setting up libxfont1 (1:1.4.4-1ubuntu0.3) ... Setting up x11-common (1:7.6+12ubuntu2) ... Setting up xfonts-encodings (1:1.0.4-1ubuntu1) ... Setting up xfonts-utils (1:7.6+1) ... Processing triggers for libc-bin ... ldconfig deferred processing now taking place root@sdfsfsfsfs:/usr/share/fonts/windfonts# mkfontscale root@sdfsfsfsfs:/usr/share/fonts/windfonts# mkfontdir root@sdfsfsfsfs:/usr/share/fonts/windfonts# fc-cache -fv /usr/share/fonts: caching, new cache contents: 0 fonts, 3 dirs /usr/share/fonts/X11: caching, new cache contents: 0 fonts, 2 dirs /usr/share/fonts/X11/encodings: caching, new cache contents: 0 fonts, 1 dirs /usr/share/fonts/X11/encodings/large: caching, new cache contents: 0 fonts, 0 dirs /usr/share/fonts/X11/util: caching, new cache contents: 0 fonts, 0 dirs /usr/share/fonts/truetype: caching, new cache contents: 0 fonts, 1 dirs /usr/share/fonts/truetype/ttf-dejavu: caching, new cache contents: 6 fonts, 0 dirs /usr/share/fonts/windfonts: caching, new cache contents: 16 fonts, 0 dirs /usr/X11R6/lib/X11/fonts: skipping, no such directory /usr/local/share/fonts: caching, new cache contents: 0 fonts, 0 dirs /root/.fonts: skipping, no such directory /var/cache/fontconfig: cleaning cache directory /root/.fontconfig: not cleaning non-existent cache directory fc-cache: succeeded
相关文章推荐
- Centos5.8 x86_64下安装DRBD+Heartbeat+NFS
- Linux下实现USB口的热插拔事件触发
- linux时区问题
- 辛星浅析linux下安装rails对于sqlite3缺少的问题
- [Linux] awk命令笔记 入门
- linux server 向外网发送邮件
- Linux下搭建php+apach+mysql+svn
- Linux Hellpworld 驱动程序加载
- linux查看本机IP、gateway、dns
- Linux下*.tar.gz文件解压缩命令
- php Linux安装
- Linux vi 操作命令整理
- Linux学习方法分享
- Linux--FFMPEG2.8 安装
- Linux进程间通信(IPC)编程实践(三) 详解System V消息队列(1)
- linux文件系统文件路径,inode,block号,sector号的相互转换
- 【学神】1-2Linux基本文件管理
- 安装linux系统后修改默认开机启动项
- linux系统中查看CPU的有关信息
- (笔记)Linux下检测网卡与网线连接状态