java - 为什么 GraphicsEnvironment 的 getAllFonts() 返回的字体与 fc-list 不同?

标签 java linux fonts

为什么 GraphicsEnvironment 的 getAllFonts() 方法返回不同的字体 比 fc-list(在 linux 上?)

fc-list 返回:

Abyssinica SIL:style=Regular
Cantarell:style=Bold
Cantarell:style=Regular
Century Schoolbook L:style=Bold
Century Schoolbook L:style=Bold Italic
Century Schoolbook L:style=Italic
Century Schoolbook L:style=Roman
Courier:style=Regular
DejaVu Sans,DejaVu Sans Condensed:style=Condensed Bold,Bold
DejaVu Sans,DejaVu Sans Condensed:style=Condensed Bold Oblique,Bold Oblique
DejaVu Sans,DejaVu Sans Condensed:style=Condensed,Book
DejaVu Sans,DejaVu Sans Condensed:style=Condensed Oblique,Oblique
DejaVu Sans,DejaVu Sans Light:style=ExtraLight
DejaVu Sans Mono:style=Bold
DejaVu Sans Mono:style=Bold Oblique
DejaVu Sans Mono:style=Book
DejaVu Sans Mono:style=Oblique
DejaVu Sans:style=Bold
DejaVu Sans:style=Bold Oblique
DejaVu Sans:style=Book
DejaVu Sans:style=Oblique
DejaVu Serif,DejaVu Serif Condensed:style=Condensed Bold,Bold
DejaVu Serif,DejaVu Serif Condensed:style=Condensed Bold Italic,Bold Italic
DejaVu Serif,DejaVu Serif Condensed:style=Condensed,Book
DejaVu Serif,DejaVu Serif Condensed:style=Condensed Italic,Italic
DejaVu Serif:style=Bold
DejaVu Serif:style=Bold Italic
DejaVu Serif:style=Book
DejaVu Serif:style=Italic
Dingbats:style=Regular
...

鉴于

GraphicsEnvironment 中的 getAllFonts 返回:

AbyssinicaSIL
CenturySchL-Bold
CenturySchL-BoldItal
CenturySchL-Ital
CenturySchL-Roma
DejaVuSans
DejaVuSans-Bold
DejaVuSans-BoldOblique
DejaVuSansCondensed
DejaVuSansCondensed-Bold
DejaVuSansCondensed-BoldOblique
DejaVuSansCondensed-Oblique
DejaVuSans-ExtraLight
DejaVuSansMono
DejaVuSansMono-Bold
DejaVuSansMono-BoldOblique
DejaVuSansMono-Oblique
DejaVuSans-Oblique
DejaVuSerif
DejaVuSerif-Bold
DejaVuSerif-BoldItalic
DejaVuSerifCondensed
DejaVuSerifCondensed-Bold
DejaVuSerifCondensed-BoldItalic
DejaVuSerifCondensed-Italic
DejaVuSerif-Italic
Dialog.bold
Dialog.bolditalic
Dialog.italic
Dialog.plain
DialogInput.bold
DialogInput.bolditalic
DialogInput.italic
DialogInput.plain
Dingbats
...

比较这两个不同的列表,教学列表中有其他字体不可用的字体。

谁能解释一下这是怎么回事?


进一步说明:

我首先提出这个问题的原因是,我试图找出一些 UI 问题,其中一个操作系统(例如 Solaris)上定义的字体与另一个操作系统(例如 Linux)上定义的字体不同。

我认为问题在于虽然两个操作系统具有相同的逻辑字体(对话框), 它们不一定具有相同的物理字体。

但是如果你制作这样的字体:

Font STANDARD_FONT = new Font("Dialog", 0, 12); 

不能保证到处都一样。

我希望我可以查看两个系统上可用的字体,看看哪些可以通过 fc-list 获得,但是 java (Dialog.plain) 报告的字体不是根据 fc-list 列出的字体。

因此,如果我通过 new Font("Dialog", 0, 12) 定义逻辑字体, 通过 java 可用的 API(例如 font.getName() 等)显示:

后记 - Dialog.plain 家庭 - 对话 名称 - 对话框 fontName - Dialog.plain 尺寸 - 12

我如何准确判断 java 选择用于对话框系列的物理字体?

最佳答案

getAllFonts() 中独有的字体系列不是物理字体,这意味着它们不是您计算机上的字体文件,因此 fc-list 找不到他们。它们是每个 Java 实现中常见的字体系列,并映射到物理字体。

Logical fonts are the five font families defined by the Java platform which must be supported by any Java runtime environment: Serif, SansSerif, Monospaced, Dialog, and DialogInput. These logical fonts are not actual font libraries. Instead, the logical font names are mapped to physical fonts by the Java runtime environment.

至于fc-list 独有的字体系列,它们很可能是您系统上运行的Java 实现不支持的物理字体。 Java 实现需要支持的唯一字体类型是 TrueType; fc-list 独有的字体可能不是 TrueType。

All implementations of the Java Platform must support TrueType fonts; support for other font technologies is implementation dependent.

来源:Java's Font API documentation .

关于java - 为什么 GraphicsEnvironment 的 getAllFonts() 返回的字体与 fc-list 不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15329880/

相关文章:

java - 将投影形式 Hibernate HQL 查询映射到对象

Java - 如何查看一个字符是否与多个字符匹配?

mysql - 进行数据库备份时网站显示不可用?

linux - virtualbox debian 中的共享文件夹中的 create-react-app 无法正常工作 - 符号链接(symbolic link)错误

html - 如何更改字符的html按钮中的字体

java - 同时使用 junit 断言和 mockito 验证

值大于 127 的 Java 字符通过 tcp 发送

linux - 使远程目录保持最新

ruby-on-rails - Rails 4.1 - ActionController::RoutingError(没有路由匹配 [GET] "/fonts/....ttf") - @font-face 问题

html - 根据 div 调整大小调整文本大小?