Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java 8 get Path to Font

Tags:

java

path

fonts

Is there a way to get the Path for a Font, regardless of the operating system?

e.g

String path = getPathToFont("Arial");
like image 760
Clemens Avatar asked Mar 16 '26 19:03

Clemens


1 Answers

No, there isn't.

Since Java 1.3, the createFont() method allows Java code to start drawing with a TrueType or PostScript font brought in from a file, or any other source of an InputStream, such as a JAR resource, network socket, or decrypted byte array. There's also a method that does take a File, but there's no method that returns the File even for fonts created that way.

Furthermore, the system-provided fonts (from GraphicsEnvironment.getAllFonts()) are not required to only be TrueType or PostScript fonts. They could be in some OS-specific format, or some implementation-private format; and they might not be loaded from a file at all, instead backed by static data (in a class or native code), or drawn purely algorithmically.

like image 61
david Avatar answered Mar 18 '26 09:03

david



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!