Bug? MeasureText does not handle Tab correctly

MrKim

Well-Known Member
Licensed User
Longtime User
Trying to measure a Tab returns -1 (at least in B4J)
B4X:
    Dim cvs1 As B4XCanvas, P As Pane, Fnt As Font = xui.CreateDefaultFont(15)
    P.Initialize("")
    cvs1.Initialize(P)
    Log(cvs1.MeasureText(TAB, Fnt).Width)

Your code MeasureText HERE and below returns 32.87109375. (And why didn't I find THIS code 3 days ago?)
B4X:
   Dim lbl As Label
   lbl.Initialize("")
   lbl.Text = TAB
   lbl.Font = Fnt
   mBase.AddView(lbl, 0, 0, -1, -1) 'mBase is a B4XView panel.
   lbl.Snapshot
   lbl.RemoveNodeFromParent
   Log(lbl.Width)

Interestingly, if I bracket the TAB, then subtract the width of 1 of the bracketing characters I get the same result as MeasureText :
B4X:
    Log(cvs1.MeasureText($"!${TAB}!"$, Fnt).Width)
    Log(cvs1.MeasureText($"!"$, Fnt).Width)
    Log(cvs1.MeasureText($"!${TAB}!"$, Fnt).Width - cvs1.MeasureText($"!"$, Fnt).Width)
 
Top