linux添加中文字库主线任务,Linux 添加中文字体库

背景:润乾报表 win上面的项目直接上传到linux 上,但预览&下载报表时乱码

如果含有斜线的单元格或统计图的报表在网页上发布时,统计图或斜线单元格里的汉字会变成小方框,此时往往是服务器端操作系统的中文安装包没有装全,导致报表里用到的字体在服务器端的操作系统里找不到,因此成了小方块。

我这只配置到前 5 步就可以了,不需要重启Linux 或字体服务,步骤总结为以下:

1、检查字体是否已经安装:

fc-list  ----------检查所有已有的字体

fc-list :lang=zh -----------只检查中文

2、到 C:\windows\fonts 复制对应字体库,微软雅黑、宋体、黑体等,各文件后缀可能不一样,有的为ttf,有的为ttc,不影响使用。

3、上传刚才复制的字体库到/usr/share/fonts/zh_CN目录下,如果没有该目录,用命令:

mkdir /usr/share/fonts/zh_CN

来创建,然后再上传。

4、修改字体权限,使root以外的用户可以使用这些字体:使用777 赋予全部权限

chmod -R 777 /usr/share/fonts/zh_CN

5、建立字体缓存:

root@gxx:/usr/share/fonts# mkfontscale

root@gxx:/usr/share/fonts# mkfontdir

root@gxx:/usr/share/fonts# fc-cache -fv

/usr/share/fonts: caching, new cache contents: 0 fonts, 4 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/cmap: caching, new cache contents: 0 fonts, 5 dirs

/usr/share/fonts/cmap/adobe-cns1: caching, new cache contents: 0 fonts, 0 dirs

/usr/share/fonts/cmap/adobe-gb1: caching, new cache contents: 0 fonts, 0 dirs

/usr/share/fonts/cmap/adobe-japan1: caching, new cache contents: 0 fonts, 0 dirs

/usr/share/fonts/cmap/adobe-japan2: caching, new cache contents: 0 fonts, 0 dirs

/usr/share/fonts/cmap/adobe-korea1: caching, new cache contents: 0 fonts, 0 dirs

/usr/share/fonts/truetype: caching, new cache contents: 0 fonts, 1 dirs

/usr/share/fonts/truetype/dejavu: caching, new cache contents: 21 fonts, 0 dirs

/usr/share/fonts/zh_CN: caching, new cache contents: 419 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

Re-scanning /usr/share/fonts: caching, new cache contents: 0 fonts, 4 dirs

Re-scanning /usr/share/fonts/X11: caching, new cache contents: 0 fonts, 2 dirs

Re-scanning /usr/share/fonts/X11/encodings: caching, new cache contents: 0 fonts, 1 dirs

Re-scanning /usr/share/fonts/cmap: caching, new cache contents: 0 fonts, 5 dirs

Re-scanning /usr/share/fonts/truetype: caching, new cache contents: 0 fonts, 1 dirs

/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

6、重启 Tomcat,以上文章中有的说要重启 Linux系统,有的说要重启字体库服务,但我都没有,而且也没有字体服务,只是重启了Tomcat 执行后有效。

7、可以再次使用 fc-list 查看字体库,已经包含了新加入的字体,或者使用上边的Java 输出也包含了新字体,打印中文水印也OK。

root@gxx:~# fc-list :lang=zh

/usr/share/fonts/zh_CN/msyhl.ttc: Microsoft YaHei UI,Microsoft YaHei UI Light:style=Light,Regular

/usr/share/fonts/zh_CN/Dengl.ttf: DengXian,等线,DengXian Light,等线 Light:style=Light,Regular

/usr/share/fonts/zh_CN/msyh.ttc: Microsoft YaHei UI:style=Regular,Normal,obyčejné,Standard,Κανονικά,Normaali,Normál,Normale,Standaard,Normalny,Обычный,Normálne,Navadno,Arrunta

/usr/share/fonts/zh_CN/simsun.ttc: SimSun,宋体:style=Regular,常规

/usr/share/fonts/zh_CN/Dengb.ttf: DengXian,等线:style=Bold

/usr/share/fonts/zh_CN/SIMLI.TTF: LiSu,隶书:style=Regular

/usr/share/fonts/zh_CN/Deng.ttf: DengXian,等线:style=Regular

/usr/share/fonts/zh_CN/STXINWEI.TTF: STXinwei,华文新魏:style=Regular

/usr/share/fonts/zh_CN/STHUPO.TTF: STHupo,华文琥珀:style=Regular

/usr/share/fonts/zh_CN/msjhl.ttc: Microsoft JhengHei,微軟正黑體,微軟正黑體 Light,Microsoft JhengHei Light:style=Light,Regular

