Private Sub MeasureTextWidth(Text As String, Font1 As B4XFont) As Int
#If B4A
Private bmp As Bitmap
bmp.InitializeMutable(2dip, 2dip)
Private cvs As Canvas
cvs.Initialize2(bmp)
Return cvs.MeasureStringWidth(Text, Font1.ToNativeFont, Font1.Size)
#Else If B4i
Return Text.MeasureWidth(Font1.ToNativeFont)
#Else If B4J
Dim jo As JavaObject
jo.InitializeNewInstance("javafx.scene.text.Text", Array(Text))
jo.RunMethod("setFont",Array(Font1.ToNativeFont))
jo.RunMethod("setLineSpacing",Array(0.0))
jo.RunMethod("setWrappingWidth",Array(0.0))
Dim Bounds As JavaObject = jo.RunMethod("getLayoutBounds",Null)
Return Bounds.RunMethod("getWidth",Null)
#End If
End Sub
Private Sub MeasureTextHeight(Text As String, Font1 As B4XFont) As Int
#If B4A
Private bmp As Bitmap
bmp.InitializeMutable(2dip, 2dip)
Private cvs As Canvas
cvs.Initialize2(bmp)
Return cvs.MeasureStringHeight(Text, Font1.ToNativeFont, Font1.Size)
#Else If B4i
Return Text.MeasureHeight(Font1.ToNativeFont)
#Else If B4J
Dim jo As JavaObject
jo.InitializeNewInstance("javafx.scene.text.Text", Array(Text))
jo.RunMethod("setFont",Array(Font1.ToNativeFont))
jo.RunMethod("setLineSpacing",Array(0.0))
jo.RunMethod("setWrappingWidth",Array(0.0))
Dim Bounds As JavaObject = jo.RunMethod("getLayoutBounds",Null)
Return Bounds.RunMethod("getHeight",Null)
#End If
End Sub