Android Question Non-English characters and MeasureMultilineTextHeight in API28

KZero

Active Member
Licensed User
Longtime User
Hi,

StringUtils MeasureMultilineTextHeight working perfect on English and any other language on API-26

but after changing target API to 28, English is measured correctly while Arabic is not



test project attached

-

i think it's related to LineSpacing

reducing line spacing to 0.85 in Arabic Text make it fit but for English it must more

B4X:
        Dim Ref as Reflector
        Ref.Target = Label1
        Ref.RunMethod3("setLineSpacing", 1, "java.lang.float", 0.85, "java.lang.float")

any ideas ?
 

Attachments

  • su.png
    su.png
    31 KB · Views: 118
  • measuretextheightapi28arabic.zip
    8.8 KB · Views: 109
Last edited:

KZero

Active Member
Licensed User
Longtime User
i found the cause in api 28
setFallbackLineSpacing is Enabled by default (on many devices, thats why the non-latin text looks correct on some device and some devices not)

setfallbacklinespaceing.png


this code fixed the measurement problem

B4X:
    Dim P As Phone
    If P.SdkVersion >= 28 Then
    Dim Ref As Reflector
        Ref.Target = label1
        Ref.RunMethod2("setFallbackLineSpacing","False","java.lang.boolean")
    End If

the only problem with this code that it makes the Arabic lines bit close to each others but it's pretty acceptable for me
i'm not sure if MeasureMultilineTextHeight can be called with custom line spacing parameter using reflection or inline java code, it will be an extra option to make the measured string looks bit better.
 
Upvote 0

mohsen24000

New Member
i found the cause in api 28
setFallbackLineSpacing is Enabled by default (on many devices, thats why the non-latin text looks correct on some device and some devices not)

View attachment 95301

this code fixed the measurement problem

B4X:
    Dim P As Phone
    If P.SdkVersion >= 28 Then
    Dim Ref As Reflector
        Ref.Target = label1
        Ref.RunMethod2("setFallbackLineSpacing","False","java.lang.boolean")
    End If

the only problem with this code that it makes the Arabic lines bit close to each others but it's pretty acceptable for me
i'm not sure if MeasureMultilineTextHeight can be called with custom line spacing parameter using reflection or inline java code, it will be an extra option to make the measured string looks bit better.
It's fine, but when using CSBuilder the problem remains
B4X:
    Dim P As Phone
    If P.SdkVersion >= 28 Then
        Dim Ref As Reflector
        Ref.Target = lblTheory
        Ref.RunMethod2("setFallbackLineSpacing","False","java.lang.boolean")
    End If
    lblTheory.Text = CS.PopAll
    lblTheory.Height = su.MeasureMultilineTextHeight(lblTheory, lblTheory.Text)
 
Upvote 0
Top