Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Full (yet lightweight) Unicode Plane 0 support (60000+ characters!) #46

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

syimyuzya
Copy link

@syimyuzya syimyuzya commented Dec 4, 2021

(See screenshot in unifont/README.md)

This PR adds support for compact, texture sheet based font to font_api, and includes a new font mod unifont that supports 60000+ Unicode characters and weighs only ~1MB (even smaller than Metro!). Edit: ~2MB now in order to improve rendering performace.

Changes made to font_api (also documented in font_api/API.md):

  • A new optional parameter getglyph in font registration: It allows a font mod to construct its own glyph texture string (e.g. using ^[sheet) instead of the default font_{name}_{codepoint}.png.

    This allows large, compact (and better compressed) sheets to be used instead of individual glyph files for a very large number of glyphs. (In comparison, the font_jp_noto mod weighs ~31MB with ~20000 chars)

  • The texture string returned by Font:render, when used in formspec, are now required to be escaped (minetest.formspec_escape).

    This should have been done already even before this PR since texture strings, by its nature, might confuse the formspec parser anyway.

The newly added font "unifont" uses GNU Unifont, the same font also used in Minecraft (and also in texture sheet form) for Unicode display.

unifont/init.lua Outdated
end
local x = codepoint % 256
local y = math.floor(codepoint / 256)
return string.format("unifont_sheet.png^[sheet:256x256:%d,%d", x, y)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to consider renaming unifont_sheet.png to something shorter, e.g. unifont.png in order to keep the resulting texture strings as short as possible (important for reducing the network load).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have now split the sheet into 256 pages, filenames are now unif_XX.png.

This also fixes the ~1sec freeze on initial texture loading. Mod size is now ~2MB, though.

Now 256 sheets, 16x16 chars each (same as Minecraft), instead of one
huge sheet.

This greatly improves performance on initial texture loading (total
size also grows to ~2MB, though).

Filenames are now `unif_XX.png` (XX for codepoint's higher byte in hex
form).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants