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

BUG that Khmer language displays incorrectly using ttf text #2249

Open
cxcxiaochuan opened this issue Nov 26, 2024 · 29 comments
Open

BUG that Khmer language displays incorrectly using ttf text #2249

cxcxiaochuan opened this issue Nov 26, 2024 · 29 comments

Comments

@cxcxiaochuan
Copy link

The framework displays Khmer TTF text content incorrectly. The text content pattern displayed is different from the original text content pattern that needs to be displayed, and the Khmer TTF text content is easily triggered

AXLOG("LabelTextFormatter error: can't find letter definition in font file for letter: 0x%x",character);

@rh101
Copy link
Contributor

rh101 commented Nov 26, 2024

Can you please show screenshots of actual and expected output?

Also, are you able to provide the TTF font file that you use for the Khmer text?

@cxcxiaochuan
Copy link
Author

Can you please show screenshots of actual and expected output?

Also, are you able to provide the TTF font file that you use for the Khmer text?

OK, wait a minute.

@cxcxiaochuan
Copy link
Author

The original text on the button below is as follows:ចាប់ផ្តើម

But the content displayed by the program becomes the following screenshot
屏幕截图 2024-11-26 131948

@cxcxiaochuan
Copy link
Author

This is the Khmer ttf file our app uses:
NotoSansKhmer-SemiBold.zip

@rh101
Copy link
Contributor

rh101 commented Nov 26, 2024

Can reproduce this issue.

Just as a test, using the system font, it displays correctly:
image

@cxcxiaochuan
Copy link
Author

Yes, it will display correctly when using system characters, but will display incorrectly when using ttf characters.

@rh101
Copy link
Contributor

rh101 commented Nov 26, 2024

After looking into this, and as a complete guess, the problem may be in Label::multilineTextWrap or FontAtlas::prepareLetterDefinitions, but I'm not familiar with the logic to figure out why.

Also, the text that reproduces the issue can be narrowed down to the following:
ផ្តើ

which ends up rendering as:
image

The problem could also be that the generated font atlas has bitmaps of the individual glyphs that would be combined to make up that character, but once they are in the font atlas, they look nothing like what they should be when combined together. So, the rendering code is attempting to create a single ផ្តើ from individual bitmaps, and I don't understand how that would ever work, since they're all bitmap images of individual characters. This is all assuming that the FontAtlas contains bitmaps, and that I am not confused about how it works (please correct me if I'm wrong).

@rh101
Copy link
Contributor

rh101 commented Nov 27, 2024

@DelinWorks You may have some insight into this issue. Would something like this require a shaping engine (like Harfbuzz)?

@smilediver
Copy link
Contributor

smilediver commented Nov 27, 2024

Text layout that Label is doing is really primitive, I don't think it will support complex languages with heavy use of diacritics, or where multiple unicode characters combine into the single one glyph, or has ligatures, etc. It only works for "simple" languages that mostly directly translate unicode's characters to visual glyphs. Diacritics may work in some cases, but probably heavily depends on the font.

I'm afraid that the only solution is to use some kind of library, where you can supply your text and get a ready image for use. Or have a custom label implementation that would support the languages you need, but that's a lot of work. Maybe using system fonts could also work.

@cxcxiaochuan
Copy link
Author

This kind of small language is a problem. The language is too complicated. We can't understand the basic grammar and rules of the language at all, and we can't modify it specifically. We might as well give up supporting this language. Anyway, the target population of this small language is relatively small.

@cxcxiaochuan
Copy link
Author

Need to close this issue? We discard revisions to this issue.

@DelinWorks
Copy link
Contributor

@rh101 it's similar to vowels in the arabic language, like عَ اٍ رْ
these are 0 width characters that have worked great with me in axmol.
I really don't know this khmer language so I can't make assumptions on how it works and if it needs a shaping engine like in the arabic lanuage

@DelinWorks
Copy link
Contributor

Have you guys looked into harfbuzz? or in the unicode list https://www.compart.com/en/unicode/
and try to find out if your language have some kind of pattern to how it's displayed?
this is what I did for the arabic shaping engine but then again I can't really tell on a language I don't know

@cxcxiaochuan
Copy link
Author

Haven't watched harfbuzz.

@cxcxiaochuan
Copy link
Author

Does the axmol engine support Arabic TTF fonts?

@smilediver
Copy link
Contributor

Arabic is right to left and there's no support for right to left languages.

@DelinWorks
Copy link
Contributor

yes, axmol does support Arabic script TTF fonts, but the text will look "unconnected" and you would need to use a shaping engine like harfbuzz, I've coded a simple Arabic shaping engine for axmol a while back https://github.com/DelinWorks/arabic-text-renderer-cpp-axmol and it works great, only in the Arabic language category like Persian , Urdu, Pashto, Kurdish and Malay but some modifications have to be made

@DelinWorks
Copy link
Contributor

DelinWorks commented Nov 27, 2024

@smilediver

Arabic is right to left and there's no support for right to left languages.

there's an option in axmol to view text RTL, but as long as you shape your text you won't really need this
label->setHorizontalAlignment(TextHAlignment::RIGHT);

@cxcxiaochuan
Copy link
Author

Thanks

@smilediver
Copy link
Contributor

Does it really? I think it just aligns text to the right side, but in Arabic "abc" needs to be displayed as "cba". I don't think there's support for that, unless I'm mistaken. And it's even more complicated than just reversing letters as you know. :)

