Bug/Feature(?): make a version of find_glyph
for ttf::Font
that supports characters beyond the Basic Multilingual Plane #1383
Open
Description
The current implementation of find_glyph
for ttf::Font
looks like this:
/// Returns the index of the given character in this font face.
pub fn find_glyph(&self, ch: char) -> Option<u16> {
unsafe {
let ret = ttf::TTF_GlyphIsProvided(self.raw, ch as u16);
if ret == 0 {
None
} else {
Some(ret as u16)
}
}
}
There is a major problem with this: if the input char is something like the 🤣
emoji (which has a numerical value of 129315
), it'll get cast to u16
and become 63779
. This can then lead to false positives, where fonts say that they support a UTF-8 codepoint, when they do in fact not; and vice versa for fonts that aim to only support emoji-like characters (like plane 1 in GNU Unifont).
The solution to this would be simple: either patch this function to use TTF_GlyphIsProvided32 instead (and without the u16
cast), or make a separate function called find_glyph_32
.
Please fix this! It would be enormously helpful.