activiti生成图片乱码解决

来源:互联网 发布:天基卫星通信网络 编辑:程序博客网 时间:2024/05/17 08:43

利用ProcessDiagramGenerator.generateDiagram方法可以生成当前活动用红色边框渲染的图片,但是执行后会有乱码的问题,这个主要是由于生成图片时的font造成的。

网上的解决方案有两种

 一种是修改源码

另一种是在xml配置中添加字体配置

Xml代码  收藏代码
  1. <property name="activityFontName" value="${diagram.activityFontName}"/>  
  2. <property name="labelFontName" value="${diagram.labelFontName}"/>  

 

将这两个属性配置为宋体,但是在程序执行的时候还是会有问题

这是因为还需要将activiti的配置对象设置到Context对象中,activiti默认不会将其注入,具体看代码

ProcessDiagramCanvas这个类

Java代码  收藏代码
  1. public ProcessDiagramCanvas(int width, int height) {  
  2.     this.canvasWidth = width;  
  3.     this.canvasHeight = height;  
  4.     //会从上下文获取,默认这个返回是空的 所以需要在自己的程序里手动设置进去  
  5. //否则会取其默认值Arial  
  6.     if (Context.getProcessEngineConfiguration() != null) {  
  7.       this.activityFontName = Context.getProcessEngineConfiguration().getActivityFontName();  
  8.     }  
  9.   
  10.     if (Context.getProcessEngineConfiguration() != null) {  
  11.       this.labelFontName = Context.getProcessEngineConfiguration().getLabelFontName();  
  12.     }  
  13.       
  14.     this.processDiagram = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);  
  15.     this.g = processDiagram.createGraphics();  
  16.     g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);  
  17.     g.setPaint(Color.black);  
  18.       
  19.     Font font = new Font(activityFontName, Font.BOLD, FONT_SIZE);  
  20.     g.setFont(font);  
  21.     this.fontMetrics = g.getFontMetrics();  
  22.   
  23.     LABEL_FONT = new Font(labelFontName, Font.ITALIC, 10);  
  24.   }  

 

所以在自己代码中要执行  Context.setProcessEngineConfiguration(processEngineConfiguration);这样才能彻底解决乱码的问题

0 0
原创粉丝点击