Browse Source

Merge remote-tracking branch 'origin/master'

master
richie 5 years ago
parent
commit
cb85bbafbc
  1. 11
      src/main/java/com/fanruan/api/cal/FormulaKit.java
  2. 1
      src/main/java/com/fanruan/api/cal/ParameterKit.java
  3. 21
      src/main/java/com/fanruan/api/report/BaseHTMLWriterKit.java
  4. 22
      src/main/java/com/fanruan/api/report/PaintKit.java
  5. 11
      src/main/java/com/fanruan/api/util/ArrayKit.java
  6. 10
      src/test/java/com/fanruan/api/cal/FormulaKitTest.java
  7. 14
      src/test/java/com/fanruan/api/util/ArrayKitTest.java
  8. 21
      src/test/java/com/fanruan/api/util/PaintKitTest.java

11
src/main/java/com/fanruan/api/cal/FormulaKit.java

@ -7,6 +7,7 @@ import com.fr.base.ScriptFormula;
import com.fr.log.FineLoggerFactory;
import com.fr.script.Calculator;
import com.fr.stable.FormulaProvider;
import com.fr.stable.StableUtils;
import com.fr.stable.StringUtils;
import com.fr.stable.UtilEvalError;
import com.fr.stable.script.CalculatorProvider;
@ -104,4 +105,14 @@ public class FormulaKit {
}
return checkFormulaContent(formula.getPureContent());
}
/**
* 判断一个对象是否可以转化为公式
* @param object 要判断的字符串
* @return 如果该字符串是以"="开头说明可以转化成公式否则不能转化成公式
*/
public static boolean canBeFormula(Object object){
return StableUtils.canBeFormula(object);
}
}

1
src/main/java/com/fanruan/api/cal/ParameterKit.java

@ -108,4 +108,5 @@ public class ParameterKit {
public static ParameterProvider[] analyzeAndUnionSameParameters(String[] paramTexts, Parameter[] ps){
return ParameterHelper.analyzeAndUnionSameParameters(paramTexts, ps);
}
}

21
src/main/java/com/fanruan/api/report/BaseHTMLWriterKit.java

@ -0,0 +1,21 @@
package com.fanruan.api.report;
import com.fr.stable.html.Tag;
import com.fr.stable.web.Repository;
import com.fr.web.BaseHTMLWriterUtils;
import java.awt.*;
public class BaseHTMLWriterKit {
/**
* 根据原始的图片和指定的尺寸以及报表上下文生成图片的HTML标签该方法只生成一个简单的img标签
* @param image 原始图片
* @param dimension 指定尺寸
* @param repo 报表上下文
* @return img图片标签
*/
public static Tag createImageTag4RepoWithCheckVml(Image image, Dimension dimension, Repository repo){
return BaseHTMLWriterUtils.createImageTag4RepoWithCheckVml(image, dimension, repo);
}
}

22
src/main/java/com/fanruan/api/report/PaintKit.java

@ -0,0 +1,22 @@
package com.fanruan.api.report;
import com.fr.base.Style;
import com.fr.report.cell.cellattr.core.CellUtils;
import java.awt.*;
public class PaintKit {
/**
* 如果value是ImageWithSuffix类的一个实例则创建一个宽为width高为height,类型为TYPE_4BYTE_ABGR的image,并将其按照比例和Style绘制
* @param value 传入的需要判断为是否是ImageWithSuffix实例的对象
* @param resolution 缩放比例的分母缩放比例为1/resolution
* @param style 绘制image的style
* @param width 绘制image的宽
* @param height 绘制image的高
* @return 返回宽为width高为height,类型为TYPE_4BYTE_ABGR的image
*/
public static Image value2Image(Object value, int resolution, Style style, int width, int height){
return CellUtils.value2Image(value, resolution, style, width, height);
}
}

11
src/main/java/com/fanruan/api/util/ArrayKit.java

@ -2,6 +2,8 @@ package com.fanruan.api.util;
import com.fr.stable.ArrayUtils;
import java.util.List;
/**
* @author richie
* @version 10.0
@ -91,4 +93,13 @@ public class ArrayKit {
public static <T> boolean isNotEmpty(T[] array) {
return ArrayUtils.isNotEmpty(array);
}
/**
* 返回一个ArrayList
* @param array 数组
* @return 链表
* */
public static <T> List<T> toList(T[] array) {
return ArrayUtils.toList(array);
}
}

10
src/test/java/com/fanruan/api/cal/FormulaKitTest.java

@ -72,4 +72,14 @@ public class FormulaKitTest extends Prepare {
assertEquals(true, FormulaKit.checkFormulaContent(new Formula("=")));
assertEquals(false, FormulaKit.checkFormulaContent("="));
}
@Test
public void canBeFormula() {
String s1 = "=1";
String s2 = "=a+b+";
String s3 = "ppp";
Assert.assertTrue(FormulaKit.canBeFormula(s1));
Assert.assertTrue(FormulaKit.canBeFormula(s2));
Assert.assertFalse(FormulaKit.canBeFormula(s3));
}
}

14
src/test/java/com/fanruan/api/util/ArrayKitTest.java

@ -1,6 +1,9 @@
package com.fanruan.api.util;
import com.fanruan.api.Prepare;
import java.util.*;
import com.fr.third.org.apache.poi.hssf.record.formula.functions.Int;
import org.junit.Assert;
import org.junit.Test;
@ -97,4 +100,15 @@ public class ArrayKitTest extends Prepare {
Assert.assertEquals(ArrayKit.addAll(longTestArray, 5L,6L), longTestResult);
Assert.assertEquals(ArrayKit.addAll(shortTestArray, new Short("5"),new Short("6")), shortTestResult);
}
@Test
public void toList() throws Exception{
Integer array[] = {1,2,3};
ArrayList<Integer> result = new ArrayList<Integer>();
result.add(1);
result.add(2);
result.add(3);
Assert.assertEquals(ArrayKit.toList(array),result);
}
}

21
src/test/java/com/fanruan/api/util/PaintKitTest.java

@ -0,0 +1,21 @@
package com.fanruan.api.util;
import com.fanruan.api.report.PaintKit;
import com.fr.base.Style;
import com.fr.plugin.present.fun.StarPainter;
import org.junit.Assert;
import org.junit.Test;
import java.awt.*;
public class PaintKitTest {
@Test
public void value2Image() {
StarPainter star = new StarPainter(1);
Style style = Style.getInstance();
Image image = PaintKit.value2Image(star, 1, style, 30, 50);
Assert.assertEquals(30, image.getWidth(null));
Assert.assertEquals(50, image.getHeight(null));
}
}
Loading…
Cancel
Save