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

Support Unicode Bidi-algorithm #2982

Open
Ghabry opened this issue May 2, 2023 · 9 comments
Open

Support Unicode Bidi-algorithm #2982

Ghabry opened this issue May 2, 2023 · 9 comments

Comments

@Ghabry
Copy link
Member

Ghabry commented May 2, 2023

Text can be mixed direction like e.g. mixing Hebrew and English or numbers:

שדחHallo קח42שמ

Player does not apply bidi here as Harfbuzz does not support such mixed-bidi:

screenshot_5

@Ghabry
Copy link
Member Author

Ghabry commented Jul 5, 2024

Actually hooking in ICU BIDI isn't that hard. Quick proof of concept:

Before:

image

After:

image

UErrorCode errorCode = U_ZERO_ERROR;
	UBiDi *bidi = ubidi_open();

	// Set the input text and specify its direction
	auto input = icu_75::UnicodeString::fromUTF32(reinterpret_cast<const UChar32*>(tx.data()), tx.length());

	ubidi_setPara(bidi, input.getBuffer(), -1, UBIDI_DEFAULT_LTR, NULL, &errorCode);

	// Get the visual order of the characters
	int32_t length = ubidi_getProcessedLength(bidi);

	UChar *output = (UChar *)malloc(sizeof(UChar) * (length + 1));

	auto outlen = ubidi_writeReordered(bidi, output, length + 1, UBIDI_DO_MIRRORING, &errorCode);

	icu_75::UnicodeString us(output, outlen);

	std::string s;
	us.toUTF8String(s);

	std::u32string txt = Utils::DecodeUTF32(s);

	free(output);
	ubidi_close(bidi);

@Ghabry
Copy link
Member Author

Ghabry commented Jul 5, 2024

Was also made aware of that in the descriptions the text reads backwards.

That was due to the "half width space" algorithm. Moved this into the Font class to fix this.

Before (top and bottom text should read the same):

image

After:

image

@Ghabry
Copy link
Member Author

Ghabry commented Jul 5, 2024

there is one more complex problem: When a message contains any command codes or ExFont it will have the same "reverse rendering" issue as the help text.

That must be rewritten to shape the entire line in one go and just assign "attributes" like the color to the individual glyphs. Instead of shaping and rendering everytime a command code is encountered.

@Ghabry
Copy link
Member Author

Ghabry commented Jul 8, 2024

Glad that all the Harfbuzz shaping stuff was already implemented over multiple weeks. This made the Bidi implementation pretty straightforward (only needed one day)


Here a message box with bidirectional text. Each text segment flows in based on its direction (is slowed down to show this better, normal message box is much faster).

simplescreenrecorder-2024-07-08_22.10.18.mp4

Command codes work but I havn't fully tested them yet.


@MAZ12211 was so kind to give me a Yume Nikki translation in "the proper way" (how you would type it when the application has proper RTL-Bidi-Support).

Here the current progress (the width calculation is still a bit bugged as you can see from the inconsistent right alignment).

screenshot_2 png

screenshot_0 png

screenshot_1 png

@Ghabry
Copy link
Member Author

Ghabry commented Jul 8, 2024

Also open for discussion is how to "flip" the Ui.

Obviously full RTL support here needs custom code for the more complex windows but just super-simple Ui flipping could be one function call per window:

out

@Ghabry Ghabry added this to the 0.8.2 milestone Jul 8, 2024
@Ghabry
Copy link
Member Author

Ghabry commented Aug 1, 2024

Pushed the current (incomplete) code here: https://github.com/Ghabry/easyrpg-player/tree/bidi

@MAZ12211
Copy link

MAZ12211 commented Aug 7, 2024

I just tested the bidi build with Toilet In Wonderland and Ib and both ended up crashing the Player

explorer_8JOtxATMi2.mp4

I'll assume you need the dmp file

@Ghabry
Copy link
Member Author

Ghabry commented Aug 7, 2024

Actually the dump file doesn't help because I do not have access right now to the computer where I compiled it 😅.

Currently easier is when you provide me with the translation files that crash.

@MAZ12211
Copy link

MAZ12211 commented Aug 8, 2024

Lol alright
I'll send the language folder because I have no clue what caused it to crash either
Toilet In Wonderland
Ib

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants