How to configure Google AppEngine to work with vec

2019-05-09 14:10发布

In AppEngine standard environment with Java8 during attempt to use SVG next error appears. I get this error when I try to draw SVG on a XSLFSlide with POI like slide.draw(graphics2D) or to convert SVG to PNG with Batik. The problem seems to appear because fontconfig cannot find fonts. In debian distribution it solves by installing libfontconfig1. How to solve it on 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条回答
做个烂人
2楼-- · 2019-05-09 14:38

I've faced the same problem and managed to solve it by explicitly telling the AppEngine VM a specific font configuration to pick up, by setting the "sun.awt.fontconfig" system property. Try inserting the following code somewhere at the very beginning of your source code (before using any font or graphic components):

    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);
查看更多
登录 后发表回答