I wrote a program in Java that uses a special font that by default doesn't exist on any operating system.
Is it possible in Java to add this special font to the operation system? For example, in Windows, to copy this font to the special Fonts folder.
If it is possible, how?
You can load a font from a File or InputStream. It can then be fed to the Component.setFont() (or similar) method for use.
From the Java tutorial, you need to create a new font and register it in the graphics environment:
After this step is done, the font is available in calls to
getAvailableFontFamilyNames()
and can be used in font constructors.If you include a font file (otf, ttf, etc.) in your package, you can use the font in your application via the method described here:
Oracle Java SE 6: java.awt.Font
There is a tutorial available from Oracle that shows this example:
I would probably wrap this up in some sort of resource loader though as to not reload the file from the package every time you want to use it.
An answer more closely related to your original question would be to install the font as part of your application's installation process. That process will depend on the installation method you choose. If it's not a desktop app you'll have to look into the links provided.
If you want to use the font to draw with graphics2d or similar, this works:
Here is how I did it!