The detectTofu function finds glyphs which are missing from a font (and so are replaced by a replacement character or "tofu").
The current algorithm works as follows:
- Measure the rendered width/height of each character in a test string.
- Compare to a character that is known to be replaced.
- If each character is the same size (including the replacement), then conclude that all characters are missing glyphs.
This works very well for many languages. However, it fails for Chinese, because typically all Han character glyphs in a font are the same size as the replacement character glyph. Also, there is no such thing as a 'complete Han font': there are always missing characters.
Therefore, we should implement a more sophisticated approach:
- Start with the above algorithm for speed.
- Render a character to an HTML canvas.
- Compare its bitmap to the bitmap of the replacement character glyph.
This will allow us to detect exactly which characters are missing, regardless of width/height.
Version: unspecified
Severity: enhancement
See Also:
T33791: Add web fonts for Chinese scripts