Implement bidi reordering at display time

I'm now using SheenBidi to reorder RTL and bidirectional text properly
at text rendering time! For Arabic this is still missing reshaping, but
everything's looking really promising now!

The code changes are really non-invasive. The changes to Font.cpp are
absolutely minimal:

     1305+    if (bidi_should_transform(text))
     1306+    {
     1307+        text = bidi_transform(text);
     1308+    }

There's now a FontBidi.cpp, which implements these two functions,
notably bidi_transform(), which takes a UTF-8 encoded string and
returns another UTF-8 encoded string that has bidi reorderings and
reshapings applied.

In that function, SheenBidi gives us information about where in the
input string runs start and end, and on a basic level, all we need to
do there is to concatenate the parts together in the order that we're
given them, and to reverse the RTL runs (recognizable by odd levels).

As this is a proof-of-concept, bidi_should_transform() still always
returns true, applying the bidi algorithm to all languages and all
strings. I'm thinking of enabling bidi only when the language/font
metadata enables RTL (which could be for the interface or for a custom
level), or outside of that, at least when RTL characters are detected
(such as Arabic or Hebrew Unicode blocks).
This commit is contained in:
Dav999
2024-01-02 03:57:26 +01:00
committed by Misa Elizabeth Kai
parent 5766e6c426
commit 59ccdbea00
4 changed files with 139 additions and 0 deletions

View File

@@ -77,6 +77,7 @@ set(VVV_SRC
src/FileSystemUtils.cpp
src/Finalclass.cpp
src/Font.cpp
src/FontBidi.cpp
src/Game.cpp
src/Graphics.cpp
src/GraphicsResources.cpp