Add Unicode support #6
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Well, this was a bit of a rabbit hole, but it's done now. The new font bitmaps will support most of the relevant Unicode codepoints in the two-byte range. I tried it out with a bunch of different languages, and they all seem to work. Performance looks fine in Dub's Performance Analyzer, testing with my rather large mod pack.
The
font-texture/READMEdetails how to re-generate the bitmaps, if you need to do so. Fonts are messy, and Unicode can be finicky in places, but that should cover all of the common problems.Most of the character location code is in
Resources.cs, which is used byGetOffsetsForCharandGetCharBoundsInTextureForinFontHandler.cs. It should hopefully be commented well-enough to follow, but feel free to ask me any questions about it. TheFontBitmapOffsetsis an inversion list, designed to store offsets when the codepoints shift to a different bitmap, or are not included in the textures.The
GetOffsetsForCharfunction can calculate a new character location by walking forward in the block from the nearest codepoint in the dictionary. Then it stashes that entry as an exact location in the dictionary to cache the calculation.At this point, there is room for an "Allow lowercase letters" config switch, since I didn't subtract those out of the bitmaps. There are far far more CJK glyphs than lowercase letters, and if I subtracted those out, the
AaBbCcpattern of Unicode codepoints outside of the ASCII range would have exploded the bitmap offsets dictionary. The switch would be a simple matter of checking eachToUpper()call and theFontHandlershould just work.