Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
need help printing a scaled string in a custom font to a 32-bit image
#1
I wanted a function to simply do a _PrintString to a 32-bit screen in a given fg/bg color, but allow the text to be scaled to 2x, 3x, etc., and work with a custom font. Kind of like a simpler RotoZoom, as it doesn't need to rotate and the x,y is the top left corner of the text and not the center. It started out as a modified RotoZoom2/DrawStrng but it used an older(?) PrintWidth function that wasn't compiling so I replaced it with _UPrintWidth. 

Anyway, this should be a simple thing to do, but nothing is appearing on the screen. 
The font is a custom fixed-width bitmap font (8x8 pixels per character) and is already set up and working before this sub is called. The screen is a 32-bit image 1024x768, already created and set to _DEST displaying text. The display is set to _AutoDisplay. 
I have tried debugging it and all the values appear to be what I expect. 
If anyone has a minute and could take a look & let me know what might be wrong here it would be most appreciated.

Code: (Select All)
'Prints string MyString stretched to xScale%, yScale%
'in the current _FONT
'to 32-bit screen at ColNum%,RowNum%
'where the width  of 1 column is _FontWidth  * xScale%
'      and height of 1 row    is _FontHeight * yScale%
'with foreground color fg~& and background color bg~&

Sub DrawString (MyString As String, fg~&, bg~&, ColNum%, RowNum%, xScale%, yScale%)
    Dim SavedSource&
    Dim SavedDest&
    Dim MyImage&
    Dim FontHandle&
    Dim x1&, y1&, x2&, y2&, w1&, h1&
    
    ' remember the source / destination
    SavedSource& = _Source
    SavedDest& = _Dest
    
    ' get the font
    FontHandle& = _Font
    
    MyImage& = _NewImage(_UPrintWidth(MyString, , FontHandle&), _FontHeight(FontHandle&), 32)
    _Dest MyImage&
    
    _Font FontHandle&
    Color fg, bg
    _UPRINTSTRING  (0     , 0  ), MyString        ,            ,               , FontHandle&  , MyImage&
    
    w1& = _Width(MyImage&) * xScale%
    h1& = _Height(MyImage&) * yScale%
    x1& = ColNum% * w1&
    y1& = RowNum% * h1&
    x2& = x1& + w1&
    y2& = y1& + h1&
    
    _PutImage (x1&, y1&)-(x2&, y2&), MyImage&, 0
    
    ' Restore the source/destination
    _Source SavedSource&
    _Dest SavedDest&
    
    ' Cleanup
    _FreeImage MyImage&
End Sub ' DrawString
Reply


Messages In This Thread
need help printing a scaled string in a custom font to a 32-bit image - by madscijr - 07-02-2025, 06:28 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Experimenting with a "StringList" type for simpler handling of string arrays/lists Heimdall 18 1,183 12-19-2025, 12:51 PM
Last Post: Heimdall
  Font Size in Threads Dimster 5 356 12-12-2025, 04:49 PM
Last Post: Dimster
  Sub not Reconizing Dim as String pmackay 18 1,440 10-16-2025, 03:32 PM
Last Post: pmackay
  error doing image collision detection with _MemGet madscijr 55 4,652 10-01-2025, 03:25 PM
Last Post: bplus
  Problem with font in Teletext browser. SquirrelMonkey 7 737 08-27-2025, 11:38 AM
Last Post: BDS107

Forum Jump:


Users browsing this thread: 1 Guest(s)