/usr/share/fonts/zh_CN/simkai.ttf: KaiTi,楷体:style=Regular,Normal,obyčejné,Standard,Κανονικά,Normaali,Normál,Normale,Standaard,Normalny,Обычный,Normálne,Navadno,Arrunta

/usr/share/fonts/zh_CN/STSONG.TTF: STSong,华文宋体:style=Regular

/usr/share/fonts/zh_CN/STFANGSO.TTF: STFangsong,华文仿宋:style=Regular

/usr/share/fonts/zh_CN/simhei.ttf: SimHei,黑体:style=Regular,Normal,obyčejné,Standard,Κανονικά,Normaali,Normál,Normale,Standaard,Normalny,Обычный,Normálne,Navadno,Arrunta

/usr/share/fonts/zh_CN/FZYTK.TTF: FZYaoTi,方正姚体:style=Regular

/usr/share/fonts/zh_CN/FZSTK.TTF: FZShuTi,方正舒体:style=Regular

/usr/share/fonts/zh_CN/msjh.ttc: Microsoft JhengHei,微軟正黑體:style=Normal,Regular,obyčejné,Standard,Κανονικά,Normaali,Normál,Normale,Standaard,Normalny,Обычный,Normálne,Navadno,Arrunta

/usr/share/fonts/zh_CN/STXINGKA.TTF: STXingkai,华文行楷:style=Regular

/usr/share/fonts/zh_CN/msyh.ttc: Microsoft YaHei,微软雅黑:style=Regular,Normal,obyčejné,Standard,Κανονικά,Normaali,Normál,Normale,Standaard,Normalny,Обычный,Normálne,Navadno,Arrunta

/usr/share/fonts/zh_CN/msjhl.ttc: Microsoft JhengHei UI,Microsoft JhengHei UI Light:style=Light,Regular

/usr/share/fonts/zh_CN/simsun.ttc: NSimSun,新宋体:style=Regular,常规

/usr/share/fonts/zh_CN/STLITI.TTF: STLiti,华文隶书:style=Regular

/usr/share/fonts/zh_CN/STZHONGS.TTF: STZhongsong,华文中宋:style=Regular

/usr/share/fonts/zh_CN/STKAITI.TTF: STKaiti,华文楷体:style=Regular

/usr/share/fonts/zh_CN/msjhbd.ttc: Microsoft JhengHei,微軟正黑體:style=Negreta,Bold,tučné,fed,Fett,Έντονα,Negrita,Lihavoitu,Gras,Félkövér,Grassetto,Vet,Halvfet,Pogrubiony,Negrito,Полужирный,Fet,Kalın,Krepko,Lodia

/usr/share/fonts/zh_CN/msjh.ttc: Microsoft JhengHei UI:style=Normal,Regular,obyčejné,Standard,Κανονικά,Normaali,Normál,Normale,Standaard,Normalny,Обычный,Normálne,Navadno,Arrunta

/usr/share/fonts/zh_CN/msyhbd.ttc: Microsoft YaHei,微软雅黑:style=Bold,Negreta,tučné,fed,Fett,Έντονα,Negrita,Lihavoitu,Gras,Félkövér,Grassetto,Vet,Halvfet,Pogrubiony,Negrito,Полужирный,Fet,Kalın,Krepko,Lodia

/usr/share/fonts/zh_CN/msyhl.ttc: Microsoft YaHei,微软雅黑,Microsoft YaHei Light,微软雅黑 Light:style=Light,Regular

/usr/share/fonts/zh_CN/msjhbd.ttc: Microsoft JhengHei UI:style=Negreta,Bold,tučné,fed,Fett,Έντονα,Negrita,Lihavoitu,Gras,Félkövér,Grassetto,Vet,Halvfet,Pogrubiony,Negrito,Полужирный,Fet,Kalın,Krepko,Lodia

/usr/share/fonts/zh_CN/STXIHEI.TTF: STXihei,华文细黑:style=Regular

/usr/share/fonts/zh_CN/STCAIYUN.TTF: STCaiyun,华文彩云:style=Regular

/usr/share/fonts/zh_CN/SIMYOU.TTF: YouYuan,幼圆:style=Regular

/usr/share/fonts/zh_CN/simfang.ttf: FangSong,仿宋:style=Regular,Normal,obyčejné,Standard,Κανονικά,Normaali,Normál,Normale,Standaard,Normalny,Обычный,Normálne,Navadno,Arrunta

/usr/share/fonts/zh_CN/msyhbd.ttc: Microsoft YaHei UI:style=Bold,Negreta,tučné,fed,Fett,Έντονα,Negrita,Lihavoitu,Gras,Félkövér,Grassetto,Vet,Halvfet,Pogrubiony,Negrito,Полужирный,Fet,Kalın,Krepko,Lodia

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值