Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Access To Default Font.  (Read 2260 times)

0 Members and 1 Guest are viewing this topic.

Lime Liquid

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Access To Default Font.
« 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!

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: Access To Default Font.
« Reply #1 on: April 15, 2023, 12:12:36 pm »
There isn't any default font in SFML.

Lime Liquid

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Re: Access To Default Font.
« Reply #2 on: April 15, 2023, 01:03:34 pm »
I know, but at least how to have a font without loading it from file?

Stauricus

  • Sr. Member
  • ****
  • Posts: 369
    • View Profile
    • A Mafia Graphic Novel
    • Email
Re: Access To Default Font.
« Reply #3 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)
« Last Edit: April 15, 2023, 01:28:30 pm by Stauricus »
Visit my game site (and hopefully help funding it? )
Website | IndieDB

Garwin

  • Jr. Member
  • **
  • Posts: 59
    • View Profile
Re: Access To Default Font.
« Reply #4 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.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Access To Default Font.
« Reply #5 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.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything