Bug? Bug #1

chrjak

Active Member
Licensed User
Hey! I will post 4 bugs in a row. in #2 #3 #4 there will be no "hi" then ;)

Since editing layout with the new designer i cant debug my widget any more -> Only when I change the typeface of the label to a private font - Please don't remove this function. It would be soooo useful! It only needs to be fixed

Especially because changing the label layout over code isn't possible

Best Regards
 

chrjak

Active Member
Licensed User
It seems to be one...
If you load a layout with modified font into a widget an error will be shown. At least it is a wrong error message then :D

I saw many Widgets with custom fonts already... it has to be possible!? Or why doesn't Android allow this?
Maybe you could draw on a canvas the font... Do you think this will work?
 

Peter Simpson

Expert
Licensed User
Hello @chrjak,
To use multiple font styles in my widget, I use a nice little rub routine that I created to turn text into a bitmap image ready for me to use in my widget. I saved the different fonts in my assets folder. When I needed to use a different typeface, I draw the selected font onto a Canvas, then returned that canvas as I bitmap ready for to use in my widget .

B4X:
Public Sub Text2BMP(ImgText As String, OriginX As Int, OriginY As Int, font As String, FontSize As Int) As Bitmap
    BitmapTxtToImg.InitializeMutable(180dip, 40dip)

    Dim CustomFont As Typeface = Typeface.LoadFromAssets(font)

    Dim CanvasImage As Canvas
        CanvasImage.Initialize2(BitmapTxtToImg)
        CanvasImage.DrawText(ImgText, OriginX, OriginY, CustomFont, FontSize, Colors.RGB(0, 0, 0), "CENTER")
    Return CanvasImage.Bitmap
End sub
Enjoy...
 
Top