Skip to content

Linux 安装字体 #32

Description

@mirages

Linux 安装字体

下载字体库

下载想要使用的字体库,然后上传至 Linux 服务器的 /usr/share/fonts 目录下

可以在 github 上去搜索相关字体,例如思源黑体。

更新字体缓存

将字体复制到 Linux 相关目录下后,需要更新字体缓存,使系统能够识别新安装的字体

fc-cache -fv

如果系统提示 fc-cache: command not found,则需要先安装 fontconfig 工具包:

yum install fontconfig

检查字体是否安装成功

可以使用 fc-list 命令来查看已经安装的字体,

fc-list
# 输出信息为
/usr/share/fonts/sourcehan/SourceHanSansSC-VF.ttf: Source Han Sans SC VF:style=Medium

可以看到以下信息:

  • 字体的路径:/usr/share/fonts/sourcehan/SourceHanSansSC-VF.ttf
  • 字体的名称:Source Han Sans SC VF
  • 字体的样式:style=Medium

也可以使用 fc-list :lang=zh 来查看安装的中文字体信息

java 代码使用字体库

可以使用 java.awt.Font 类来加载使用字体

import java.awt.*
Font font = new Font("Source Han Sans SC VF", Font.PLAIN, 36);

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    linuxlinux commad

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions