87ac051e创建于 2025年10月29日历史提交

Text Development FAQs

How Do I Optimize the Display of Text with an Undefined Glyph?

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 "\uffffHello World\uffff" text as an example. \uffff indicates text with an undefined glyph.

The following figures show the comparison.

Display Optimization Enabled or Not Effect
Disabled image_undefined_off_ts
Enabled image_undefined_on_ts