minetest / blog

Minetest's official blog - see what's new in Minetest!
https://blog.minetest.net/
MIT License
17 stars 9 forks source link

[content] Unicode Text Rendering #129

Closed erlehmann closed 1 year ago

erlehmann commented 1 year ago

Blog Section

Mods News

Please enter your content.

erle created a Unicode text rendering library named unicode_text for both fixed-width and variable-width font-rendering. The input is UTF-8 encoded text, the output is a pixels table that can be written to an image file using the tga_encoder library. This allows users to modify the pixels and write monochrome or colormapped bitmaps if full RGBA colors are not desired. Fonts can be loaded in the GNU Unifont .hex file format.

Existing signs code often uses one image file per character and combines them using texture modifiers. By rendering text to a single image server-side, the full range of Unicode can be supported by servers without sending tens of thousands of small images (or, alternatively, fewer-but-much-bigger textures) to Minetest clients. Using Unifont CSUR, it is also possible to render non-Unicode text written in Tengwar, Klingon, or Sitelen Pona (a Toki Pona writing system).

cora has already created a signs mods named uc_signs that pairs unicode_text with a clever delivery mechanism discovered by ROllerozxa: As the [png texture modifier just hands off image data to the engine to render and does not validate the input is actually in PNG format, it can be used to inline any type of image the engine supports. This approach avoids any bookkeeping issues and race conditions associated with dynamic media loading, but requires at least Minetest 5.5 clients. The mini-mod sitelen_pona_signs shows how the uc_signs API can be used to register custom signs.

Working on unicode_text, erle found that compressing TGA files using zlib can be a fast way to create images with a smaller filesize than even PNG files optimized with optipng. This unintuitive result could enable future Minetest servers to reduce transfer size for generated textures by up to 95% while keeping backwards compatibility with older clients – just by combining two features that have been part of Minetest for many years.

Add relevant details

unicode_text on MeseHub: https://git.minetest.land/erlehmann/unicode_text unicode_text on ContentDB: https://content.minetest.net/packages/erlehmann/unicode_text/ uc_signs on Codeberg: https://codeberg.org/cora/uc_signs uc_signs on ContentDB: https://content.minetest.net/packages/cora/ucsigns/ sitelen_pona_signs on Codeberg: https://codeberg.org/cora/sitelen_pona_signs Proposal to create small texture files fast with zlib + TGA: https://github.com/minetest/minetest/issues/13795

“Screenshot”

This is some example text I rendered that shows rendering for different writing systems, including Emoji.

screenshot of unicode_text screenshot of uc_signs

erlehmann commented 1 year ago

Here is an in-game screenshot of the unicode_text_test mod:

minetest-mod-unicode-text-test

erlehmann commented 1 year ago

Here are a small and a big example text rendering (either use the small one or crop the big one as desired):

test

example

GreenXenith commented 1 year ago

Thank you for your submission! August/September blog post is now published (68d2055).