【问题标题】:Infinite scan for fonts in Apache FOP on CentOS在 CentOS 上的 Apache FOP 中无限扫描字体
【发布时间】: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


    【解决方案1】:

    我找到了解决问题的方法。我不确定这样做是对还是错,但它确实有效。解决方法是基于File.getAbsolutFile() 默认情况下返回针对user.dir 选项定义的目录解析的目录这一​​事实。所以我需要一些方法来在 Tomcat 服务启动时传递这个选项。我发现这样做的唯一方法是将-Duser.dir=/%CATALINA_HOME/ 添加到%CATALINA_HOME/bin/setenv.sh 文件中定义的CATALINA_OPTS 变量中。之后,字体扫描过程花费了正常的时间,我的应用开始正常工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-06-17
      • 2013-11-15
      • 2019-06-21
      • 1970-01-01
      • 2012-04-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多