Home > Software engineering >  Install a font from memory C
Install a font from memory C

Time:01-22

I am working on a project and making font files encrypted due to privacy issues, and want to install it via the C application. But the issue is I can only install it when I decrypt it and place it physically on disk (AddFontResource). And this way the decrypted font file will be shown to the user which I don't want. Is there any way to read font as stream? Or any other better option?

CodePudding user response:

the issue is I can only install it when I decrypt it and place it physically on disk (AddFontResource).

That is only way to make the font accessible to other processes. Using AddFontMemResourceEx() instead, you can install a font from the decrypted memory rather than from a disk file, but the font will only be accessible to the calling process, not to other processes.

And this way the decrypted font file will be shown to the user which I don't want.

Sorry, but that is the only way if you want to make the font accessible to other processes.

Is there any way to read font as stream?

There is no such option, no.

CodePudding user response:

On Windows, a better approach is not to call GDI AddFontResource, but rather to use DirectWrite and create a private font set. There is a code sample that covers exactly your scenario at https://github.com/microsoft/Windows-classic-samples/tree/main/Samples/DirectWriteCustomFontSets.

  •  Tags:  
  • Related