Currently, the undefined glyphs are displayed as blanks by default, which may confuse users.
The system provides a switch, which can display undefined glyphs as tofu blocks once enabled.
In ArkTS, you can use the setTextUndefinedGlyphDisplay API to enable the display of undefined glyphs as tofu blocks.
import { text } from "@kit.ArkGraphics2D";
text.setTextUndefinedGlyphDisplay(text.TextUndefinedGlyphDisplay.USE_TOFU); In C/C++, you can use the OH_Drawing_SetTextUndefinedGlyphDisplay API to enable the display of undefined glyphs as tofu blocks.
#include "drawing/drawing_text_global.h" OH_Drawing_SetTextUndefinedGlyphDisplay(TEXT_NO_GLYPH_USE_TOFU);
The preceding two APIs control the same switch. You can use either of them.
Take the text "\uffffHello World\uffff" as an example, where \uffff represents a character with a missing glyph.
The following figures show the comparison.
| Display Optimization Enabled or Not | Effect |
|---|---|
| Disabled | ![]() |
| Enabled | ![]() |