B4J Question How to get Font Famyly and style

tanush62

Member
I know how to set Font (family, style, size)

B4X:
Sub Process_Globals
    Public lbl1, lbl2 As B4XView
    Private xfont As B4XFont

'..........

End Sub

Sub Slider2_ValueChange (Value As Double)
    fsize2=Value
    xfont = fx.CreateFont(nfont2, fsize2, True, False)
    lbl2.Font = xfont
End Sub

But how to get Family and style (bold, italic) in code from existing label? I want to read them from already defined label. How to extract them from variable like xfont?
 

tanush62

Member
It is not possible. However you can use the label font directly and set it to other views.
Found the way. Maybe it will be useful to someone.

B4X:
  Dim af As B4XFont
   Dim xaf As String
    Dim fbold1, fitalic1 As Boolean
    Dim nfont1 As string

    af=label1.Font
    xaf = af    'Trick is here, converting B4xfont into string
    Dim xbeg, xend As Int
    xbeg = xaf.IndexOf("family=")
    xend = xaf.IndexOf(", style")
    nfont1=xaf.SubString2(xbeg+7,xend)
 
    xbeg = xaf.IndexOf("style=")
    xend = xaf.IndexOf(", size")
 
    xaf=xaf.SubString2(xbeg+6,xend)
    fbold1 = xaf.Contains("Bold")
    fitalic1 = xaf.Contains("Italic")
And it works like a charm.
 
Last edited:
Upvote 0
Top