如何配置Google AppEngine以使用矢量图形?

时间:2017-07-14 10:01:07

标签: java google-app-engine svg java-8 awt

在AppEngine标准环境中使用Java8尝试使用SVG时出现下一个错误。当我尝试使用POI(如slide.draw(graphics2D)在XSLFSlide上绘制SVG或使用Batik将SVG转换为PNG时,我收到此错误。 似乎出现问题是因为fontconfig无法找到字体。在debian发行版中,它通过安装libfontconfig1来解决。如何在AppEngine上解决它?

java.lang.NullPointerException
at sun.awt.FontConfiguration.getVersion(FontConfiguration.java:1264)
at sun.awt.FontConfiguration.readFontConfigFile(FontConfiguration.java:219)
at sun.awt.FontConfiguration.init(FontConfiguration.java:107)
at sun.awt.X11FontManager.createFontConfiguration(X11FontManager.java:774)
at sun.font.SunFontManager$2.run(SunFontManager.java:431)
at java.security.AccessController.doPrivileged(Native Method)
at sun.font.SunFontManager.<init>(SunFontManager.java:376)
at sun.awt.FcFontManager.<init>(FcFontManager.java:35)
at sun.awt.X11FontManager.<init>(X11FontManager.java:57)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at java.lang.Class.newInstance(Class.java:443)
at sun.font.FontManagerFactory$1.run(FontManagerFactory.java:83)
at java.security.AccessController.doPrivileged(Native Method)
at sun.font.FontManagerFactory.getInstance(FontManagerFactory.java:74)
at java.awt.Font.getFont2D(Font.java:491)
at java.awt.Font.canDisplay(Font.java:1980)
at org.apache.poi.sl.draw.DrawTextParagraph.canDisplayUpTo(DrawTextParagraph.java:756)
at org.apache.poi.sl.draw.DrawTextParagraph.getAttributedString(DrawTextParagraph.java:640)
at org.apache.poi.sl.draw.DrawTextParagraph.breakText(DrawTextParagraph.java:248)
at org.apache.poi.sl.draw.DrawTextShape.drawParagraphs(DrawTextShape.java:159)
at org.apache.poi.sl.draw.DrawTextShape.getTextHeight(DrawTextShape.java:220)
at org.apache.poi.sl.draw.DrawTextShape.drawContent(DrawTextShape.java:102)
at org.apache.poi.sl.draw.DrawSimpleShape.draw(DrawSimpleShape.java:93)
at org.apache.poi.sl.draw.DrawSheet.draw(DrawSheet.java:71)
at org.apache.poi.sl.draw.DrawSlide.draw(DrawSlide.java:41)
at org.apache.poi.xslf.usermodel.XSLFSlide.draw(XSLFSlide.java:307)

1 个答案:

答案 0 :(得分:4)

我遇到了同样的问题,并设法通过设置"sun.awt.fontconfig"系统属性,明确告诉AppEngine VM一个特定的字体配置来解决它。尝试在源代码的最开头(在使用任何字体或图形组件之前)的某处插入以下代码:

    String fontConfig = System.getProperty("java.home")
            + File.separator + "lib"
            + File.separator + "fontconfig.Prodimage.properties";
    if (new File(fontConfig).exists())
        System.setProperty("sun.awt.fontconfig", fontConfig);