@DelinWorks
Copy link
Contributor

DelinWorks commented Nov 27, 2024

yes, that's what the shaping engine does, it reverses it like "cba" instead of "abc" so it looks right for Arabic, it also does connectives like بـت instead of ب ت

@cxcxiaochuan
Copy link
Author

There is no way. Arabic writing is different from Chinese, English, Japanese and other languages. It is in the opposite direction.

@DelinWorks
Copy link
Contributor

DelinWorks commented Nov 27, 2024

what do you mean there's no way? I was able to achieve it in axmol pretty easily,
even if it's in opposite direction that's not a big issue, just reverse the text and add connectives and that's basically what shaping is, this is how every major OS does it, including harfbuzz library.

@DelinWorks
Copy link
Contributor

DelinWorks commented Nov 27, 2024

if you were talking about axmol supporting it right out of the box then no axmol doesn't, but that doesn't mean libraries like harfbuzz can't exist

@cxcxiaochuan
Copy link
Author

It would be better if the Arabic TTF could be integrated into axmol, but it doesn't matter if it can't be integrated. The current TTF is sufficient anyway. It's just that the display in some places does not conform to the habits of Arabs. They should be able to understand it in the context. After all, most of the information they come across on the Internet is from left to right.

@rh101
Copy link
Contributor

rh101 commented Nov 27, 2024

It would be better if the Arabic TTF could be integrated into axmol, but it doesn't matter if it can't be integrated. The current TTF is sufficient anyway. It's just that the display in some places does not conform to the habits of Arabs. They should be able to understand it in the context. After all, most of the information they come across on the Internet is from left to right.

I'm not sure what you mean by some of those remarks, but they can be misconstrued. It's also off-topic, since this issue isn't about the Arabic language or Axmol support for it. As @DelinWorks has explained, using the Harfbuzz library, support can be added on top of Axmol or any other engine in order to generate the correct output.

If you wish to go down that path of using Harfbuzz, then look into DelinWorks' own project that was linked above to get some idea of how to implement it.

Other than that, I'm not sure that anything more can be done to fix this in Axmol at this point in time. Perhaps in the future it will be revisited, but it's not something trivial to implement.

@cxcxiaochuan
Copy link
Author

OK

@DelinWorks
Copy link
Contributor

DelinWorks commented Nov 27, 2024

It would be better if the Arabic TTF could be integrated into axmol, but it doesn't matter if it can't be integrated. The current TTF is sufficient anyway. It's just that the display in some places does not conform to the habits of Arabs. They should be able to understand it in the context. After all, most of the information they come across on the Internet is from left to right.

I'm not sure what you mean by that, it's off topic. but yeah it should be easy to implement for any other language, just different complex rulesets, with the renderer at your disposal along with an open source codebase, the sky is the limit for what you can do!

@cxcxiaochuan
Copy link
Author

Sorry, I got off topic and jumped to another question.

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

4 participants