在CentOS上的Apache FOP中无限扫描字体 [英] Infinite scan for fonts in Apache FOP on CentOS

查看:188
本文介绍了在CentOS上的Apache FOP中无限扫描字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在其中一个项目中,我使用Apache Batik将SVG转换为PDF.该项目是运行在Tomcat 7中的Spring应用程序.在运行Ubuntu的开发机上,一切正常,并且使用$ CATALINA_HOME/bin/startup.sh启动了Tomcat.但是,当我尝试使用CentOS 6在生产服务器上运行该应用程序并且Tomcat使用service tomcat7 start命令启动时,该应用程序将在转换时陷入无限循环.我尝试调试问题并找到了这段代码:

I use Apache Batik to convert SVG into PDF in one of the projects. The project is Spring application running in Tomcat 7. Everything works OK on development machine which runs under Ubuntu with Tomcat being started using $CATALINA_HOME/bin/startup.sh. But when I try to run the app on production server with CentOS 6 and Tomcat started using service tomcat7 start command the app falls into infinite loop on convertation. I've tried to debug the problem and found this piece of code:

/**
 * 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字体扫描有任何想法?还是我做错了什么?

in PDFDocumentGraphics2DConfigurator class. When I'm running the app on developer machine the line URI thisUri = new File(".").getAbsoluteFile().toURI(); results with thisUri being assigned with ~/tomcat/bin/. folder. When the app is running on production machine it is assigned with /. value. I think that this is the main problem because the value of thisUri is the folder in which FOP starts fonts search and on the production machine this is the root of file system and recursive search on the whole FS structure is very slow. I tried to add fop.xconf file to the WEB-INF directory with fonts configuration but it didn't affected the behavior of FOP. And I can't start Tomcat on production server the same way as I start on the dev machine. Has anyone ideas on how to configure the base directory for font scan of FOR? Or am I doing something wrong?

推荐答案

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

I've found the workaround for the problem. I'm not sure if its wright or wrong to do stuff like that but it works. The workaround is based on the fact that File.getAbsolutFile() by default returns the directory resolved against the directory defined by user.dir option. So I need some way to pass this option on Tomcat service start. The only way I've found to do this is to add -Duser.dir=/%CATALINA_HOME/ to the CATALINA_OPTS variable defined in %CATALINA_HOME/bin/setenv.sh file. After that the font scan process took normal amount of time and my app started to work fine.

这篇关于在CentOS上的Apache FOP中无限扫描字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