How to configure Google AppEngine to work with vector graphic?
Asked Answered
A

1

8

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)
Ainu answered 14/7, 2017 at 10:1 Comment(0)
W
12

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);
Works answered 4/11, 2017 at 4:1 Comment(1)
Fixed it for me, Thank you!Nathan

© 2022 - 2024 — McMap. All rights reserved.