本文是博文 https://blog.csdn.net/wenhao_ir/article/details/145433648 的延伸擴展。
本文是博文 https://blog.csdn.net/wenhao_ir/article/details/145433648 的延伸擴展。
問:運行 ls /usr/lib/fonts/ 發現有一個名叫 msyh.ttc 的字體文件,能介紹下msyh.ttc不?
msyh.ttc 是 微軟雅黑(Microsoft YaHei) 字體的 TrueType Collection (TTC) 格式文件。它是 Windows 操作系統中常見的 中文無襯線字體,專門設計用于清晰地顯示簡體中文文本,當然也能顯示英文。
1. msyh.ttc 詳細信息
- 字體名稱:微軟雅黑(Microsoft YaHei)
- 文件格式:TTC(TrueType Collection)
- 適用語言:簡體中文、英文
- 提供商:微軟(Microsoft)
- 文件位置:
- Windows:通常位于
C:\Windows\Fonts\msyh.ttc - Linux:如果你在
/usr/lib/fonts/發現了msyh.ttc,可能是手動復制或安裝的
- Windows:通常位于
2. TTC(TrueType Collection)是什么?
.ttc 是 TrueType Collection(TrueType 字體集)格式,它允許多個 TrueType 字體 共用一個文件。相比單個 .ttf,TTC 主要用于:
- 減少磁盤占用(多個相似字體共享字形數據)
- 提供多個字體變體(如 Regular、Bold 等)
通常 msyh.ttc 里面包含:
- 微軟雅黑 Regular(普通字體)
- 微軟雅黑 Bold(加粗字體)
- 可能包含其他變體
3. msyh.ttc 在 Linux 的應用
如果 Qt 運行環境設置了:
export QT_QPA_FONTDIR=/usr/lib/fonts/
那么 Qt 應用會自動從 /usr/lib/fonts/ 目錄加載 msyh.ttc 作為默認字體。
如果想手動測試字體,可以用 fc-list 命令檢查:
fc-list | grep msyh
如果輸出類似:
/usr/lib/fonts/msyh.ttc: Microsoft YaHei,微軟雅黑:style=Regular
說明系統成功識別了 msyh.ttc。
如果想讓 msyh.ttc 在 Qt 里生效,可以在代碼里指定:
QFont font("Microsoft YaHei", 12);
QApplication::setFont(font);
或者如果 msyh.ttc 不能被系統識別,你可以手動加載:
int fontId = QFontDatabase::addApplicationFont("/usr/lib/fonts/msyh.ttc");
QStringList fontFamilies = QFontDatabase::applicationFontFamilies(fontId);
if (!fontFamilies.isEmpty()) {QFont font(fontFamilies.at(0));QApplication::setFont(font);
}
4. 如何在 Linux 上安裝 msyh.ttc
如果 msyh.ttc 還沒有安裝,你可以:
-
從 Windows 復制
- 進入
C:\Windows\Fonts\ - 復制
msyh.ttc到 Linux/usr/lib/fonts/或/usr/share/fonts/truetype/ - 運行
fc-cache -fv更新字體緩存
- 進入
-
檢查字體是否生效
fc-list | grep "Microsoft YaHei"
5. msyh.ttc 與 msyh.ttf 的區別
msyh.ttc是字體集合,通常包含多個變體(Regular、Bold)msyh.ttf是單個 TrueType 字體,只包含 Regular 或 Bold 其中一種
結論
msyh.ttc是微軟雅黑字體,適用于中文和英文。- 它是 TrueType Collection (TTC) 格式,包含多個字體變體。
- 在 Qt/Linux 上可以直接使用,但有時需要
fc-cache -fv刷新字體緩存。 - 如果
msyh.ttc存在于/usr/lib/fonts/,Qt 應用可能已經在使用它作為默認字體。