4

How do we know if a true type font has code points above 0xFFFF ?

0

3 Answers 3

2

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:

  1. Parse the .ttf file (the spec is open-ish)
  2. Try and measure the output of the characters you are interested in and compare the measurements to the known replacement character

This answer has a .NET/C# solution: Get supported characters of a font - in C#

1
  • What is the 'known replacement character'? It isn't U+FFFD, at least not always. Aug 17, 2016 at 17:28
0

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.

0

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);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.