How do we know if a true type font has code points above 0xFFFF?
There's an API (GetFontUnicodeRanges/GetGlyphIndices), but it doesn't go above 0xFFFF, as I suspect you know.
There are 2 obvious methods for finding out programatically:
.ttf
file ( the spec is open-ish)This answer has a .NET/C# solution: Get supported characters of a font - in C#
If running Windows 7+, you can call DirectWrite's IDWriteFontFace::GetGlyphIndices
to get the nominal glyph id's from the cmap of given code points, or IDWriteFontFace1::GetUnicodeRanges
(either Win 8+ or Platform Update for Windows 7) if you just want to know all the ranges. GDI GetGlyphIndices
and Uniscribe ScriptGetCmap
supported only the basic multi-lingual plane.
ScriptShape
API to the rescue. Windows 7 and higher. Unlike ScriptGetCMap
, it supports UTF-16 surrogate pairs. For unsupported by the font characters, it returns a zero glyph index.
The sample below assumes a one glyph string. The buffers are all static. See the API docs for buffer size requirements.
wchar_t ws[] = L"𠀋"; // Known astral plane character
SelectObject(hDC, hFont); // Font to analyze - construct your own
SCRIPT_CACHE ScCache = nullptr; //One of those per font, per size.
HRESULT hr;
SCRIPT_ITEM si[3]; // Static buffers here :(
int ci;
WORD Glyphs[10], Clust[10];
SCRIPT_VISATTR sva[10];
hr = ScriptItemize(ws, wcslen(ws), 2, nullptr, nullptr, si, &ci);
int ng;
hr = ScriptShape(hDC, &ScCache, s, s[1] ? 2 : 1, _countof(Glyphs), &si[0].a, Glyphs, Clust, sva, &ng);
// For the win!
bool FontSupportsThisGlyph = (ng == 1 && Glyphs[0] != 0);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.