javafontsjava-7jdk-internal-api

jdk7: sun.font.fontManager replacement/how to get filename information from fontname


Using Oracle(Sun) JDK6 and trying to move to Oracle JDK7

I am using sun.awt.GraphicsEnvironment to find all system fonts in order to use them to change pdf font used in my pdf file. Here is the exact code I am using:

GraphicsEnvironment gEnv = GraphicsEnvironment.getLocalGraphicsEnvironment();

// get all system fonts
final Font[] fonts = gEnv.getAllFonts();

After that I will need to get the exact font file path on the system, so I use:

FontManager.getFontPath(true) + "/" +
               FontManager.getFileNameForFontName(font_name);

The problem now is that sun.font.FontManager is no longer a class and has been converted to an interface. I searched online and came up with some solutions that I am not satisfied with and I am looking for other ideas to help solve my problem.

The solutions that I found:

  1. Deploy my project on Java 6 instead of Java 7 (Not recommend as I use some new features in Java 7).
  2. I found the code of the FontManager class online, but using it will require including a lot of other classes/interfaces and the process seems dummy and time consuming. Also I am not if I am allowed to use that code as it's proprietary of Sun company.

What I need is: *A way to find the exact font file path on the system*. All ideas are welcomed.


Solution

  • You're not saying which JDK you use (Oracle, OpenJDK, ..). Possibly you have

    FontManagerFactory.getInstance()
    

    available. Or the inteface implementation Win32FontManager (if you're on Windows)?