简体   繁体   English

jdk7:sun.font.fontManager 替换/如何从 fontname 获取文件名信息

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

Using Oracle(Sun) JDK6 and trying to move to Oracle JDK7使用 Oracle(Sun) JDK6 并尝试迁移到 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.我正在使用sun.awt.GraphicsEnvironment来查找所有系统字体,以便使用它们来更改我的 pdf 文件中使用的 pdf 字体。 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.现在的问题是, sun.font.FontManager不再是一个类, sun.font.FontManager被转换成了一个接口。 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).在 Java 6 而不是 Java 7 上部署我的项目(不推荐,因为我使用了 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.我在网上找到了 FontManager 类的代码,但使用它需要包含很多其他类/接口,而且这个过程似乎很愚蠢且耗时。 Also I am not if I am allowed to use that code as it's proprietary of Sun company.如果我被允许使用该代码,我也不会,因为它是 Sun 公司的专有代码。

What I need is: * A way to find the exact font file path on the system *.我需要的是: *一种在系统上找到确切字体文件路径的方法*. All ideas are welcomed.欢迎所有想法。

You're not saying which JDK you use (Oracle, OpenJDK, ..).您不是说您使用的是哪个 JDK(Oracle、OpenJDK 等)。 Possibly you have可能你有

FontManagerFactory.getInstance()

available.可用的。 Or the inteface implementation Win32FontManager (if you're on Windows)?或者接口实现Win32FontManager (如果你在 Windows 上)?

This code works on Windows 10 and IBM Java 8此代码适用于 Windows 10 和 IBM Java 8

sun.font.SunFontManager.getInstance().getPlatformFontPath(true)

But on macOS 11 and AdoptOpenJDK 8/11 an empty string is returned.但在 macOS 11 和 AdoptOpenJDK 8/11 上,返回空字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM