Android Code Snippet Draw multiline text on canvas

Description: draw a string with embedded CRLF on canvas.

Code:
B4X:
Sub DrawMultilineText(Canv As Canvas, Text As String, x As Float, y As Float, Typeface1 As Typeface, textSize As Float, Color As Int, Align1 As String, Space As Float)
    Dim lineHeight As Float = Canv.MeasureStringHeight(Text, Typeface1, textSize)
    For Each line As String In Regex.Split(CRLF, Text)
        Canv.DrawText(line, x, y, Typeface1, textSize, Color, Align1)
        y = y + lineHeight + Space
    Next
End Sub
Usage:
B4X:
Dim c As Canvas
c.Initialize(Panel1)
Dim txt As String = "This is the first line" & CRLF & "This is the second line" & CRLF & "..." & CRLF & "This is the last line"
DrawMultilineText(c, txt, 50dip, 50dip, Typeface.DEFAULT_BOLD, 18, Colors.Black, "LEFT", 10dip)
DrawMultilineText(c, txt, 50%x - Panel1.Left, 200dip, Typeface.DEFAULT_BOLD, 18, Colors.Black, "CENTER", 5dip)
 
Top