libreoffice解决中文字体不生效 fontconfig字体配置

问题:CentOS7.8 系统使用libreoffice将word转为pdf,系统已安装”方正小标宋简体“相关中文字体,仍无法识别中文字体。
实际使用中pdf总是只能显示思源黑体和思源宋体两种字体,相关服务器安装配置参考:服务器配置概要

所有对 fontconfig 文件的更改只有在重新启动程序后才会生效!

具体解决:

  1. fc-list :lang=zh 确认系统已安装的中文字体;
  2. 修改 fontconfig 默认配置 /etc/fonts/fonts.conf 信息,优先添加相关中文字体,参考如下:
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<!-- /etc/fonts/fonts.conf file to configure system font access -->
<fontconfig>
<!--
    DO NOT EDIT THIS FILE.
    IT WILL BE REPLACED WHEN FONTCONFIG IS UPDATED.
    LOCAL CHANGES BELONG IN 'local.conf'.

    The intent of this standard configuration file is to be adequate for
    most environments.  If you have a reasonably normal environment and
    have found problems with this configuration, they are probably
    things that others will also want fixed.  Please submit any
    problems to the fontconfig bugzilla system located at fontconfig.org

    Note that the normal 'make install' procedure for fontconfig is to
    replace any existing fonts.conf file with the new version.  Place
    any local customizations in local.conf which this file references.

    Keith Packard
-->

<!-- Font directory list -->

    <dir>/usr/share/fonts</dir>
    <dir>/usr/share/X11/fonts/Type1</dir> <dir>/usr/share/X11/fonts/TTF</dir> <dir>/usr/local/share/fonts</dir>
    <dir prefix="xdg">fonts</dir>
    <!-- the following element will be removed in the future -->
    <dir>~/.fonts</dir>
    
    
    <match>
        <test qual="any" name="family">
            <string>方正小标宋简体</string>
        </test>
        <edit name="family" mode="assign" binding="same">
            <string>FZXiaoBiaoSong-B05S</string>
        </edit>
    </match>
    <match>
        <test qual="any" name="family">
            <string>宋体</string>
        </test>
        <edit name="family" mode="assign" binding="same">
            <string>SimSun</string>
        </edit>
    </match>
    <match>
        <test qual="any" name="family">
            <string>仿宋</string>
        </test>
        <edit name="family" mode="assign" binding="same">
            <string>FangSong</string>
        </edit>
    </match>
    <match>
        <test qual="any" name="family">
            <string>仿宋_GB2312</string>
        </test>
        <edit name="family" mode="assign" binding="same">
            <string>FangSong</string>
        </edit>
    </match>
    <match>
        <test qual="any" name="family">
            <string>黑体</string>
        </test>
        <edit name="family" mode="assign" binding="same">
            <string>SimHei</string>
        </edit>
    </match>
    <match>
        <test qual="any" name="family">
            <string>楷体</string>
        </test>
        <edit name="family" mode="assign" binding="same">
            <string>KaiTi</string>
        </edit>
    </match>
    <match>
        <test qual="any" name="family">
            <string>微软雅黑</string>
        </test>
        <edit name="family" mode="assign" binding="same">
            <string>Microsoft YaHei</string>
        </edit>
    </match>
    <match>
        <test qual="any" name="family">
            <string>方正仿宋</string>
        </test>
        <edit name="family" mode="assign" binding="same">
            <string>FZFangSong-Z02</string>
        </edit>
    </match>
    

<!--
  Accept deprecated 'mono' alias, replacing it with 'monospace'
-->
    <match target="pattern">
        <test qual="any" name="family">
            <string>mono</string>
        </test>
        <edit name="family" mode="assign" binding="same">
            <string>monospace</string>
        </edit>
    </match>

<!--
  Accept alternate 'sans serif' spelling, replacing it with 'sans-serif'
-->
    <match target="pattern">
        <test qual="any" name="family">
            <string>sans serif</string>
        </test>
        <edit name="family" mode="assign" binding="same">
            <string>sans-serif</string>
        </edit>
    </match>

<!--
  Accept deprecated 'sans' alias, replacing it with 'sans-serif'
-->
    <match target="pattern">
        <test qual="any" name="family">
            <string>sans</string>
        </test>
        <edit name="family" mode="assign" binding="same">
            <string>sans-serif</string>
        </edit>
    </match>

<!--
  Load local system customization file
-->
    <include ignore_missing="yes">conf.d</include>

<!-- Font cache directory list -->

    <cachedir>/usr/lib/fontconfig/cache</cachedir>
    <cachedir prefix="xdg">fontconfig</cachedir>
    <!-- the following element will be removed in the future -->
    <cachedir>~/.fontconfig</cachedir>

    <config>
<!--
  Rescan configuration every 30 seconds when FcFontSetList is called
 -->
        <rescan>
            <int>30</int>
        </rescan>
    </config>

</fontconfig>

  1. fc-cache -fv 更新缓存; fc-match 方正小标宋简体 确认配置是否生效;
  2. ps aux | grep soffice 查看并杀死进程,重启soffice;

参考:
fontconfig: https://wiki.gentoo.org/wiki/Fontconfig/zh-cn

Tags: none

添加新评论