openharmony 鸿蒙 text-faqs

2026-08-25 浏览 (1)

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 NotEffect
Disabledimage_undefined_off_ts
Enabledimage_undefined_on_ts

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 text-overview

openharmony 鸿蒙 complex-text-c

openharmony 鸿蒙 geometric-shape-drawing-arkts

openharmony 鸿蒙 native-fence-guidelines

openharmony 鸿蒙 native-vsync-guidelines

openharmony 鸿蒙 displaysync-overview

openharmony 鸿蒙 custom-font-c

openharmony 鸿蒙 system-font-c

openharmony 鸿蒙 canvas-get-result-draw-arkts

openharmony 鸿蒙 primitive-drawing-overview

  • 所属分类: 后端技术
  • 本文标签: 鸿蒙 软件
  • 版权声明: 本文链接 https://seaxiang.com/blog/QqRmC6lm