Skip to main content

Colored Glyph Support

With the integration of Monotype’s iType library, the CGI Studio text engine now supports colored bitmaps from the CBDT table of truetype/opentype fonts.

Scope of new functionality

  • Monotype must be configured as a font engine (for further details, please reference the CMake configuration section below)
  • TextNode2D must be used (this feature is not supported with CanvasText, or by the deprecated TextEffect)
  • Two renders are available for TextNode2D when using Monotype: Bitmap and GlyphAtlas. The option Bitmap must be used.
  • Colored glyph bitmaps are taken from the font file in their raw format. No scaling is applied. To match different font sizes, you will need to add different sized glyph bitmaps to the font file.
  • Text color will always be applied as color multiplication. For this reason, the colored bitmaps are colorized with the text color. Only white text color will preserve the colors from the original image.

CMake configuration

  • Choose Monotype for CANDERA_FONTENGINE
  • Activate the new flag CANDERA_TEXTENGINE_COLORBITMAP_ENABLED

A third party library ”lodepng” has been added to decode images in PNG format, and is licensed under the ”zlib License”. This library is available within the cgi_studio_3psw folder, with its path set to the CMake variable CGISTUDIO_LODEPNG_INCLUDE_PATH.

Cache: You can change the cache size for the maximum number of cached colored bitmap elements. The macro is defined as: CANDERA_TEXTENGINE_COLORBITMAP_CACHE_ELEMENT_COUNT - default value: 20 This macro can be changed using a compiler flag (-D... or cmake add_definitions). Alternatively, you can directly add this macro to the generated config headers.

The colored glyphs will use a 32 bit per pixel RGBA format, while regular glyphs use an 8 bit per pixel alpha format. If a text contains one or more colored glyphs, the bitmap generated by TextNode2D will be in RGBA format. As a result, bitmaps generated by TextNode2D instances containing colored glyphs will require 4 times the necessary memory required by TextNode2D instances without colored glyphs. Colored glyphs are cached internally by the text engine in RGBA format. This cache also contributes to increased memory consumption.