Android Question Typeface Monospace Style_Italic

Robert Valentino

Well-Known Member
Licensed User
Longtime User
I have labels that were made in Designer with a Typeface of MONOSPACE Style ITALIC

When I create a New label on a panel I am displaying in ScrollView2D and assign it a typeface of
B4X:
Typeface.CreateNew(Typeface.MONOSPACE, Typeface.STYLE_ITALIC)

It appears as MONOSPACE but does not have the ITALIC style

Is designer doing something different in its label creation?

The code for the label I create is as follows:
B4X:
  Dim AnotherPlayer  As Label
                 
  AnotherPlayer.Initialize("")
  AnotherPlayer.Gravity  = Gravity.LEFT + Gravity.CENTER_VERTICAL
  AnotherPlayer.Typeface = Typeface.CreateNew(Typeface.MONOSPACE, Typeface.STYLE_ITALIC)
  AnotherPlayer.TextSize = 16

Which matches exactly what I have in the labels I create in Designer. Why is the ITALIC style not taking effect?

BobVal
 

Robert Valentino

Well-Known Member
Licensed User
Longtime User
OK. I bow to your results and THANK YOU for pointing me to a fix (right now I have 8 extra Label fields on my designer screen hidden that I move into a position and show when needed) would like to try using the setTextSkewX but do not know how.

Can you tell me how to do a setTextSkewX

BobVal
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
This will do it:

B4X:
Dim Paint As JavaObject = NewPlayer
Paint = Paint.RunMethod("getPaint",Null)
Dim Skew As Float = -0.25
Paint.RunMethod("setTextSkewX",Array(Skew))

Requires the JavaObject Library to be selected in the libs tab.

As mentioned in the linked article, make sure you remove the Typeface Italic, otherwise it will be skewed twice on devices that do support it.
 
Upvote 0

Robert Valentino

Well-Known Member
Licensed User
Longtime User
I have been having this Italic problem (if you knew me you would LOL saying that's your only problem Bob) so I decided to write routine to check if Italic was supported

B4X:
Sub SupportItalic(Act As Activity) As Boolean
   Dim Cvs            As Canvas

   Dim TextWidth1  As Int
   Dim TextWidth2  As Int

   Cvs.Initialize(Act)

   TextWidth1 = Cvs.MeasureStringWidth("Robert Valentino", Typeface.CreateNew(Typeface.MONOSPACE, Typeface.STYLE_ITALIC), 10)
   TextWidth2 = Cvs.MeasureStringWidth("Robert Valentino", Typeface.CreateNew(Typeface.MONOSPACE, Typeface.STYLE_NORMAL), 10)

  
   If TextWidth1 = TextWidth2 Then Return False

   Return True
End Sub

What I found out with the Above code is the on my Samsung Italic is NOT supported in MONOSPACE mode (if I change MONOSPACE to DEFAULT this routine will return True).

So at least I can call this routine once to see if I should handle MONOSPACE ITALIC myself when creating fields in code.

Hopes this helps someone - Thanks for all the help everyone has given on this issue.

BobVal


PS: Guess I should have include this routine Stevel05 provided for me to make the field Italic

B4X:
Public  Sub MakeFieldItalic(Field As Label)

       Dim JavaObj As JavaObject = Field
       Dim Skew  As Float      = -0.25
      
       JavaObj = JavaObj.RunMethod("getPaint",Null)
       JavaObj.RunMethod("setTextSkewX",Array(Skew))
End Sub


Now when I create fields I can make them Italic if the device does not support it.
 
Last edited:
Upvote 0

Robert Valentino

Well-Known Member
Licensed User
Longtime User
This works:

B4X:
Public  Sub MakeFieldItalic(Field As Label, Bold As Boolean)

       Dim JavaObj As JavaObject = Field
       Dim Skew  As Float      = -0.25
      
       JavaObj = JavaObj.RunMethod("getPaint",Null)
       JavaObj.RunMethod("setTextSkewX",Array(Skew))
      
       JavaObj.RunMethod("setFakeBoldText",Array(Bold))        
End Sub
 
Upvote 0
Top