SFML community forums

Help => Graphics => Topic started by: Lime Liquid on April 15, 2023, 11:55:31 am

Title: Access To Default Font.
Post by: Lime Liquid on April 15, 2023, 11:55:31 am
How to access SFML's default font?
I have read the documentation but it's outdated.

I need to access SFML's default font because I'm running an executable from usb drive and then ejecting it.
Of course, custom font (chivomono) I used didn't load because it wasn't there.

I can't copy font and exe to hard drive, because Windows Defender blocks it even with Administrator Permission. I'm using Visual Studio 2022.

Thanks for reading!
Title: Re: Access To Default Font.
Post by: G. on April 15, 2023, 12:12:36 pm
There isn't any default font in SFML.
Title: Re: Access To Default Font.
Post by: Lime Liquid on April 15, 2023, 01:03:34 pm
I know, but at least how to have a font without loading it from file?
Title: Re: Access To Default Font.
Post by: Stauricus on April 15, 2023, 01:15:52 pm
if the doc are outdated, probably you're reading from version 1.6 or something like that, when default fonts were a thing

now you need to load a font to use text. some years ago I asked about what to do if users deleted font files (and you couldn't display an error text because you wouldn't have a font), and it was suggested to load a font from memory. its a good approach.

EDIT: here it is:
https://www.sfml-dev.org/documentation/2.5.1/classsf_1_1Font.php#abf2f8d6de31eb4e1db02e061c323e346

more details here:
https://stackoverflow.com/questions/17406710/how-to-integrate-hardcode-a-font-file-into-my-program

basically you put a font in that program from deadnote site (actually there are tons of apps that do that. it's nothing special). it will give you an array, you put that array in your code, and load it with the SFML function font.loadFromMemory(fontChar, fontSize)
Title: Re: Access To Default Font.
Post by: Garwin on April 15, 2023, 01:18:11 pm
You cannot. You can load from stream but you need it put to the stream ....

But you can have font on your usb and load it from usb. The path can be relative.
Title: Re: Access To Default Font.
Post by: Hapax on April 16, 2023, 11:07:13 pm
You can copy the font file from the USB device into memory (as mentioned above). Then, even after you eject the device, the file is still accessible in memory. No need to store on hard disk or anything; the font file in its entirety is right there in memory.

Of course, if you close the program, the memory is lost along with the font file but that makes sense.

I suppose the question that arises is why it's such an issue to install a font. Perhaps the font and/or executable are unsafe. You should check those.