cycfi / elements

Elements C++ GUI library
http://cycfi.github.io/elements/
3.09k stars 238 forks source link

Provide an API for allowing to specify memory locations for fonts (and possibly images) #394

Open Flole998 opened 5 months ago

Flole998 commented 5 months ago

There are some use-cases, for example single-file executables, where it would be a great benefit to allow specifying a vector of font-names and the binary data for those fonts or a pointer to that data. This way app-developers can grab fonts from whichever place they prefer to store them and whichever way of storing them fits their needs best.

Something similar could be done for images, for the same use-case.

djowel commented 5 months ago

I think you'll need to be precise in what the API would look like.

Flole998 commented 5 months ago

I'm not sure "where" to add it, but it could look like this:

addMemoryFont(std::string name, void* fontdata, size_t fontlength)

The fontdata pointer could also be made a shared char pointer I guess.

As for what happens when it's called: The font data can be loaded from memory as in the patch I posted on Discord, the difficult part is adding this to the font map and extracting the font information out of it, as the fontconfig helpers apparently only accept directories to scan.