【发布时间】:2017-02-16 13:22:03
【问题描述】:
我在其中一个项目中使用 Apache Batik 将 SVG 转换为 PDF。该项目是在 Tomcat 7 中运行的 Spring 应用程序。在 Ubuntu 下运行的开发机器上一切正常,Tomcat 使用 $CATALINA_HOME/bin/startup.sh 启动。但是,当我尝试使用 CentOS 6 在生产服务器上运行该应用程序并且 Tomcat 开始使用 service tomcat7 start 命令时,该应用程序在转换时陷入无限循环。我试过调试问题,发现这段代码:
/**
* Creates the {@link FontInfo} instance for the given configuration.
* @param cfg the configuration
* @param useComplexScriptFeatures true if complex script features enabled
* @return the font collection
* @throws FOPException if an error occurs while setting up the fonts
*/
public static FontInfo createFontInfo(Configuration cfg, boolean useComplexScriptFeatures)
throws FOPException {
FontInfo fontInfo = new FontInfo();
final boolean strict = false;
if (cfg != null) {
URI thisUri = new File(".").getAbsoluteFile().toURI();
InternalResourceResolver resourceResolver
= ResourceResolverFactory.createDefaultInternalResourceResolver(thisUri);
//TODO The following could be optimized by retaining the FontManager somewhere
FontManager fontManager = new FontManager(resourceResolver, FontDetectorFactory.createDefault(),
FontCacheManagerFactory.createDefault());
//TODO Make use of fontBaseURL, font substitution and referencing configuration
//Requires a change to the expected configuration layout
DefaultFontConfig.DefaultFontConfigParser parser
= new DefaultFontConfig.DefaultFontConfigParser();
DefaultFontConfig fontInfoConfig = parser.parse(cfg, strict);
DefaultFontConfigurator fontInfoConfigurator
= new DefaultFontConfigurator(fontManager, null, strict);
List<EmbedFontInfo> fontInfoList = fontInfoConfigurator.configure(fontInfoConfig);
fontManager.saveCache();
FontSetup.setup(fontInfo, fontInfoList, resourceResolver, useComplexScriptFeatures);
} else {
FontSetup.setup(fontInfo, useComplexScriptFeatures);
}
return fontInfo;
}
在PDFDocumentGraphics2DConfigurator 类中。当我在开发人员机器上运行应用程序时,URI thisUri = new File(".").getAbsoluteFile().toURI(); 行的结果是 thisUri 被分配了 ~/tomcat/bin/. 文件夹。当应用程序在生产机器上运行时,它被分配了/. 值。我认为这是主要问题,因为thisUri 的值是 FOP 开始字体搜索的文件夹,而在生产机器上,这是文件系统的根目录,整个 FS 结构的递归搜索非常慢。我尝试使用字体配置将fop.xconf 文件添加到WEB-INF 目录,但它并没有影响FOP 的行为。而且我无法像在开发机器上启动一样在生产服务器上启动 Tomcat。
有没有人知道如何配置 FOR 字体扫描的基本目录?还是我做错了什么?
【问题讨论】:
标签: java centos6 batik apache-fop