系统的真实字体名是怎么解析获得的?

2022-11-14 09:44:55 +08:00
 wszgrcy
2871 次点击
所在节点    编程
16 条回复
swulling
2022-11-14 09:51:48 +08:00
ttc 文件里面定义的,可以参考

https://learn.microsoft.com/en-us/typography/opentype/spec/name

如果想自己获取,找一找有没有对应的库吧。
cairnechen
2022-11-14 09:52:20 +08:00
这个问题曾经也困扰过我,比如 VScode 设置 Font Family 的时候,又有中文名又有英文名,不知道哪个是准确的

例:Menlo, 思源黑体, 'Courier New', monospace
swulling
2022-11-14 09:55:14 +08:00
@cairnechen 前三个是三个不同的字体。最后一个其实可以理解是一种 alias 。
cairnechen
2022-11-14 10:06:14 +08:00
@swulling 我的意思是我不知道,这个位置是要填思源黑体,还是 SourceHanSans ,好多字体配置文件都没说明白,只能靠猜
swulling
2022-11-14 10:09:03 +08:00
@cairnechen

https://www.lcdf.org/type/index.html

$ otfinfo --info raleway.ttf
Family: Raleway Light
Subfamily: Regular
Full name: Raleway Light -< HERE
PostScript name: Raleway-Light
Preferred family: Raleway
Preferred subfamily: Light
ye4241
2022-11-14 10:25:01 +08:00
很多字体都有 Family Name 的,而 Fullname 也是可以做成不一样,最终决定字体的唯一性的其实是 Fontname 吧。

https://imgur.com/a/u9NV6ZI

所以 Word 中看到的微软雅黑只是中文下的 Family Name 的,在存储到 Word 文件的时候,会用他的 PS Name 的 Family Name 也就是 Microsoft YaHei 。

至于解析么,我只知道 C#的,https://stackoverflow.com/a/15279356

对了,查看字体属性的软件是 FontFroge
wszgrcy
2022-11-14 10:25:43 +08:00
@swulling 感谢,我看看
wszgrcy
2022-11-14 10:29:22 +08:00
@ye4241 雅黑好像有两个名字,中文是微软雅黑,英文是 Microsoft YaHei (windows 字体预览可以看到),不知道是不是国情所在
kokutou
2022-11-14 10:37:30 +08:00
我只知道绝大部分软件里这 2 个都可以用。

wszgrcy
2022-11-14 10:38:04 +08:00
@swulling 微软有点敷衍.utf16 竟然不写 le 还是 be....看来微软在搞字体的时候也没想到有一天有 arm 点 windows,估计字体这块 arm 是兼容的 x86
Kakus
2022-11-14 10:54:46 +08:00
python 读取系统字体列表:

```
from matplotlib import font_manager
ttf_lists = font_manager.fontManager.ttflist
for font in ttf_lists:
print(font)
```

cairnechen
2022-11-14 11:23:34 +08:00
@swulling
Family: Source Han Sans SC
Subfamily: Regular
Full name: Source Han Sans SC
PostScript name: SourceHanSansSC-Regular
Version: Version 2.004;hotconv 1.0.118;makeotfexe 2.5.65603
Unique ID: 2.004;ADBO;SourceHanSansSC-Regular;ADOBE
Description: Dr. Ken Lunde (project architect, glyph set definition & overall production); Masataka HATTORI 服部正貴 (production & ideograph elements)
Designer: Ryoko NISHIZUKA 西塚涼子 (kana, bopomofo & ideographs); Paul D. Hunt (Latin, Greek & Cyrillic); Sandoll Communications 산돌커뮤니케이션, Soo-young JANG 장수영 & Joo-yeon KANG 강주연 (hangul elements, letters & syllables)
Manufacturer: Adobe
Vendor URL: http://www.adobe.com/type/
Trademark: Source is a trademark of Adobe in the United States and/or other countries.
Copyright: © 2014-2021 Adobe ( http://www.adobe.com/), with Reserved Font Name 'Source'.
License URL: http://scripts.sil.org/OFL
License Description: This Font Software is licensed under the SIL Open Font License, Version 1.1. This Font Software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the SIL Open Font License for the specific language, permissions and limitations governing your use of this Font Software.
Vendor ID: ADBO

所以怎么知道 VScode Font Family 哪里应该填哪个?
1 、Family: Source Han Sans SC
2 、Full name: Source Han Sans SC
3 、PostScript name: SourceHanSansSC-Regular
4 、思源黑体
swulling
2022-11-14 11:28:36 +08:00
@cairnechen 填 Family:Source Han Sans SC 就行了。字体你理解是一个个的家族,每个家族里有不同的字型,不同字型的粗细轻重不同。最简单就是普通和加粗的区别。

让你填 family 的就填家族名。
xtreme1
2022-11-14 11:30:26 +08:00
cpstar
2022-11-14 11:31:13 +08:00
这难道不是加载了 TTC/TTF 之后,读取相应 key 为那么,显然其 value 么?完成了从 name 到 file 的对应关联。

然后在 css 中使用,你能确定客户机安装了相应字体么?那不是需要 @ media 传送给客户呀,那自然可以解析自己的 TTF/TTC 获取到应该使用的名字了呀
leoleozhu
2022-11-14 12:16:12 +08:00
otf ttf 中有 name table ,名称相关的都是这里来的,和文件名没有关系
同时 font family 是多语言的,例如思源黑体,在日文中叫源ノ明体,英文叫 SourceHanSans

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/895009

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX