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

时光总嘲笑我的痴心妄想 提交于 2019-12-01 02:11:19

问题


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.


回答1:


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)?



来源:https://stackoverflow.com/questions/13684342/jdk7-sun-font-fontmanager-replacement-how-to-get-filename-information-from-font

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!