How do I know if a true font has a code above 0xFFFF?
There is an API (GetFontUnicodeRanges / GetGlyphIndices) in there, but it does not exceed 0xFFFF as I suspect you know.
There are two obvious methods for searching programmatically:
- Parse the file
.ttf
( spec open-ish) - Try to measure the output characters you are interested in and compare the measurements to a known replacement character.
This answer has a .NET / C # solution: Get Supported Font Characters - in C #
source to share
If you are using Windows 7+, you can call DirectWrite IDWriteFontFace::GetGlyphIndices
to get the nominal glyph id from the cmap of the given code points, or IDWriteFontFace1::GetUnicodeRanges
(either Win 8+ or Windows 7 Platform Update) if you just want to know all the ranges. GDI GetGlyphIndices
and Uniscribe ScriptGetCmap
only support the basic multilingual plane.
source to share
ScriptShape
API to the rescue. Windows 7 and higher. In contrast ScriptGetCMap
, it supports UTF-16 surrogate pairs. Glyph index zero is returned for unsupported font characters.
The example below assumes one line of glyph. All buffers are static. See 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);
source to share