For this I use sUtils.MeasureMultilineTextHeight, which has always worked fine, but noticed it can give too small a height if the text contains
non-ASCII characters. Attached an image showing the troublesome text.
I have worked out a work-around (shown below), which seems to be working OK, but wonder what the standard way is to deal with this.
RBS
non-ASCII characters. Attached an image showing the troublesome text.
I have worked out a work-around (shown below), which seems to be working OK, but wonder what the standard way is to deal with this.
B4X:
Public Sub MeasureMultilineTextHeightLabel2(oParent As Object, tLabelProps As tViewProps) As Int
Dim lblDummy As Label
Dim iHt As Int
Dim iDoubleLinebreaks As Int
Dim dBytesDivChars As Double
Dim dExtra As Double
Dim arrBytes() As Byte = tLabelProps.strText.GetBytes("UTF8")
dBytesDivChars = arrBytes.Length / tLabelProps.strText.Length
If dBytesDivChars > 1 Then
dExtra = dBytesDivChars - 1
dBytesDivChars = 1 + dExtra * Enums.dNonASCIITextHeightCorrection 'default for Enums.dNonASCIITextHeightCorrection is 0.1
End If
'Log("dBytesDivChars: " & dBytesDivChars)
'setup temp label
lblDummy.Initialize("")
lblDummy.TextSize = tLabelProps.fTextSize
lblDummy.Typeface = tLabelProps.oTypeFace
lblDummy.Height = tLabelProps.iHeight
lblDummy.Width = tLabelProps.iWidth
lblDummy.Padding = tLabelProps.arrPadding
'note here the label height has to be doubled to avoid too small readings with char 9632 (??)
'---------------------------------------------------------------------------------------
mvPageRoot.AddView(lblDummy, 0, -1000, tLabelProps.iWidth, tLabelProps.iHeight) ' * 2)
'MeasureMultilineTextHeight doesn't consider the padding!
If tLabelProps.oCSB.IsInitialized Then
lblDummy.Text = tLabelProps.oCSB
iHt = sUtils.MeasureMultilineTextHeight(lblDummy, tLabelProps.oCSB) + tLabelProps.arrPadding(1) + tLabelProps.arrPadding(3)
Else
lblDummy.Text = tLabelProps.strText
iHt = sUtils.MeasureMultilineTextHeight(lblDummy, tLabelProps.strText) + tLabelProps.arrPadding(1) + tLabelProps.arrPadding(3)
End If
iDoubleLinebreaks = CountStringInString(Chr(10) & Chr(10), tLabelProps.strText, False)
iHt = iHt * dBytesDivChars + iDoubleLinebreaks * Enums.dCorrectDoubleLinebreakHeightFactor * (tLabelProps.fTextSize / 18)
lblDummy.RemoveView
Return iHt
End Sub
RBS