如何配置Google AppEngine以使用矢量图形? [英] How to configure Google AppEngine to work with vector graphic?

查看:327
本文介绍了如何配置Google AppEngine以使用矢量图形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  java.lang.NullPointerException $ b $在sun.awt.FontConfiguration.getVersion(FontConfiguration.java:1264)
。在sun.awt.FontConfiguration.readFontConfigFile(FontConfiguration.java:219)
在sun.awt.FontConfiguration.init(FontConfiguration.java:107)
在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)
在sun.reflect.NativeConstructorAccessorImpl.newInstance0(本机方法)
在sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
在sun.reflect .DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang .reflect.Constructor.newInstance(Constructor.java:423)$ b $在java.lang.Class.newInstance(Class.java:443)
在sun.font.FontManagerFactory $ 1.run(FontManagerFactory.java:在java.security.AccessController.doPrivileged处使用
(Native Method)$ b $在sun.font.FontManagerFactory.getInstance(FontManagerFactory.java:74)
在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)在org.apache.poi.sl.draw.DrawTextParagraph.getAttributedString(DrawTextParagraph.java:640)

在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(DrawSimp leShape.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)


解决方案

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

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


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)

解决方案

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);

这篇关于如何配置Google AppEngine以使用矢量图形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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