How can I find all supported font weights in Java?

How can I find all available font fonts for a given font in Java?

The TextAttribute for font weights lists 11 different weight constants, which is more than just Font.PLAIN and Font.BOLD. I would like to know which ones actually exist for a given font family, so I can make sure that I only use the weights for which the font exists.

The getAttributes () and getAvailableAttributes () methods on a Font will only show whether the Font supports the FONT_WEIGHT attribute, not what weights it does.

If I just pass in a specific value to see what I get back, I have no guarantee that I will get what I asked for. The TextAttribute class says, "The values ​​for WEIGHT, WIDTH, and POSTURE are interpolated by the system, which may choose the 'closest available' font, or use other methods to approximate the user's request."

+2


a source to share





All Articles