tom5454 / Toms-Peripherals

MIT License
14 stars 2 forks source link

Fix non-ASCII characters support of text drawing #17

Closed xuhao148 closed 1 month ago

xuhao148 commented 1 month ago

Currently unicode_page_**.bin font files won't work, because their codepoint tables contain their actual unicode codepoints (e.g. unicode_page_53.bin declares that it contains glyphs from 5300 to 53FF), but CC-Tweaked's Lua backend always decodes the Lua string into 8-bit characters (0000 - 00FF) only, which means the non-ASCII characters will be split into multiple individual characters and never hit any of their codepoints.

I suggest two ways of fixing this:

The first would be,

  1. Add a new drawTextUTF8 method, which converts the given String into a byte array, decode the byte array with UTF-8 and do the same as drawText method.
  2. Merge unicode_page_**.bin into one single file.

The second would be,

  1. Keep the unicode_page_**.bin files unmerged, but remap every codepoint maps into 0000 - 00FF.
  2. Users can then write a Lua function theirselves to parse the UTF-8 string, where they switch to the font according to the high word of one Unicode character and draw the low word as an 8-bit character.