Skip to content

Conversation

@SineSwiper
Copy link

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/README details 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 by GetOffsetsForChar and GetCharBoundsInTextureFor in FontHandler.cs. It should hopefully be commented well-enough to follow, but feel free to ask me any questions about it. The FontBitmapOffsets is an inversion list, designed to store offsets when the codepoints shift to a different bitmap, or are not included in the textures.

The GetOffsetsForChar function 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 AaBbCc pattern of Unicode codepoints outside of the ASCII range would have exploded the bitmap offsets dictionary. The switch would be a simple matter of checking each ToUpper() call and the FontHandler should just work.

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.

1 participant