I recently learned how to register a TTF font with a local GraphicsEnvironment, st, for my use case (SVG-PNG transcoding), Apache Batik can recognize the font:
import java.awt.Font; import java.awt.FontFormatException; import java.awt.GraphicsEnvironment; // [...] GraphicsEnvironment lge = GraphicsEnvironment.getLocalGraphicsEnvironment(); try { Font font = Font.createFont(Font.TRUETYPE_FONT, fontFile); lge.registerFont(font); } catch (FontFormatException e) { logger.warn(e.getMessage(), e); } catch (IOException e) { logger.warn(e.getMessage(), e); }
However, I was wondering if I can unregister previously existing fonts to ensure that only registered fonts will be used in transcoding.
GraphicsEnvironment # unregisterFont (...) does not exist, how can I do this?
PS: I do not want to subclass GraphicsEnvironment, since I cannot assume that there is any particular subclass, for example sun.awt.Win32GraphicsEnvironment.
EDIT: Additional Information:
- As sun.font.FontManager is modified using Java7 (from class to interface and much more), I would prefer not to use a workaround based on it.
- My JVM is an Oracle JVM.
java fonts awt batik
RobertG
source share