[layout-normalizer] Font->glyph name mapping incomplete and at wrong level
simoncozens opened this issue · 2 comments
To provide human-readable output, layout-normalizer maps glyph IDs to glyph names. It does this purely by looking at codepoints and turning codepoints into glyph names using the AGL, defaulting to stringifying the GID for unencoded glyphs. The first place to look for glyph names should be the post
table's glyphNameIndex
, and then potentially the Macintosh glyph list (See the post
table spec), and if there isn't one there, then stringify the GID. (I don't recommend intuiting a glyph name from the cmap table.)
Perhaps read_fonts::tables::post::Post::glyph_name
would be helpful here; and perhaps some mid-level font library (Skrifa?) should have a utility function that maps a glyph ID to post
name if there is one and stringifying the GID if not.
This appears to do the job:
fn gid_to_name<'a>(font: &impl TableProvider<'a>, gid: GlyphId) -> String {
if let Ok(Some(name)) = font
.post()
.map(|post| post.glyph_name(gid).map(|x| x.to_string()))
{
name
} else {
format!("gid{:}", gid)
}
}
good call, not sure why I didn't bother checking post
first, definitely an oversight.