为Linux安装字体(微软雅黑,微软雅黑UI)

检测字体

【GetLocalFontFamily.java】

import java.awt.*;

public class GetLocalFontFamily {
    public static void main(String[] agrs) {
        //获取系统中可用的字体的名字
        GraphicsEnvironment e = GraphicsEnvironment.getLocalGraphicsEnvironment();
        String[] fontName = e.getAvailableFontFamilyNames();
        for (int i = 0; i < fontName.length; i++) {
            System.out.println(fontName[i]);
        }
    }
}

# 编译为字节码
javac GetLocalFontFamily.java
# 执行
java GetLocalFontFamily

【结果】

[root@vultr ~]# java GetLocalFontFamily
Century Schoolbook L
Dialog
DialogInput
Dingbats
Lucida Bright
Lucida Sans
Lucida Sans Typewriter
Monospaced
Nimbus Mono L
Nimbus Roman No9 L
Nimbus Sans L
SansSerif
Serif
Standard Symbols L
URW Bookman L
URW Chancery L
URW Gothic L
URW Palladio L
Utopia

准备字体文件

微软雅黑,微软雅黑UI TTC文件——百度云

安装字体

# 新建目录
mkdir /usr/share/fonts/myfonts
# 将上述三个文件通过FileZilla或者winscp或者scp命令传输到上述创建的目录下
# 进入此目录
cd /usr/share/fonts/myfonts
# 执行如下相关命令
mkfontscale
mkfontdir
fc-cache -fv
# 输出blabla一堆信息
/usr/share/fonts: caching, new cache contents: 0 fonts, 2 dirs
/usr/share/fonts/default: caching, new cache contents: 0 fonts, 2 dirs
/usr/share/fonts/default/Type1: caching, new cache contents: 35 fonts, 0 dirs
/usr/share/fonts/default/ghostscript: caching, new cache contents: 4 fonts, 0 dirs
/usr/share/fonts/myfonts: caching, new cache contents: 6 fonts, 0 dirs
/usr/share/X11/fonts/Type1: skipping, no such directory
/usr/share/X11/fonts/TTF: skipping, no such directory
/usr/local/share/fonts: skipping, no such directory
/root/.local/share/fonts: skipping, no such directory
/root/.fonts: skipping, no such directory
/usr/share/fonts: caching, new cache contents: 0 fonts, 2 dirs
/usr/share/X11/fonts/Type1: skipping, no such directory
/usr/share/X11/fonts/TTF: skipping, no such directory
/usr/local/share/fonts: skipping, no such directory
/root/.local/share/fonts: skipping, no such directory
/root/.fonts: skipping, no such directory
/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

# ls查看当前文件夹下文件
[root@vultr myfonts]# ls
fonts.dir  fonts.scale  MSYHBD.TTC  MSYHL.TTC  MSYH.TTC

检查是否安装成功

再次执行检测程序

# 执行
java GetLocalFontFamily

【输出如下】

[root@vultr ~]# java GetLocalFontFamily
Century Schoolbook L
Dialog
DialogInput
Dingbats
Lucida Bright
Lucida Sans
Lucida Sans Typewriter
Microsoft YaHei UI
Microsoft YaHei UI Light
Monospaced
Nimbus Mono L
Nimbus Roman No9 L
Nimbus Sans L
SansSerif
Serif
Standard Symbols L
URW Bookman L
URW Chancery L
URW Gothic L
URW Palladio L
Utopia
微软雅黑
微软雅黑 Light

对比发现多了四个,分别是“Microsoft YaHei UI”/“Microsoft YaHei UI Light”/“微软雅黑”/“微软雅黑 Light”

你可能感兴趣的:(为Linux安装字体(微软雅黑,微软雅黑UI))