Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Loading Fonts
#1
I was wondering since the update to 4.3.0 loading fonts has changed.  Older programs now throw a error trying to load fonts.  How do you now load font for windows in qb64pe?  Thanks in advance for your help.
Reply
#2
Nothing changed.  Did you perhaps extract to a new folder and have the path change?
Reply
#3
Here is what I have:
f& = _LoadFont("/usr/share/fonts/TTF/DejaVuSansMono-Bold.ttf", 13 + ENLARGE%, STYLE$)
_Font f&

Results: Invalid handle

Path is correct not sure why it creates an error.
Reply
#4
(01-12-2026, 03:25 AM)cage Wrote: Here is what I have:
f& = _LoadFont("/usr/share/fonts/TTF/DejaVuSansMono-Bold.ttf", 13 + ENLARGE%, STYLE$)
_Font f&

Results: Invalid handle

Path is correct not sure why it creates an error.

    I would also double check the Value of ENLARGE% and STYLE$.      You aren't showing what your using for those here.
and try this code as well

ffile$ = "/usr/share/fonts/TTF/DejaVuSansMono-Bold.ttf"
if not _FILEEXISTS(ffile$) then
print "Font File Missing !"
end
end if
Reply
#5
Is that a relative path instead of an absolute path?  If so, you might also want to check for the "Output EXE to source folder" option and make certain it matches what you had before.  If the exe isn't going where you expect it to, the paths aren't going to match either.
Reply
#6
The example above  is an absolute path. I found a solution that does work with a relative path but I am still testing things out. What I did find what does work is the following:

_Font _LoadFont("DejaVuSansMono-Bold.ttf", 14, "monospace") 

I works for screen 0 but not for image windows.
Reply
#7
(01-12-2026, 07:33 PM)cage Wrote: The example above  is an absolute path. I found a solution that does work with a relative path but I am still testing things out. What I did find what does work is the following:

_Font _LoadFont("DejaVuSansMono-Bold.ttf", 14, "monospace") 

I works for screen 0 but not for image windows.
   Are you loading the font FOR that Window.    Each New Image starts up with the default font until you change it for THAT Image Handle
Reply
#8
As Tony mentioned above, you have to make your font call *AFTER* you set the screen or destination

_Font _LoadFont("DejaVuSansMono-Bold.ttf", 14, "monospace")
SCREEN _NEWIMAGE(800, 600, 32)

Such as the above, that's not going to work for you. The SCREEN command will create a completely new screen, with the default _FONT 16 in use. If you're using SCREEN or _DEST to change your display, you'll need to make certain that the proper font is in use after those calls.

If you'd share your actual code, it'd make it a lot easier to point exactly to whatever is wrong and help correct it for you.
Reply
#9
_Font _LoadFont("DejaVuSansMono-Bold.ttf", 14, "monospace")
SCREEN _NEWIMAGE(800, 600, 32)

Yes thank you that works. What I have found is that QB64pe does not like an absolute path when loading fonts. Found this out using you snippet. It always returned font was missing with absolute paths.  It's something that worked in an older version but not in the new one. Now I only need to place the font into the same folder as the program and it works like it should. SMcNeill thank you very much for helping out this old man!
Reply
#10
(01-13-2026, 01:34 AM)cage Wrote: _Font _LoadFont("DejaVuSansMono-Bold.ttf", 14, "monospace")
SCREEN _NEWIMAGE(800, 600, 32)

Yes thank you that works. What I have found is that QB64pe does not like an absolute path when loading fonts. Found this out using you snippet. It always returned font was missing with absolute paths.  It's something that worked in an older version but not in the new one. Now I only need to place the font into the same folder as the program and it works like it should. SMcNeill thank you very much for helping out this old man!

     I find that odd and not at all my experience.    I was loading fonts in a program today with absolute path's as I searched for the Best Linux font for Steve's little CONST reference project.    I'm using the very latest release of QB64PE too.      I strongly suspect that you are typing something in the path incorrectly !     If your on Linux or MAC just 1 letter will kill your absolute path since those file systems are case sensitive !      Windows is a little more forgiving !           I usually use string variables for filenames and I ALWAYS check with _FILEEXISTS first to make sure they are there BEFORE I do a _SNDOPEN or _LOADIMAGE or _LOADFont on an external file ! .
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Star Truckload of old CP437 compatible fonts mnrvovrfc 2 791 12-03-2023, 07:04 PM
Last Post: vividpixel
  Looking for sample code showing how to make use of different fonts hanness 6 1,221 05-03-2022, 11:00 PM
Last Post: Dav

Forum Jump:


Users browsing this thread: 1 Guest(s)