Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Change font size / Maintain screen size.
#4
a while ago I figured out a way to speed up the display of texts. unfortunately, if we use _printstring , it is very slow. This writes to the screen in a software way and will be very slow to process. I figured out that if we map the characters to image in advance, it will take up space in the memory, but it will be very fast. in hardware mode (33) very fast!

it is easy to use

Code: (Select All)
Dim Shared font_collection(9, 99, 1): Screen _NewImage(800, 600, 32)
Const font_sh = 32 'font installed 32(software) or 33(hardware) using

'font_install font_index , font location, color
font_install 0, Environ$("SYSTEMROOT") + "\fonts\arial.ttf", _RGBA32(255, 0, 0, 255), 50
font_install 1, Environ$("SYSTEMROOT") + "\fonts\lucon.ttf", _RGBA32(0, 255, 0, 255), 50






'printtype x_position,    y_position,     fontsize,     text$       text$: to determine the index of the installed letter at the beginning   "#fontindex#........."
'if x_position is -1, then text write to center

printtype 20, 20, 50, "#0#this is 0 index font"
printtype -1, 100, 20, "#1#this is 1 index font (to center)"



Sub font_install (f_index, f$, col&, fs)
    sh = Int(fs * .08): af = _LoadFont(f$, fs): k$ = "'+0123456789.?!=:>()<%/-,ABCDEFGHIJKLMNOPQRSTVXYZUWabcdefghijklmnopqrstvxyzuw "
    For ac = 0 To Len(k$) - 1: ac$ = Mid$(k$, ac + 1, 1): _Font af
        temp2 = _NewImage(_PrintWidth(ac$) + sh, fs + sh, 32): _Dest temp2: Cls , 0: _Font af
        Color _RGBA32(20, 20, 20, _Alpha32(col&)), 0: _PrintString (sh, sh), ac$
        Color col&, 0: _PrintString (0, 0), ac$
        font_collection(f_index, ac + 1, 0) = _CopyImage(temp2, font_sh): _FreeImage temp2
    font_collection(f_index, ac + 1, 1) = Asc(ac$): Next ac: font_collection(f_index, 0, 0) = af
End Sub


Sub printtype (px, py, f_size, t$)
    ReDim text_raw(299, 4) As Long: actual_x = px: f_index = 0: tr_c = 0
    Do Until ac = Len(t$): ac = ac + 1: ac$ = Mid$(t$, ac, 1)
        If ac$ = "#" Then
            f_index = Val(Mid$(t$, ac + 1, 1)): ac = ac + 2
        Else
            find = -1: For t = 1 To 99: If Asc(ac$) = font_collection(f_index, t, 1) Then find = t: Exit For
            Next t
            If find <> -1 Then
                af = font_collection(f_index, find, 0): xsize = Int(f_size / _Height(af) * _Width(af))
                text_raw(tr_c, 0) = af: text_raw(tr_c, 1) = actual_x: text_raw(tr_c, 2) = xsize + actual_x
                tr_c = tr_c + 1: actual_x = actual_x + xsize
            End If
        End If
    Loop: If px = -1 Then mv = (_Width(mon) - actual_x) / 2 + 1
    For t = 0 To tr_c - 1: tx = text_raw(t, 0): _PutImage (text_raw(t, 1) + mv, py)-(text_raw(t, 2) + mv, py + f_size), tx: Next t: text_large = actual_x
End Sub
Reply


Messages In This Thread
RE: Change font size / Maintain screen size. - by MasterGy - 11-11-2022, 05:25 PM



Users browsing this thread: 2 Guest(s)