I have a custom font I want to show off in a Java program where the user can view it without having to install it. Does anyone know how to do that?
I have implemented the following:
font = java.awt.Font.createFont(java.awt.Font.TRUETYPE_FONT, new java.io.File(Clazz.class.getResource("/resources/segoescb.ttf").toURI()));
font = font.deriveFont(11.0F);
Embed fonts in a document or presentation Open the file you want to embed fonts in. On the application (PowerPoint or Word) menu, select Preferences. In the dialog box, under Output and Sharing, select Save. Under Font Embedding, select Embed fonts in the file.
To set the font for a Swing component, use its setFont() method of the component. JButton closeButton = new JButton("Close"); closeButton. setFont(f4);
Logical fonts are the five font families defined by the Java platform which must be supported by any Java runtime environment: Serif, SansSerif, Monospaced, Dialog, and DialogInput. These logical fonts are not actual font libraries.
I have never done it, but it seems like the methods you want are
Importing the Font
Font createFont(int fontFormat, InputStream fontStream)
or alternatively
Font createFont(int fontFormat, File fontFile)
The int
parameter is either Font.TRUETYPE_FONT
or Font.TYPE1_FONT
, while the InputStream
or File
parameter contains the font's binary data.
Using the Font after import:
To make the Font available to Font constructors the returned Font must be registered in the
GraphicsEnviroment
by callingregisterFont(Font)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With