如果应用程序比如生成pdf或pdf生成图片,而其中包含中文字体,那么操作系统通常需要安装中文字体,本文将介绍如何在centos及debian系统上安装字体,以及如何构建带字体的docker镜像。

centos安装字体

1
2
3
4
5
yum install mkfontscale fontconfig -y
simsun.ttc /usr/share/fonts/local/simsun.ttc
simkai.ttf /usr/share/fonts/local/simkai.ttf
simhei.ttf /usr/share/fonts/local/simhei.ttf
mkfontscale && mkfontdir && fc-cache

debian安装字体

1
2
3
4
5
apt-get update && apt-get install ttf-mscorefonts-installer fontconfig -y
simsun.ttc /usr/share/fonts/local/simsun.ttc
simkai.ttf /usr/share/fonts/local/simkai.ttf
simhei.ttf /usr/share/fonts/local/simhei.ttf
mkfontscale && mkfontdir && fc-cache

构建基于centos的docker镜像

1
2
3
4
5
6
#install fonts
RUN yum install mkfontscale fontconfig -y
ADD simsun.ttc /usr/share/fonts/local/simsun.ttc
ADD simkai.ttf /usr/share/fonts/local/simkai.ttf
ADD simhei.ttf /usr/share/fonts/local/simhei.ttf
RUN mkfontscale && mkfontdir && fc-cache

构建基于debian的docker镜像

1
2
3
4
5
RUN apt-get update && apt-get install ttf-mscorefonts-installer fontconfig -y && apt-get clean && rm -rf /var/lib/apt/lists/*
ADD simsun.ttc /usr/share/fonts/local/simsun.ttc
ADD simkai.ttf /usr/share/fonts/local/simkai.ttf
ADD simhei.ttf /usr/share/fonts/local/simhei.ttf
RUN mkfontscale && mkfontdir && fc-cache

查看已安装的字体情况

1
2
3
fc-list
#或
fc-list :lang=zh