Android Question MeasureMultilineTextHeight error for Chinese words?

Hello. When I try to adjust the height of a label view containing Chinese words, sometimes the height cannot be adjusted correctly. Is it my coding error or intrinsic problem? Thank you :)

B4X:
Sub Globals
    Dim Lb1 As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
    
    Dim su As StringUtils
    Lb1.Initialize("")
    Lb1.Gravity=Bit.Or(Gravity.TOP,Gravity.CENTER_HORIZONTAL)
    Lb1.TextSize=20:Lb1.textcolor=Colors.black:Lb1.color=Colors.yellow
    Lb1.Text="東南西北" &CRLF&CRLF& "東南西北" &CRLF&CRLF& "東南西北"
    Activity.AddView(Lb1,0,0,Activity.Width,0)
    Lb1.Height=su.MeasureMultilineTextHeight(Lb1,Lb1.Text)
    
End Sub
 
Only half of the last line is shown.

1634450973420.png


PS: Seems there are sometimes problems with strings containing non-English language :-(
https://www.b4x.com/android/forum/t...t-provides-value-which-crops-the-text.132609/
 
Upvote 0
For curiosity , I tested with your code and also using the Designer and it worked just as intended. Now, you need to wait for Erel to give you a better answer.
View attachment 120378
Thank you! It's strange. And with two CRLF between each line theoretically there should be two empty lines between the three lines of text. So strictly speaking what's shown in your screenshot is not completely "right". But yea, let's wait for Erel.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
The actual measurement happens in the native SDK.

BCTextEngine does measure it correctly (there will be issues with word wrapping with Chinese):
B4X:
BBLabel1.Text = $"東南西北
    
東南西北

東南西北"$
    Dim TextHeight As Int = BBLabel1.Paragraph.Height / TextEngine.mScale  + BBLabel1.Padding.Top + BBLabel1.Padding.Bottom
    BBLabel1.mBase.Height = TextHeight 
    BBLabel1.Redraw

1634543964118.png
 
Upvote 0
The actual measurement happens in the native SDK.

BCTextEngine does measure it correctly (there will be issues with word wrapping with Chinese):
B4X:
BBLabel1.Text = $"東南西北
   
東南西北

東南西北"$
    Dim TextHeight As Int = BBLabel1.Paragraph.Height / TextEngine.mScale  + BBLabel1.Padding.Top + BBLabel1.Padding.Bottom
    BBLabel1.mBase.Height = TextHeight
    BBLabel1.Redraw

View attachment 120410
Thank you Erel.

BCTextEngine is a nice work-around (I haven't used it before).
 
Upvote 0
Top