Bug? [B4X][BBCodeview] Line spacing problem related to font size.

William Lancee

Well-Known Member
Licensed User
Longtime User
When the textsize is greater then 35, the line spacing is inconsistent

fontproblem.PNG


B4X:
    BBCodeView1.Text = _
$"
[TextSize=42]Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc fermentum elit vitae nisi faucibus, vitae lacinia turpis mattis.
[/TextSize]
"$
 

William Lancee

Well-Known Member
Licensed User
Longtime User
Keeping those properties constant (default here)...

On my screen, the spacing between the o of Lorem and the o of consectetur is 5mm.
But the spacing between u of Nunc and u of faucibus is only 3mm.

Is that really by design? Or is it too subtle to see?

(The effect is only present/seen for larger font sizes)
 

William Lancee

Well-Known Member
Licensed User
Longtime User
That works with SpaceBetweenLines= 40dip. The minimum is not relevant to this issue.

I could use B4XCanvas to measure font height and use that value (1x or 1.5x or 2x).

Thanks.
 

William Lancee

Well-Known Member
Licensed User
Longtime User
Once again, @Erel points out that what appears to a bug is just a wrong assumption.

Somewhere behind the scenes, the code is computing a line spacing and then increases it if the text does not fit.
Of course that makes sense (after understanding the process).

For those who are following this thread, the formula below works for me. Note that since the line spacing occurs in the text engine,
all text in a given code view has the same spacing, irrespective of varying font sizes. However, you can use the [Vertical=..] tag [/Vertical]
to override the default.

B4X:
Dim fs As Int = 35      'or whatever your font size is
Textengine1.SpaceBetweenLines = 1.85 * cv.MeasureText("X", xui.CreateDefaultFont(fs)).Height
 
Top