godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.11k stars 69 forks source link

Add a tag for Furigana in RichTextLabel #5876

Open lpares12 opened 1 year ago

lpares12 commented 1 year ago

Describe the project you are working on

Developing a Japanese learning app/game.

Describe the problem or limitation you are having in your project

The Japanese language relies on this thing called Furigana, which basically is a text on top of Kanji to display its pronunciation. You can see an example here. As you can see in the image, a Kanji 私 has the text わたし on top, which defines the reading of the Kanji.

This is used in all reading materials (books, newspapers, games,...) broadly, meaning any app or game that uses the Japanese language will be using Furigana at some point, and currently there is no easy way to implemt this in Godot. You could technically overlap labels on top of a RichTextLabel containing Kanji. But then you would need to manually modify line heights of the lines in the RichTextLabel to accomodate space for the furigana.

There is no good current solution to do this right now. In my case I need to display Furigana so users know how to pronounce the Kanji that they learn in my game.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

My idea is to add a [furigana] tag in RichTextLabel's BBCode. The user will be able to add bbcode_text such as:

hello, this is a [furigana=brief]example[/furigana]

To display something like: hello, this is a example with the brief word centered on top of the work example in a smaller font.

And also a new font entry (furigana_font) will be added to the theme of RichTextLabel, since 99% of the times the font for the Furigana will be smaller than the normal text.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

You can see an example of how this is implemented in: https://github.com/lpares12/godot/commits/feat_furigana which is based on the current (30/11/2022) 3.5 branch of godotengine repo.

And this is how it looks in the editor.

Screenshot from 2022-11-30 11-27-31

For the bbcode_text This is a furigana demo [furigana=abc]attached[/furigana]. You can see abc on top of the word "attached"

Screenshot from 2022-11-30 11-29-25

For now this implementation does not support effects and so on, and whenever the Furigana is bigger than the text, it will move out of the container and be "cut".

If this enhancement will not be used often, can it be worked around with a few lines of script?

No, this is not something easy to workaround. And I can't think of any way to do this that does not take a lot of hours to implement.

Is there a reason why this should be core and not an add-on in the asset library?

Because this will open up a lot of possiblities for Japanese games and apps to be developed with Godot. As I said before, this is a must-have tool for Japanese games. Mostly all books have this, even for Japanese native speakers, so this is not only used for japanese learning purposes.

I'm not sure this can be easily integrated as an add-on or plugin, since it is necessary to change the line-height of individual lines within a RichTextLabel and break lines when the word does not fit in the line. Maybe someone with a bit more experience could do this, but for me it was easier to just implement it into the code.

lpares12 commented 1 year ago

By the way, I spoke with someone in the godot contributors chat and I was told new features should be added to Godot 4.x and be backported to 3.x, but unless this is gonna be integrated I prefer not to spend time doing it for Godot 4.x (since I currently don't use it). That's why for now the feature I made is base on 3.5 branch.

YuriSizov commented 1 year ago

By the way, I spoke with someone in the godot contributors chat and I was told new features should be added to Godot 4.x and be backported to 3.x, but unless this is gonna be integrated I prefer not to spend time doing it for Godot 4.x (since I currently don't use it). That's why for now the feature I made is base on 3.5 branch.

Without an implementation for 4.x no new feature will be merged. We don't want to create discrepancy between versions such that different branches start to diverge from each other. Also keep in mind that implementing this for 4.x and for 3.x would be very different.

lpares12 commented 1 year ago

You are right, there are some resemblances but it is true that some things have changed a lot. That's why I do not plan to do it for Godot 4 for now, if it's not gonna be added, since I'm using Godot 3 and I can use my fork for that. But still other people will benefit from this addition.

And I don't mind porting it myself if it's gonna be added.

Psychpsyo commented 1 year ago

I'd suggest using [ruby][/ruby] as the bbcode for this instead of [furigana][/furigana]. Ruby text is the more general term for this concept when applied to more than just Japanese, like Korean or Chinese.

Additionally it'd be the same terminology that HTML uses for this with its \<ruby> tag. (although their version is a bit more complicated)

lpares12 commented 1 year ago

Changing it to ruby sounds good to me. I did not know about it, but if it's a general term for other languages too, makes total sense.