Is it possible to embed a TTF or OTF font file in a C++ application?
Is it possible to embed a TTF or OTF font file in a C++ application so that开发者_运维问答 application can use it without installing it on target machine? Any thoughts are welcome. (target platforms are going to be Windows and Macintosh). Purpose: Font is a private one and should not be available to the users.
OS X: Include the font in the app’s Resources
directory, then add the value ATSApplicationFontsPath
to the app’s Info.plist
containing the path relative to the Resources directory.
Windows: MSDN has an article for Windows Forms using the System.Drawing.Text.PrivateFontCollection
class and one for WPF using the System.Windows.Media.FontFamily
class. This is assuming you’re using C++/CLI and the .NET GUI frameworks; it probably won’t apply for MFC.
Recently, got to know that a TTF font is simply a byte array. Just take a hexdump and prepare the byte array (taking care of the endianness, most modern architectures are little endian).
Following thread has details:
https://twitter.com/awmanoj/status/1071718063647580161
In golang, there is also a generator of the byte array. Quite trivial to implement the same in another language like Java/C++ per the need.
精彩评论