Tên phông chữ được bản địa hóa nếu người tạo phông chữ chọn xuất bản siêu dữ liệu cho một miền địa phương cụ thể, nhưng tất cả phông chữ đều có tên hệ thống, thường là tên PostScript, đảm bảo cùng một phông chữ có thể tham chiếu và truy xuất số lượng đáng tin cậy.
Đối với phông chữ OpenType và TrueType, bạn có thể tìm tên được bản địa hóa trong bản ghi name
của tệp OpenType.
The Naming Table (OpenType Spec 1.6) @ Microsoft Typography
Font Names Table (TrueType Spec) @ Apple
Đối với PostScript loại 1 phông chữ, bạn có thể xác định vị trí các tên phân công của tờ khai FontName của họ.
Adobe Type 1 Font Format @ Adobe (PDF)
Cập nhật:
Tôi đã kiểm tra để xem liệu tên PostScript có thể được sử dụng để khởi tạo một font chữ, và tiếc là nó không hoạt động. Tuy nhiên, sử dụng tên được bản địa hóa (như được truy xuất từ liên kết của Mark Ransom trong nhận xét của anh ấy) sẽ hoạt động. Mẫu này nằm trong C#.
using System.Drawing;
namespace FontNameCheckApplication
{
class Program
{
[STAThread]
static void Main(string[] args)
{
Font TimesNewRomanByPSName = new Font("TimesNewRomanPSMT", 16f);
Console.WriteLine("TimesNewRomanPSMT = {0}", TimesNewRomanByPSName.Name);
Font TimesNewRomanByName = new Font("Times New Roman", 16f);
Console.WriteLine("Times New Roman = {0}", TimesNewRomanByName.Name);
Font ArialByPSName = new Font("ArialMT", 16f);
Console.WriteLine("ArialMT = {0}", ArialByPSName.Name);
Font ArialByName = new Font("Arial", 16f);
Console.WriteLine("Arial = {0}", ArialByName.Name);
Font GulimByEnglishName = new Font("Gulim", 16f);
Console.WriteLine("Gulim = {0}", GulimByEnglishName.Name);
Font GulimByKoreanName = new Font("굴림", 16f);
Console.WriteLine("굴림 = {0}", GulimByKoreanName.Name);
Console.ReadKey();
}
}
}
Thật không may, chúng tôi đã thay đầu bằng phông chữ thay vì "Microsoft Sans Serif" chắc chắn không phải là Times New Roman hoặc Arial. Điều này cho thấy rằng tên PostScript không thể được sử dụng đáng tin cậy để tham chiếu cùng một phông chữ.
Dưới đây là kết quả:
TimesNewRomanPSMT = Microsoft Sans Serif
Times New Roman = Times New Roman
ArialMT = Microsoft Sans Serif
Arial = Arial
Gulim = Gulim
?? = Gulim
Cập nhật # 2:
Dưới đây là một ví dụ cho Win32.
Một điều cần lưu ý là CreateFontIndirect()
có thể thay thế. Khi chạy mẫu này, tôi không bao giờ có một tay cầm rỗng, ngay cả đối với tên PostScript. Để xem liệu chúng tôi có thể nhận được một trận đấu không được đặt trước hay không, chúng tôi nên sử dụng EnumFontFamiliesEx()
để quét danh sách phông chữ hệ thống có sẵn. Chúng tôi nhận được kết quả tương tự như C#, nhưng không có thay thế. Đối với một số phông chữ, kết quả có thể tùy thuộc vào cài đặt chế độ đồ họa (xem SetGraphicsMode()
/GM_ADVANCED).
LOGFONT structure (Windows) @ MSDN
CreateFontIndirect function (Windows) @ MSDN
SetGraphicsMode function (Windows) @ MSDN
EnumFontFamiliesEx function (Windows) @ MSDN
EnumFontFamExProc callback function (Windows) @ MSDN
#include "stdafx.h"
#include <Windows.h>
void TestCreateFont(LPCTSTR lpczFontName, BYTE bCharSet)
{
LOGFONT lf;
lf.lfHeight = 0;
lf.lfWidth = 0;
lf.lfEscapement = 0;
lf.lfOrientation = 0;
lf.lfWeight = FW_DONTCARE;
lf.lfItalic = FALSE;
lf.lfUnderline = FALSE;
lf.lfStrikeOut = FALSE;
lf.lfCharSet = bCharSet;
lf.lfOutPrecision = OUT_OUTLINE_PRECIS;
lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
lf.lfQuality = DEFAULT_QUALITY;
lf.lfPitchAndFamily = DEFAULT_PITCH;
// NOTE: LF_FACESIZE = 32, WinGdi.h
_tcsncpy_s(lf.lfFaceName, 32, lpczFontName, _tcsnlen(lpczFontName, 32));
HFONT hf = ::CreateFontIndirect(&lf);
// NOTE: LF_FACESIZE = 32, WinGdi.h
_tprintf_s(_T("TestCreateFont:\r\n%.32s = %.32s, bCharSet=%d, HFONT=0x%8.8x\r\n\r\n"), lpczFontName, lf.lfFaceName, bCharSet, hf);
::DeleteObject(hf);
}
int CALLBACK MyEnumFontFamExProc(const LOGFONT *lpelfe, const TEXTMETRIC *lpntme, DWORD FontType, LPARAM lParam)
{
_tprintf_s(_T(" Found: %.32s, bCharSet=%d\r\n"), lpelfe->lfFaceName, lpelfe->lfCharSet);
return 1;
}
void TestEnumFontFamiliesEx(LPCTSTR lpczFontName, BYTE bCharSet)
{
LOGFONT lf;
lf.lfHeight = 0;
lf.lfWidth = 0;
lf.lfEscapement = 0;
lf.lfOrientation = 0;
lf.lfWeight = FW_DONTCARE;
lf.lfItalic = FALSE;
lf.lfUnderline = FALSE;
lf.lfStrikeOut = FALSE;
lf.lfCharSet = bCharSet;
lf.lfOutPrecision = OUT_OUTLINE_PRECIS;
lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
lf.lfQuality = DEFAULT_QUALITY;
lf.lfPitchAndFamily = DEFAULT_PITCH; // NOTE: DEFAULT_PITCH = 0, WinGdi.h
// NOTE: LF_FACESIZE = 32, WinGdi.h
_tcsncpy_s(lf.lfFaceName, 32, lpczFontName, _tcsnlen(lpczFontName, 32));
_tprintf_s(_T("TestEnumFontFamiliesEx: %.32s, bCharSet=%d\r\n"), lpczFontName, bCharSet);
HDC hdcAll = GetDC(NULL);
::EnumFontFamiliesEx(hdcAll, &lf, &MyEnumFontFamExProc, 0, 0);
}
int _tmain(int argc, _TCHAR* argv[])
{
TestCreateFont(_T("TimesNewRomanPSMT"), DEFAULT_CHARSET);
TestCreateFont(_T("Times New Roman"), DEFAULT_CHARSET);
TestCreateFont(_T("ArialMT"), DEFAULT_CHARSET);
TestCreateFont(_T("Arial"), DEFAULT_CHARSET);
TestCreateFont(_T("Gulim"), DEFAULT_CHARSET);
TestCreateFont(_T("굴림"), DEFAULT_CHARSET);
TestEnumFontFamiliesEx(_T("TimesNewRomanPSMT"), DEFAULT_CHARSET);
TestEnumFontFamiliesEx(_T("Times New Roman"), DEFAULT_CHARSET);
TestEnumFontFamiliesEx(_T("ArialMT"), DEFAULT_CHARSET);
TestEnumFontFamiliesEx(_T("Arial"), DEFAULT_CHARSET);
TestEnumFontFamiliesEx(_T("Gulim"), DEFAULT_CHARSET);
TestEnumFontFamiliesEx(_T("굴림"), DEFAULT_CHARSET);
return 0;
}
Và đây là kết quả:
TestCreateFont:
TimesNewRomanPSMT = TimesNewRomanPSMT, bCharSet=1, HFONT=0xda0a117c
TestCreateFont:
Times New Roman = Times New Roman, bCharSet=1, HFONT=0xdb0a117c
TestCreateFont:
ArialMT = ArialMT, bCharSet=1, HFONT=0xdc0a117c
TestCreateFont:
Arial = Arial, bCharSet=1, HFONT=0xdd0a117c
TestCreateFont:
Gulim = Gulim, bCharSet=1, HFONT=0xde0a117c
TestCreateFont:
?? = ??, bCharSet=1, HFONT=0xdf0a117c
TestEnumFontFamiliesEx: TimesNewRomanPSMT, bCharSet=1
TestEnumFontFamiliesEx: Times New Roman, bCharSet=1
Found: Times New Roman, bCharSet=0
Found: Times New Roman, bCharSet=177
Found: Times New Roman, bCharSet=178
Found: Times New Roman, bCharSet=161
Found: Times New Roman, bCharSet=162
Found: Times New Roman, bCharSet=186
Found: Times New Roman, bCharSet=238
Found: Times New Roman, bCharSet=204
Found: Times New Roman, bCharSet=163
Found: Times New Roman, bCharSet=0
Found: Times New Roman, bCharSet=177
Found: Times New Roman, bCharSet=161
Found: Times New Roman, bCharSet=162
Found: Times New Roman, bCharSet=186
Found: Times New Roman, bCharSet=238
Found: Times New Roman, bCharSet=204
Found: Times New Roman, bCharSet=163
Found: Times New Roman, bCharSet=0
Found: Times New Roman, bCharSet=177
Found: Times New Roman, bCharSet=178
Found: Times New Roman, bCharSet=161
Found: Times New Roman, bCharSet=162
Found: Times New Roman, bCharSet=186
Found: Times New Roman, bCharSet=238
Found: Times New Roman, bCharSet=204
Found: Times New Roman, bCharSet=163
Found: Times New Roman, bCharSet=0
Found: Times New Roman, bCharSet=177
Found: Times New Roman, bCharSet=161
Found: Times New Roman, bCharSet=162
Found: Times New Roman, bCharSet=186
Found: Times New Roman, bCharSet=238
Found: Times New Roman, bCharSet=204
Found: Times New Roman, bCharSet=163
TestEnumFontFamiliesEx: ArialMT, bCharSet=1
TestEnumFontFamiliesEx: Arial, bCharSet=1
Found: Arial, bCharSet=0
Found: Arial, bCharSet=177
Found: Arial, bCharSet=178
Found: Arial, bCharSet=161
Found: Arial, bCharSet=162
Found: Arial, bCharSet=186
Found: Arial, bCharSet=238
Found: Arial, bCharSet=204
Found: Arial, bCharSet=163
Found: Arial, bCharSet=0
Found: Arial, bCharSet=177
Found: Arial, bCharSet=161
Found: Arial, bCharSet=162
Found: Arial, bCharSet=186
Found: Arial, bCharSet=238
Found: Arial, bCharSet=204
Found: Arial, bCharSet=163
Found: Arial, bCharSet=0
Found: Arial, bCharSet=177
Found: Arial, bCharSet=178
Found: Arial, bCharSet=161
Found: Arial, bCharSet=162
Found: Arial, bCharSet=186
Found: Arial, bCharSet=238
Found: Arial, bCharSet=204
Found: Arial, bCharSet=163
Found: Arial, bCharSet=0
Found: Arial, bCharSet=177
Found: Arial, bCharSet=161
Found: Arial, bCharSet=162
Found: Arial, bCharSet=186
Found: Arial, bCharSet=238
Found: Arial, bCharSet=204
Found: Arial, bCharSet=163
TestEnumFontFamiliesEx: Gulim, bCharSet=1
Found: Gulim, bCharSet=0
Found: Gulim, bCharSet=129
Found: Gulim, bCharSet=161
Found: Gulim, bCharSet=162
Found: Gulim, bCharSet=186
Found: Gulim, bCharSet=238
Found: Gulim, bCharSet=204
TestEnumFontFamiliesEx: ??, bCharSet=1
Found: Gulim, bCharSet=0
Found: Gulim, bCharSet=129
Found: Gulim, bCharSet=161
Found: Gulim, bCharSet=162
Found: Gulim, bCharSet=186
Found: Gulim, bCharSet=238
Found: Gulim, bCharSet=204
Dưới đây là một đoạn trích từ 01.cho các giá trị CharSet.
#define ANSI_CHARSET 0
#define DEFAULT_CHARSET 1
#define SYMBOL_CHARSET 2
#define SHIFTJIS_CHARSET 128
#define HANGEUL_CHARSET 129
#define HANGUL_CHARSET 129
#define GB2312_CHARSET 134
#define CHINESEBIG5_CHARSET 136
#define OEM_CHARSET 255
#define JOHAB_CHARSET 130
#define HEBREW_CHARSET 177
#define ARABIC_CHARSET 178
#define GREEK_CHARSET 161
#define TURKISH_CHARSET 162
#define VIETNAMESE_CHARSET 163
#define THAI_CHARSET 222
#define EASTEUROPE_CHARSET 238
#define RUSSIAN_CHARSET 204
#define MAC_CHARSET 77
#define BALTIC_CHARSET 186
Một số ví dụ về các tên phông chữ cục bộ có thể được tìm thấy ở đây: http://www.trigeminal.com/samples/font_choices.html –