Sub6Resources / flutter_html

A Flutter widget for rendering static html as Flutter widgets (Will render over 80 different html tags!)
https://pub.dev/packages/flutter_html
MIT License
1.76k stars 815 forks source link

Ruby (Furigana) on Android with a big font #387

Closed Larpoux closed 3 years ago

Larpoux commented 3 years ago

Hi,

Here is my code :

child: Html
 (

             data: '<div><ruby>私<rt>わたし</rt></ruby>は<ruby>週末<rt>しゅうまつ</rt></ruby>に<ruby>野球<rt>やきゅう</rt></ruby>をする。</div>',
             style:
             {
                             "div": Style
                             (
                                             backgroundColor: Colors.white,
                                             fontSize: FontSize(30),
                                             fontFamily:  "Hiragino Kaku Gothic Pro",
                             ),
                             "b": Style(color:HighLightColor),
             },
)

The rendering is fine on iOS (see the enclosed screenshot), but is bad on Android (see the other enclosed screenshot) : The furigana annotation is almost completely eaten.

Note : with a fontSize: FontSize(13), the rendering is OK, but the text is really too small to be readable.

Please, tell me if I can do something to fix that. Furigana is very, very important for us. Eaven a hard dirty patch into the code would be OK.

On iOS :

Screenshot 2020-08-20 at 07 09 33

on Android :

Screenshot 2020-08-20 at 07 13 22
Larpoux commented 3 years ago

Does someone have any news about this PR (Problem Report) ? Thank you.

Larpoux commented 3 years ago

Any news for this Problem Report ?

Larpoux commented 3 years ago

Does someone have any news about this PR (Problem Report) ? Thank you.

erickok commented 3 years ago

As I have no real understanding of typesetting of Ruby,I couldn't even know what the problem is, let alone since it. It's this something that works with plain Text widget in Flutter? Could you explain in more detail what the problem is. Sorry for the lack of understanding. I only know latin languages.

tneotia commented 3 years ago

I think I see what you mean... iOS: image vs Android: image It seems cut off. I'll try soon to workout what is going on here.

Larpoux commented 3 years ago

Yeah ! Thank you so much if you can do something for that. We will ship our App in 3 months and this problem was very serious for us. I was about to dive into flutter_html code to try to find a fix, but I guess that flutter_html is a very complicated plugin. And Ruby/Furigana support is probably a very tricky code inside flutter_html.

Thank again if you can do something.

tneotia commented 3 years ago

Hi @Larpoux , I did some preliminary testing just now and it seems like your problem is because you are setting backgroundColor in your Style for <div>. When I removed the background color the Ruby displayed fine - I don't know if this is a good solution for you, nevertheless this shouldn't be happening so I will try to fix it.

Larpoux commented 3 years ago

Thank you very much @tneotia for spending time on this PR.

Yes, it is acceptable not to use backgroundColor. This is much better than having furigana eaten 😆 .

tneotia commented 3 years ago

Yea, this is very weird. I cannot reproduce it anymore with your code on my physical device. It could be an issue with the emulator?

image

This is the exact same code you gave me and I made no changes to the library. @erickok could you check this out on your end too (if you have an Android)?

Larpoux commented 3 years ago

HI @tneotia ,

I did several tests with flutter_html 1.2.0.

A- On an emulator

1. iOS, with backgroundColor:

ios

2. Android, with backgroudColor:

android-without-bg

3. iOS, without backgroundColor:

ios-without-bg

4. Android, without bacgroundColor:

android-without-bg

Those tests shows that the Ruby text does not seem to be eaten by the emulators by flutter_html, but we have a (new?) problem with continuation lines.

B- On a real device, without backgroundColor:

The furigana is eaten, and the continuation lines are too high toto

My code

Html//Widget

(               
                data :'<div>' +
                (
                          //_japExample
                          '<ruby>私<rt>わたし</rt></ruby>は<ruby>週末<rt>しゅうまつ</rt></ruby>に<ruby>野球<rt>やきゅう</rt></ruby>をする。' +
                           '<ruby>私<rt>わたし</rt></ruby>は<ruby>週末<rt>しゅうまつ</rt></ruby>に<ruby>野球<rt>やきゅう</rt></ruby>をする。' +
                           '<ruby>私<rt>わたし</rt></ruby>は<ruby>週末<rt>しゅうまつ</rt></ruby>に<ruby>野球<rt>やきゅう</rt></ruby>をする。'
                ) + '</div>',

                style:
                {
                            "div": Style
                             (
                                        //!!!!!!!!!!!!!!!backgroundColor: sound.isPlaying( audio ) ? LightSelected : Colors.white,
                                        fontSize: FontSize(16),
                                        fontFamily:  "Hiragino Kaku Gothic Pro",
                              ),
                              //!!!!!!!!!!!!!!!!!!!!!!!!!!!!"b": Style(color:HighLightColor),
                },
 )
tneotia commented 3 years ago

@Larpoux I think increasing the lineHeight for <ruby> in <style> will probably fix the issue, since the "main" ruby lines are typset properly, there just is not enough space for the small characters above the "main" lines. I still think that we should try and solve this properly though without any workaround, this data is helpful and I'll look into it some more. In the meantime can you try lineHeight like this: lineHeight: LineHeight(2.4) in your Style for <div>?

Also your default background color should be Colors.transparent to make sure Furigana isn't eaten when rendered.

Larpoux commented 3 years ago

@tneotia , Yes, lineHeight: parameter was the solution (I did not know this parameter before).

Actually, Ruby/Furigana is now OK, except a little problem : on iOS, the characters that do not have Furigana annotation above are too high. But it is OK on Android. This is a small detail, and we can live with that ;-) . Thank you @tneotia for the time you have spent on this Issue.

Here are the result on iOS :

Screenshot 2021-02-12 at 17 29 09

And here the result on Android :

Screenshot_2021-02-12-17-27-31-323_com dyglot dyglot

tneotia commented 3 years ago

Sure, no problem, glad it worked. You can increase or decrease the lineHeight number as you wish, 1.2 is default so I asked you to double it for testing. Just know this will also affect English text, which will have the spacing you see between the big font size characters (I guess those are called Ruby).

tneotia commented 3 years ago

@erickok this can be closed I think.