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

How to handle mixed left-to-right and right-to-left text? #472

Open
slouken opened this issue Jan 27, 2025 · 3 comments
Open

How to handle mixed left-to-right and right-to-left text? #472

slouken opened this issue Jan 27, 2025 · 3 comments
Milestone

Comments

@slouken
Copy link
Collaborator

slouken commented Jan 27, 2025

If you have a string with "some latin chars ... some arabic chars.. " you probably have to use multiple fonts, but also change left-to-right and right-to-left rendering.

Also, beside LTR/RTL, you may also want to change style (italic bold etc), size, breaking, hyphenation, or justification

interesting links:

Unicode Bidirectional Algorithm: https://www.unicode.org/reports/tr9/

What HarfBuzz doesn't do: https://harfbuzz.github.io/what-harfbuzz-doesnt-do.html

Originally posted by @1bsyl in #362

@slouken
Copy link
Collaborator Author

slouken commented Jan 27, 2025

More information on using ICU to handle this:
https://unicode-org.github.io/icu-docs/apidoc/released/icu4c/ubidi_8h.html#details

@slouken
Copy link
Collaborator Author

slouken commented Jan 27, 2025

So you can potentially implement this on top of the SDL_ttf 3.0 API, using text objects and TTF_SetTextPosition() to align them correctly.

@slouken
Copy link
Collaborator Author

slouken commented Jan 28, 2025

I've updated SDL_ttf's right-to-left language support. It doesn't do the full BiDi algorithm, but if you've split your text into multiple single-direction runs it should handle them correctly. You can call TTF_SetTextDirection() to explicitly set the direction if you're using text objects, but if you've split them properly HarfBuzz should be able to detect the correct flow direction.

@slouken slouken added this to the 3.x milestone Jan 28, 2025
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

No branches or pull requests

1 participant