Browse Source

Merge pull request #23 in TC/finekit from ~MARS.MA/finekit:master to master

* commit 'b741f9b9d5757ece06ccda958ed8c95b3bb14f66':
  KERNEL-1197 按要求修改
  KERNEL-1197 新增两个单元测试,添加了一个返回值说明,删除掉了被标记为Open的BaseFormula
  KERNEL-1197 按要求修改。
  KERNEL-1197 新增utils,以及一些类。
pull/19/head
superman 5 years ago
parent
commit
67bbc5b6a4
  1. 11
      src/main/java/com/fanruan/api/cal/FormulaKit.java
  2. 21
      src/main/java/com/fanruan/api/report/BaseHTMLWriterKit.java
  3. 22
      src/main/java/com/fanruan/api/report/PaintKit.java
  4. 10
      src/test/java/com/fanruan/api/cal/FormulaKitTest.java
  5. 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.log.FineLoggerFactory;
import com.fr.script.Calculator; import com.fr.script.Calculator;
import com.fr.stable.FormulaProvider; import com.fr.stable.FormulaProvider;
import com.fr.stable.StableUtils;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import com.fr.stable.UtilEvalError; import com.fr.stable.UtilEvalError;
import com.fr.stable.script.CalculatorProvider; import com.fr.stable.script.CalculatorProvider;
@ -104,4 +105,14 @@ public class FormulaKit {
} }
return checkFormulaContent(formula.getPureContent()); return checkFormulaContent(formula.getPureContent());
} }
/**
* 判断一个对象是否可以转化为公式
* @param object 要判断的字符串
* @return 如果该字符串是以"="开头说明可以转化成公式否则不能转化成公式
*/
public static boolean canBeFormula(Object object){
return StableUtils.canBeFormula(object);
}
} }

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

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(true, FormulaKit.checkFormulaContent(new Formula("=")));
assertEquals(false, FormulaKit.checkFormulaContent("=")); 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));
}
} }

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