CentOS7.5---7.9 中文字体匹配错误 fontconfig-2.13.0

时间:2024-03-04 12:09:40

wps 显示方正字体错误,已经按照如下步骤添加方正字体和windows上的字体:

/usr/share/fonts/目录下创建FangZheng、Windows文件夹,将相应的ttf、ttc文件放入文件夹中

$ fc-cache && mkfontscale && mkfontdir

 

查看字体支持的中文字体的文件

$ fc-list :lang=zh
    /usr/share/fonts/wps-office/FZXBSJW.TTF: FZXiaoBiaoSong\-B05S:style=Regular
    ......
    /usr/share/fonts/wps-office/FZKANGFW.TTF: FZKangTi\-S07T:style=Regular

正常匹配到中文字体的显示(其他系统)
$ fc-list :lang=zh
    /usr/share/fonts/wps-office/FZXBSJW.TTF: 方正小标宋简体,FZXiaoBiaoSong\-B05S:style=Regular
    /usr/share/fonts/wps-office/FZHTK.TTF: 方正黑体_GBK,FZHei\-B01:style=Regular
    /usr/share/fonts/wps-office/FZXBSK.TTF: 方正小标宋_GBK,FZXiaoBiaoSong\-B05:style=Regular
    ......
    /usr/share/fonts/wps-office/FZSSK.TTF: 方正书宋_GBK,FZShuSong\-Z01:style=Regular

看出区别了吧!!! 正常输出有中文字体名

 

根据中文字体名匹配相应的字体文件

$ fc-match -a <字体名> | head

$ fc-match -a 方正仿宋简体 | head
$ fc-match -a 方正小标宋简体 | head
$ fc-match -a 方正仿宋_GBK | head

下面 方正仿宋简体 没有匹配到
$ fc-match -a 方正仿宋简体 | head
    NotoSansCJK-Regular.ttc: "Noto Sans CJK SC" "Regular"
    NotoSansCJK-Medium.ttc: "Noto Sans CJK SC" "Medium"

正常匹配到中文字体的显示(其他系统)
$ fc-match -a 方正小标宋简体 | head
    FZXBSJW.TTF: "方正小标宋简体" "Regular"
    NotoSansCJK-Regular.ttc: "Noto Sans CJK SC" "Regular"
$ fc-match -a 方正仿宋_GBK | head
    FZFSK.TTF: "方正仿宋_GBK" "Regular"
    NotoSansCJK-Regular.ttc: "Noto Sans CJK SC" "Regular"

 

查询字体文件的相关信息,字体文件中不显示中文名称等信息

$ fc-query /usr/share/fonts/wps-office/FZXBSJW.TTF
Pattern has 24 elts (size 32)
    family: "FZXiaoBiaoSong-B05S"(s)
    familylang: "en"(s)
    style: "Regular"(s)
    stylelang: "en"(s)
    fullname: "FZXiaoBiaoSong-B05S"(s)
    fullnamelang: "en"(s)
    slant: 0(i)(s)
    weight: 80(f)(s)
    width: 100(f)(s)
    foundry: "BDFZ"(s)
    file: "/usr/share/fonts/wps-office/FZXBSJW.TTF"(s)
    index: 0(i)(s)
    outline: True(s)
    scalable: True(s)
    charset: 
    ......
    lang: bg|fj|ho|ia|ie|io|kum|nr|om|os|ru|sel|so|ss|st|sw|ts|uz|xh|zh-cn|zh-sg|zu|kj|kwm|ms|ng|rn|rw|sn|za(s)
    fontversion: 0(i)(s)
    capability: "otlayout:hani"(s)
    fontformat: "TrueType"(s)
    decorative: False(s)
    postscriptname: "FZXBSJW--GB1-0"(s)
    color: False(s)
    symbol: False(s)
    variable: False(s)

正常匹配到中文字体的显示(其他系统)
$ fc-query /usr/share/fonts/wps-office/FZXBSJW.TTF
Pattern has 24 elts (size 32)
    family: "FZXiaoBiaoSong-B05S"(s) "方正小标宋简体"(s)
    familylang: "en"(s) "zh-cn"(s)
    style: "Regular"(s)
    stylelang: "en"(s)
    fullname: "FZXiaoBiaoSong-B05S"(s) "方正小标宋简体"(s)
    fullnamelang: "en"(s) "zh-cn"(s)
    slant: 0(i)(s)
    weight: 80(f)(s)
    width: 100(f)(s)
    foundry: "BDFZ"(s)
    file: "/usr/share/fonts/wps-office/FZXBSJW.TTF"(s)
    index: 0(i)(s)
    outline: True(s)
    scalable: True(s)
    charset: 
    ......
    lang: bg|fj|ho|ia|ie|io|kum|nr|om|os|ru|sel|so|ss|st|sw|ts|uz|xh|zh-cn|zh-sg|zu|kj|kwm|ms|ng|rn|rw|sn|za(s)
    fontversion: 0(i)(s)
    capability: "otlayout:hani"(s)
    fontformat: "TrueType"(s)
    decorative: False(s)
    postscriptname: "FZXBSJW--GB1-0"(s)
    color: False(s)
    symbol: False(s)
    variable: False(s)

同样的查询,同样的字体文件,为啥你不输出中文字体名字啊! 垃圾啊!

 

解决方法(降fontconfig版本):

1.卸载fontconfig-2.13.0

# yum list installed | grep fontconfig
# rpm -e --nodeps fontconfig
# yum list installed | grep fontconfig

 

2.安装fontconfig-2.10.95

# rpm -ivh fontconfig-2.10.95-11.el7.aarch64.rpm
# rpm -qi fontconfig

 

3.更新字体缓存和索引

# fc-cache && mkfontscale && mkfontdir

 

4.查看字体是否包含中文

# fc-query /usr/share/fonts/wps-office/FZXBSJW.TTF

 

5.查看是否可以匹配到字体

# fc-match -a 方正仿宋简体 | head
# fc-match -a 方正小标宋简体 | head
# fc-match -a 方正仿宋_GBK | head

 

6.wps进行查看

# wps 1.doc

 

fontconfig-2.13.1 应该也解决这个问题了,升级过程碰到了其他问题,没操作成功。 

 

fontconfig降版本的后遗症

/sbin/ldconfig: /lib64/libstdc++.so.6 不是符号链接

$ sudo ldconfig -v
$ sudo ln -sf /path/source.so.x.xxx /path/source.so.x

$ ll /lib64/libstdc++.so*
$ sudo ln -sf /lib64/libstdc++.so.6.0.19 /lib64/libstdc++.so.6

 

修改了这个库啊?  /usr/lib64/libfontconfig.so

ll /usr/lib64/libfontconfig.so*
lrwxrwxrwx. 1 root root     23 Jul 13 23:31 /usr/lib64/libfontconfig.so -> libfontconfig.so.1.11.1
lrwxrwxrwx. 1 root root     22 Aug 20 06:41 /usr/lib64/libfontconfig.so.1 -> libfontconfig.so.1.7.0
-rwxr-xr-x. 1 root root 272064 Aug 24  2018 /usr/lib64/libfontconfig.so.1.7.0

 

关于x86_64平台fontconfig-2.10.95下载

安装CentOS7.0---7.2系统,通过该系统的yum源来下载fontconfig-2.10.95的rpm包