Variable fonts in Java

175 Views Asked by At

Is there any existing tool or library in the Java ecosystem that can handle variable fonts and allow me to read and modify their variable axes programmatically (with the aim of rendering the font)?

I have come across the TrueTypeFont class from the Apache PDFBox library, but it does not seem to provide direct methods for accessing and modifying the variable axes. Similarly, java.awt.Font offers a getAvailableAttributes() method but does not return any variable font axes.

1

There are 1 best solutions below

0
Nithesh Kanna On

The TrueTypeFont class from the Apache PDFBox library and java.awt.Font do not seem to provide direct methods for accessing and modifying the variable axes.

You might be able to use a TextAttribute with the deriveFont method as a workaround. For example, you can create a semi-bold font like this: Font semiBoldfont = font.deriveFont (Map.of (TextAttribute.WEIGHT, TextAttribute.WEIGHT_SEMIBOLD));.

However, this might not give you the full control over the variable axes that you’re looking for.