Browse Source

add click demo

master
独行之狼 3 years ago
parent
commit
91e528d06c
  1. 3
      build.xml
  2. BIN
      fr-plugin-CharCartnoon-1.0/fr-plugin-CharCartnoon-1.0.jar
  3. 6
      fr-plugin-CharCartnoon-1.0/plugin.xml
  4. BIN
      install/fr-plugin-CharCartnoon-1.0.zip
  5. BIN
      lib/Filters.jar
  6. BIN
      lib/thumbnailator-0.4.8.jar
  7. 6
      plugin.xml
  8. 84
      src/com/fr/plugin/cool/cartnoon/FRAnimateArraow.java
  9. 32
      src/com/fr/plugin/cool/cartnoon/FRCartnoonFunctions.java
  10. 42
      src/com/fr/plugin/cool/cartnoon/FRCountUp.java
  11. 78
      src/com/fr/plugin/cool/cartnoon/FRDissolveText.java
  12. 19
      src/com/fr/plugin/cool/cartnoon/FREncryptorFunction.java
  13. 25
      src/com/fr/plugin/cool/cartnoon/FRPrintText.java
  14. 16
      src/com/fr/plugin/cool/cartnoon/FRRollText.java
  15. 80
      src/com/fr/plugin/cool/cartnoon/FRRotateText.java
  16. 71
      src/com/fr/plugin/cool/cartnoon/FunConstants.java
  17. 88
      src/com/fr/plugin/cool/cartnoon/TestFun.java
  18. 98
      src/com/fr/plugin/cool/cartnoon/utils/DrawValueLine.java
  19. BIN
      src/com/fr/plugin/cool/cartnoon/web/resource/images/click.png
  20. BIN
      src/com/fr/plugin/cool/cartnoon/web/resource/images/hour.png
  21. BIN
      src/com/fr/plugin/cool/cartnoon/web/resource/images/minute.png

3
build.xml

@ -74,7 +74,8 @@
</fileset>
<!--下面加入第三方包-->
<!--<zipfileset excludes="META-INF/*.SF" src="${libs}/jasypt-1.9.3.jar"></zipfileset>-->
<zipfileset excludes="META-INF/*.SF" src="${libs}/Filters.jar"></zipfileset>
<zipfileset excludes="META-INF/*.SF" src="${libs}/thumbnailator-0.4.8.jar"></zipfileset>
</jar>
</target>

BIN
fr-plugin-CharCartnoon-1.0/fr-plugin-CharCartnoon-1.0.jar

Binary file not shown.

6
fr-plugin-CharCartnoon-1.0/plugin.xml

@ -6,13 +6,13 @@
<env-version>10.0</env-version>
<jartime>2018-07-31</jartime>
<vendor>all100</vendor>
<description><![CDATA[]]></description>
<description><![CDATA[以数字或文字为内容生成一些动画特效,如旋转、浮动等,注意:单元格显示内容设置为用HTML显示内容。]]></description>
<change-notes><![CDATA[
[2021-8-19]初始化插件。<br/>
]]></change-notes>
<extra-core>
<LocaleFinder class="com.fr.plugin.cool.cartnoon.FunLocaleFinder"/>
<FunctionGroup class="com.fr.plugin.cool.cartnoon.FREncryptorFunction"/>
<FunctionGroup class="com.fr.plugin.cool.cartnoon.FRCartnoonFunctions"/>
</extra-core>
<extra-decision>
@ -20,5 +20,5 @@
<URLAliasProvider class="com.fr.plugin.cool.cartnoon.web.ImageURLAliasBridge"/>
<WebResourceProvider class="com.fr.plugin.cool.cartnoon.web.CSSLoader"/>
</extra-decision>
<function-recorder class="com.fr.plugin.cool.cartnoon.FRCoolGif"/>
<function-recorder class="com.fr.plugin.cool.cartnoon.FRPrintText"/>
</plugin>

BIN
install/fr-plugin-CharCartnoon-1.0.zip

Binary file not shown.

BIN
lib/Filters.jar

Binary file not shown.

BIN
lib/thumbnailator-0.4.8.jar

Binary file not shown.

6
plugin.xml

@ -6,13 +6,13 @@
<env-version>10.0</env-version>
<jartime>2018-07-31</jartime>
<vendor>all100</vendor>
<description><![CDATA[]]></description>
<description><![CDATA[以数字或文字为内容生成一些动画特效,如旋转、浮动等,注意:单元格显示内容设置为用HTML显示内容。]]></description>
<change-notes><![CDATA[
[2021-8-19]初始化插件。<br/>
]]></change-notes>
<extra-core>
<LocaleFinder class="com.fr.plugin.cool.cartnoon.FunLocaleFinder"/>
<FunctionGroup class="com.fr.plugin.cool.cartnoon.FREncryptorFunction"/>
<FunctionGroup class="com.fr.plugin.cool.cartnoon.FRCartnoonFunctions"/>
</extra-core>
<extra-decision>
@ -20,5 +20,5 @@
<URLAliasProvider class="com.fr.plugin.cool.cartnoon.web.ImageURLAliasBridge"/>
<WebResourceProvider class="com.fr.plugin.cool.cartnoon.web.CSSLoader"/>
</extra-decision>
<function-recorder class="com.fr.plugin.cool.cartnoon.FRCoolGif"/>
<function-recorder class="com.fr.plugin.cool.cartnoon.FRPrintText"/>
</plugin>

84
src/com/fr/plugin/cool/cartnoon/FRAnimateArraow.java

@ -0,0 +1,84 @@
package com.fr.plugin.cool.cartnoon;
import com.fr.intelli.record.Focus;
import com.fr.intelli.record.Original;
import com.fr.plugin.cool.cartnoon.utils.AnimatedGifEncoder;
import com.fr.plugin.cool.cartnoon.utils.DrawValueLine;
import com.fr.plugin.cool.cartnoon.web.ImageViewer;
import com.fr.record.analyzer.EnableMetrics;
import com.fr.script.AbstractFunction;
import com.fr.stable.ColumnRow;
import com.fr.stable.Primitive;
import com.fr.stable.fun.Authorize;
import net.coobird.thumbnailator.Thumbnails;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@EnableMetrics
@Authorize(callSignKey = FunConstants.PLUGIN_ID)
public class FRAnimateArraow extends AbstractFunction {
@Override
@Focus(id = FunConstants.PLUGIN_ID, text = "Plugin-Function_FRAnimateArraow", source = Original.PLUGIN)
public Object run(Object[] args) {
if(!FunConstants.Author()){
return FunConstants.AUTHOR_ERROR;
}
if(!FunConstants.CheckArgs(args,4)){
return Primitive.ERROR_VALUE;
}
final int width= Integer.parseInt(args[0].toString());
final int height= Integer.parseInt(args[1].toString());
final Color color = FunConstants.TextToColor(args[2].toString());
final int stroke= Integer.parseInt(args[3].toString());
final String id=FunConstants.GetCellId(this);
final String url="/webroot/decision/url/img?id="+id;
try {
CreateAnimateArra(id,width,height,color,stroke);
} catch (IOException e) {
e.printStackTrace();
}
return "<img src=\""+url+"\" width=\""+width+"\" height=\""+height+"\" />";
}
private void CreateAnimateArra(String id,int width,int height,Color color,int stroke) throws IOException {
// 读数据
AnimatedGifEncoder e = new AnimatedGifEncoder();
ByteArrayOutputStream out=new ByteArrayOutputStream();
e.start(out);
e.setTransparent(new Color(255,255,255));
//图片之间间隔时间
e.setDelay(100); // 1 frame per sec
//重复次数 0表示无限重复 默认不重复
e.setRepeat(0);
//添加图片
int arraLen=width*8/10;
int len=arraLen/10;
for (int i = 1; i <= len; i++) {
final BufferedImage image = new BufferedImage(width,height,BufferedImage.TYPE_INT_ARGB);
e.addFrame(setFilter(image,i*10,stroke,stroke*2,color));
}
e.finish();
byte[] data = out.toByteArray();
ImageViewer.gifData.put(id,data);
}
//生成箭头
private BufferedImage setFilter(BufferedImage src,int arraLen, float stroke, double alh,Color color) {
int sx=src.getWidth()/10;
int sy=src.getHeight()/10;
int ex=sx+arraLen;
int ey=sy;
DrawValueLine drawValueLine= new DrawValueLine(src,sx,sy,ex,ey,alh);
drawValueLine.DrawLine(stroke,color);
return src;
}
}

32
src/com/fr/plugin/cool/cartnoon/FRCartnoonFunctions.java

@ -0,0 +1,32 @@
package com.fr.plugin.cool.cartnoon;
import com.fr.intelli.record.Focus;
import com.fr.record.analyzer.EnableMetrics;
import com.fr.stable.fun.Authorize;
import com.fr.stable.fun.impl.AbstractFunctionDefContainer;
import com.fr.stable.script.FunctionDef;
@EnableMetrics
@Authorize(callSignKey = FunConstants.PLUGIN_ID)
public class FRCartnoonFunctions extends AbstractFunctionDefContainer {
@Override
@Focus(id=FunConstants.PLUGIN_ID, text="字符动画函数")
public FunctionDef[] getFunctionDefs() {
return new FunctionDef[]{
new FunctionDef("FRPrintText", "生成打字机动画效果。\n参数说明:\n参数1:字符型,打字的文本。\n参数2:整型,显示宽度。\n参数3:整型,显示高度。\n参数4:整型,文本字号。\n参数5:整型,动画刷新频率(毫秒)。\n示例:FRPrintText(\"123456790\",500,100,20,100,\"ffff00\")", FRPrintText.class.getName()),
new FunctionDef("FRRollText", "生成浮动文本动画效果。\n参数说明:\n参数1:字符型,要浮动的文本。\n参数2:整型,文本字号。\n参数3:字符型,文本颜色。\n示例:FRRollText(\"2021\",25,\"ff0000\")", FRRollText.class.getName()),
new FunctionDef("FRDissolveText", "生成溶解文本动画效果。\n参数说明:\n参数1:字符型,要溶解的文本。\n参数2:整型,文本宽度。\n参数3:整型,文本高度。\n参数4:整型,文本字号。\n参数5:整型,动画刷新频率(毫秒)。\n示例:FRDissolveText(\"88888888888\",180,50,25,300,\"ff0000\")", FRDissolveText.class.getName()),
new FunctionDef("FRRotateText", "生成旋转文本动画效果。\n参数说明:\n参数1:字符型,要旋转的文本。\n参数2:整型,文本宽度。\n参数3:整型,文本高度。\n参数4:整型,文本字号。\n参数5:整型,动画刷新频率(毫秒)。\n示例:FRRotateText(\"你好,世界\",180,180,25,300,\"ff0000\")", FRRotateText.class.getName()),
new FunctionDef("FRAnimateArraow", "生成箭头动画效果。\n参数说明:\n参数1:整型,页面占用宽度。\n参数2:整型,页面占用高度。\n参数3:文本,箭头颜色,如FF0000。\n参数4:整型,箭头粗细。\n示例:FRAnimateArraow(300,200,\"ff0000\",10)", FRAnimateArraow.class.getName()),
new FunctionDef("FRCountUp", "生成数字计数动画效果。\n参数说明:\n参数1:整型,要计数的数字。\n参数2:整型,显示宽度。\n参数3:整型,显示高度。\n参数4:整型,文本字号。\n参数5:整型,动画刷新频率(毫秒)。\n示例:FRCountUp(\"123456790\",500,100,20,100,\"ffff00\")", FRCountUp.class.getName()),
};
}
@Override
public String getGroupName() {
if (!FunConstants.Author()) {
return FunConstants.AUTHOR_ERROR;
}
return "字符动画函数";
}
}

42
src/com/fr/plugin/cool/cartnoon/FRCountUp.java

@ -0,0 +1,42 @@
package com.fr.plugin.cool.cartnoon;
import com.fr.intelli.record.Focus;
import com.fr.intelli.record.Original;
import com.fr.record.analyzer.EnableMetrics;
import com.fr.script.AbstractFunction;
import com.fr.stable.Primitive;
import com.fr.stable.fun.Authorize;
import java.awt.*;
@EnableMetrics
@Authorize(callSignKey = FunConstants.PLUGIN_ID)
public class FRCountUp extends AbstractFunction {
@Override
@Focus(id = FunConstants.PLUGIN_ID, text = "Plugin-Function_FRCountUp", source = Original.PLUGIN)
public Object run(Object[] args) {
if(!FunConstants.Author()){
return FunConstants.AUTHOR_ERROR;
}
if(!FunConstants.CheckArgs(args,6)){
return Primitive.ERROR_VALUE;
}
final Integer number = Integer.parseInt(args[0].toString());
int width= Integer.parseInt(args[1].toString());
int height= Integer.parseInt(args[2].toString());
int fontSize= Integer.parseInt(args[3].toString());
int rate= Integer.parseInt(args[4].toString());
final Color color = FunConstants.TextToColor(args[5].toString());
final String id=FunConstants.GetCellId(this);
final String url="/webroot/decision/url/img?id="+id;
FunConstants.CreateCountUpAnimate(id,number,fontSize,rate,color,width);
return "<img src=\""+url+"\" width=\""+width+"\" height=\""+height+"\" />";
}
}

78
src/com/fr/plugin/cool/cartnoon/FRDissolveText.java

@ -0,0 +1,78 @@
package com.fr.plugin.cool.cartnoon;
import com.fr.intelli.record.Focus;
import com.fr.intelli.record.Original;
import com.fr.plugin.cool.cartnoon.utils.AnimatedGifEncoder;
import com.fr.plugin.cool.cartnoon.web.ImageViewer;
import com.fr.record.analyzer.EnableMetrics;
import com.fr.script.AbstractFunction;
import com.fr.stable.ColumnRow;
import com.fr.stable.Primitive;
import com.fr.stable.fun.Authorize;
import com.jhlabs.image.DissolveFilter;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
@EnableMetrics
@Authorize(callSignKey = FunConstants.PLUGIN_ID)
public class FRDissolveText extends AbstractFunction {
@Override
@Focus(id = FunConstants.PLUGIN_ID, text = "Plugin-Function_FRDissolveText", source = Original.PLUGIN)
public Object run(Object[] args) {
if(!FunConstants.Author()){
return FunConstants.AUTHOR_ERROR;
}
if(!FunConstants.CheckArgs(args,6)){
return Primitive.ERROR_VALUE;
}
final String text = args[0].toString();
int width= Integer.parseInt(args[1].toString());
int height= Integer.parseInt(args[2].toString());
int fontSize= Integer.parseInt(args[3].toString());
int rate= Integer.parseInt(args[4].toString());
final Color color = FunConstants.TextToColor(args[5].toString());
final String id=FunConstants.GetCellId(this);
final String url="/webroot/decision/url/img?id="+id;
CreateDissoveText(id,text,fontSize,rate,color,width);
return "<img src=\""+url+"\" width=\""+width+"\" height=\""+height+"\" />";
}
private void CreateDissoveText(String id,String text,int fontSize,int rate,Color color,int width) {
// 读数据
AnimatedGifEncoder e = new AnimatedGifEncoder();
ByteArrayOutputStream out=new ByteArrayOutputStream();
e.start(out);
//图片之间间隔时间
e.setDelay(rate); // 1 frame per sec
//重复次数 0表示无限重复 默认不重复
e.setRepeat(0);
//添加图片
final BufferedImage image = FunConstants.ImageFromText(text, fontSize, color, width);
for (float i = 0; i <= 9; i++) {
float v=i/10;
e.addFrame(setFilter(image,v,v));
}
e.finish();
byte[] data = out.toByteArray();
ImageViewer.gifData.put(id,data);
}
//设置图像溶解效果
private BufferedImage setFilter(BufferedImage src, float density, float softness) {
BufferedImage result = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TYPE_4BYTE_ABGR);
DissolveFilter dissolveFilter = new DissolveFilter();
dissolveFilter.setDensity(density);
dissolveFilter.setSoftness(softness);
dissolveFilter.filter(src, result);
return result;
}
}

19
src/com/fr/plugin/cool/cartnoon/FREncryptorFunction.java

@ -1,19 +0,0 @@
package com.fr.plugin.cool.cartnoon;
import com.fr.stable.fun.impl.AbstractFunctionDefContainer;
import com.fr.stable.script.FunctionDef;
public class FREncryptorFunction extends AbstractFunctionDefContainer {
@Override
public FunctionDef[] getFunctionDefs() {
return new FunctionDef[]{
new FunctionDef("FRCoolGif", "FRCoolGif(varchar1,varchar2,logical3):生成Gif。", FRCoolGif.class.getName()),
new FunctionDef("FRRollNumber", "FRRollNumber(varchar1,varchar2,logical3):生成Gif。", FRRollNumber.class.getName()),
};
}
@Override
public String getGroupName() {
return "字符动画函数";
}
}

25
src/com/fr/plugin/cool/cartnoon/FRCoolGif.java → src/com/fr/plugin/cool/cartnoon/FRPrintText.java

@ -4,17 +4,23 @@ import com.fr.intelli.record.Focus;
import com.fr.intelli.record.Original;
import com.fr.record.analyzer.EnableMetrics;
import com.fr.script.AbstractFunction;
import com.fr.stable.ColumnRow;
import com.fr.stable.Primitive;
import com.fr.stable.fun.Authorize;
import java.awt.*;
@EnableMetrics
@Authorize(callSignKey = com.fr.plugin.cool.cartnoon.FunConstants.PLUGIN_ID)
public class FRCoolGif extends AbstractFunction {
public class FRPrintText extends AbstractFunction {
@Override
@Focus(id = com.fr.plugin.cool.cartnoon.FunConstants.PLUGIN_ID, text = "Plugin-Function_FRCoolGif", source = Original.PLUGIN)
@Focus(id = com.fr.plugin.cool.cartnoon.FunConstants.PLUGIN_ID, text = "Plugin-Function_FRPrintText", source = Original.PLUGIN)
public Object run(Object[] args) {
if(!FunConstants.Author()){
return FunConstants.AUTHOR_ERROR;
}
if(!FunConstants.CheckArgs(args,6)){
return Primitive.ERROR_VALUE;
}
final String text = args[0].toString();
int width= Integer.parseInt(args[1].toString());
@ -23,16 +29,11 @@ public class FRCoolGif extends AbstractFunction {
int rate= Integer.parseInt(args[4].toString());
final Color color = FunConstants.TextToColor(args[5].toString());
final ColumnRow currentColumnRow = this.getCalculator().getCurrentColumnRow();
final String id=FunConstants.GetCellId(this);
final String url="/webroot/decision/url/img?id="+id;
int intRow=currentColumnRow.getRow();
int intCol=currentColumnRow.getColumn();
final String strCol = String.valueOf((char) (intCol + 65));
String id=strCol+intRow;
String gifUrl="/webroot/decision/url/img?id="+id;
FunConstants.CreateGif(id,text,fontSize,rate,color,width);
return "<img src=\""+gifUrl+"\" width=\""+width+"\" height=\""+height+"\" />";
FunConstants.CreatePrintAnimate(id,text,fontSize,rate,color,width);
return "<img src=\""+url+"\" width=\""+width+"\" height=\""+height+"\" />";
}

16
src/com/fr/plugin/cool/cartnoon/FRRollNumber.java → src/com/fr/plugin/cool/cartnoon/FRRollText.java

@ -4,17 +4,21 @@ import com.fr.intelli.record.Focus;
import com.fr.intelli.record.Original;
import com.fr.record.analyzer.EnableMetrics;
import com.fr.script.AbstractFunction;
import com.fr.stable.ColumnRow;
import com.fr.stable.Primitive;
import com.fr.stable.fun.Authorize;
import java.awt.*;
@EnableMetrics
@Authorize(callSignKey = FunConstants.PLUGIN_ID)
public class FRRollNumber extends AbstractFunction {
public class FRRollText extends AbstractFunction {
@Override
@Focus(id = FunConstants.PLUGIN_ID, text = "Plugin-Function_FRCoolGif", source = Original.PLUGIN)
@Focus(id = FunConstants.PLUGIN_ID, text = "Plugin-Function_FRRollText", source = Original.PLUGIN)
public Object run(Object[] args) {
if(!FunConstants.Author()){
return FunConstants.AUTHOR_ERROR;
}
if(!FunConstants.CheckArgs(args,3)){
return Primitive.ERROR_VALUE;
}
final String text = args[0].toString();
int fontsize= Integer.parseInt(args[1].toString());
@ -24,7 +28,7 @@ public class FRRollNumber extends AbstractFunction {
}
private String CreateDiv(String number,int fontsize,String color){
String beginText="<div class=\"text\" style=\"--fsize:"+fontsize+"vmin\";--fcolor:#"+color+"\";>";
String beginText="<div class=\"text\" style=\"--fsize:"+fontsize+"vmin;--fcolor:#"+color+"\";>";
String endText="</div>";
int numLen=number.length();
String divText="";

80
src/com/fr/plugin/cool/cartnoon/FRRotateText.java

@ -0,0 +1,80 @@
package com.fr.plugin.cool.cartnoon;
import com.fr.intelli.record.Focus;
import com.fr.intelli.record.Original;
import com.fr.plugin.cool.cartnoon.utils.AnimatedGifEncoder;
import com.fr.plugin.cool.cartnoon.web.ImageViewer;
import com.fr.record.analyzer.EnableMetrics;
import com.fr.script.AbstractFunction;
import com.fr.stable.Primitive;
import com.fr.stable.fun.Authorize;
import net.coobird.thumbnailator.Thumbnails;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@EnableMetrics
@Authorize(callSignKey = FunConstants.PLUGIN_ID)
public class FRRotateText extends AbstractFunction {
@Override
@Focus(id = FunConstants.PLUGIN_ID, text = "Plugin-Function_FRRotateText", source = Original.PLUGIN)
public Object run(Object[] args) {
if(!FunConstants.Author()){
return FunConstants.AUTHOR_ERROR;
}
if(!FunConstants.CheckArgs(args,6)){
return Primitive.ERROR_VALUE;
}
final String text = args[0].toString();
int width= Integer.parseInt(args[1].toString());
int height= Integer.parseInt(args[2].toString());
int fontSize= Integer.parseInt(args[3].toString());
int rate= Integer.parseInt(args[4].toString());
final Color color = FunConstants.TextToColor(args[5].toString());
final String id=FunConstants.GetCellId(this);
final String url="/webroot/decision/url/img?id="+id;
try {
CreateText(id,text,fontSize,rate,color);
} catch (IOException e) {
e.printStackTrace();
}
return "<img src=\""+url+"\" width=\""+width+"\" height=\""+height+"\" />";
}
private void CreateText(String id,String text,int fontSize,int rate,Color color) throws IOException {
// 读数据
AnimatedGifEncoder e = new AnimatedGifEncoder();
ByteArrayOutputStream out=new ByteArrayOutputStream();
e.start(out);
//图片之间间隔时间
e.setDelay(rate); // 1 frame per sec
//重复次数 0表示无限重复 默认不重复
e.setRepeat(0);
//添加图片
final BufferedImage image = FunConstants.ImageFromMultiText(text, fontSize, color);
for (float i = 1; i <= 10; i++) {
// float scale=i/10;
float rotate=i*36;
e.addFrame(setFilter(image,1,rotate));
}
e.finish();
byte[] data = out.toByteArray();
ImageViewer.gifData.put(id,data);
}
//设置图像旋转缩放
private BufferedImage setFilter(BufferedImage src, float scale, float rotate) throws IOException {
BufferedImage result = Thumbnails.of(src).scale(scale).rotate(rotate).asBufferedImage();
return result;
}
}

71
src/com/fr/plugin/cool/cartnoon/FunConstants.java

@ -1,8 +1,13 @@
package com.fr.plugin.cool.cartnoon;
import com.fr.locale.InterProviderFactory;
import com.fr.log.FineLoggerFactory;
import com.fr.plugin.context.PluginContexts;
import com.fr.plugin.cool.cartnoon.utils.AnimatedGifEncoder;
import com.fr.plugin.cool.cartnoon.web.ImageViewer;
import com.fr.script.AbstractFunction;
import com.fr.script.Calculator;
import com.fr.stable.ColumnRow;
import com.fr.stable.fun.Authorize;
import sun.font.FontDesignMetrics;
@ -14,6 +19,15 @@ import java.io.ByteArrayOutputStream;
@Authorize(callSignKey = FunConstants.PLUGIN_ID)
public class FunConstants {
static final String PLUGIN_ID = "com.fr.plugin.cool.cartnoon";
static final String AUTHOR_ERROR = InterProviderFactory.getProvider().getLocText("Plugin.Function.CartNoon_AUTHOR_ERROR");
static boolean Author() {
return PluginContexts.currentContext().isAvailable();
}
static boolean CheckArgs(Object[] args,int num) {
return args.length==num;
}
static Color TextToColor(String ColorText) {
Color result=new Color(0,0,0);
if (ColorText.length() != 6) {
@ -52,8 +66,28 @@ public class FunConstants {
g2.dispose();
return img;
}
final static BufferedImage ImageFromMultiText(String text, int fontSize, Color color) {
Font font = new Font("黑体", Font.BOLD, fontSize);
FontMetrics fm = FontDesignMetrics.getMetrics(font);
int textWidth = fm.stringWidth(text);
int textHeight=fm.getHeight();
final int top = fm.getAscent()+(textWidth-textHeight)/2;
BufferedImage img = new BufferedImage(textWidth, textWidth, BufferedImage.TYPE_4BYTE_ABGR);
Graphics2D g2 = img.createGraphics();
FineLoggerFactory.getLogger().info("textWidth,textHeightY:{},{}",textWidth,textHeight);
AffineTransform affineTransform = new AffineTransform();
Font rotatedFont = font.deriveFont(affineTransform);
g2.setFont(rotatedFont);
g2.setColor(color);
g2.drawString(text, 0, top);
g2.dispose();
return img;
}
final static void CreateGif(String id,String text,int fontSize,int rate,Color color,int width) {
final static void CreatePrintAnimate(String id, String text, int fontSize, int rate, Color color, int width) {
// 读数据
int len=text.length();
@ -78,4 +112,39 @@ public class FunConstants {
byte[] data = out.toByteArray();
ImageViewer.gifData.put(id,data);
}
final static void CreateCountUpAnimate(String id, Integer number, int fontSize, int rate, Color color, int width) {
// 读数据
int len=10;
int step=number/len;
AnimatedGifEncoder e = new AnimatedGifEncoder();
ByteArrayOutputStream out=new ByteArrayOutputStream();
e.start(out);
//图片之间间隔时间
e.setDelay(rate); // 1 frame per sec
//重复次数 0表示无限重复 默认不重复
e.setRepeat(0);
//添加图片
String subStr;
for (int i = 0; i <= len; i++) {
subStr=String.valueOf(i*step);
e.addFrame(ImageFromText(subStr,fontSize,color,width));
}
e.finish();
byte[] data = out.toByteArray();
ImageViewer.gifData.put(id,data);
}
static String GetCellId(AbstractFunction calculator){
String[] result={};
final ColumnRow currentColumnRow = calculator.getCalculator().getCurrentColumnRow();
int intRow=currentColumnRow.getRow();
int intCol=currentColumnRow.getColumn();
final String strCol = String.valueOf((char) (intCol + 65));
String id=strCol+intRow;
return id;
}
}

88
src/com/fr/plugin/cool/cartnoon/TestFun.java

@ -1,37 +1,77 @@
package com.fr.plugin.cool.cartnoon;
import com.fr.base.BaseUtils;
import com.fr.plugin.cool.cartnoon.utils.AnimatedGifEncoder;
import com.fr.plugin.cool.cartnoon.utils.DrawValueLine;
import com.fr.plugin.cool.cartnoon.web.ImageViewer;
import javafx.scene.shape.Shape3D;
import net.coobird.thumbnailator.Thumbnails;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.geom.GeneralPath;
import java.awt.image.BufferedImage;
import java.io.*;
public class TestFun {
public static final int SIZE = 200;
public static void main(String args[]) throws Exception {
BufferedImage image1 = ImageIO.read(new File("D:/123.jpg"));
BufferedImage image2 = ImageIO.read(new File("D:/456.jpg"));
AnimatedGifEncoder e = new AnimatedGifEncoder();
//生成的图片路径
// e.start(new FileOutputStream("D:/testgif.gif"));
final FileOutputStream fileOutputStream = new FileOutputStream("D:/testgif.gif");
ByteArrayOutputStream out=new ByteArrayOutputStream();
e.start(out);
//图片之间间隔时间
e.setDelay(500); // 1 frame per sec
//重复次数 0表示无限重复 默认不重复
e.setRepeat(0);
//添加图片
e.addFrame(image1);
e.addFrame(image2);
e.finish();
byte[] data = out.toByteArray();
fileOutputStream.write(data);
ByteArrayInputStream input = new ByteArrayInputStream(data);
BufferedImage image = ImageIO.read(input);
File outputfile = new File("d:/bufferimage.gif");
ImageIO.write(image, "GIF", outputfile);
// BufferedImage image1 = new BufferedImage(500, 500, BufferedImage.TYPE_4BYTE_ABGR);
// DrawValueLine drawValueLine= new DrawValueLine(image1,50,50,250,50,24.0);
// drawValueLine.DrawLine(10);
// final BufferedImage image = BaseUtils.readImage("com/fr/plugin/cool/cartnoon/web/resource/images/click.png");
BufferedImage image = BaseUtils.readImage("I:\\Users\\Administrator\\2020\\report-starter-10\\plugin-function-char-cartnoon\\src\\com\\fr\\plugin\\cool\\cartnoon\\web\\resource\\images\\click.png");
final BufferedImage hour = BaseUtils.readImage("I:\\Users\\Administrator\\2020\\report-starter-10\\plugin-function-char-cartnoon\\src\\com\\fr\\plugin\\cool\\cartnoon\\web\\resource\\images\\hour.png");
final BufferedImage minute = BaseUtils.readImage("I:\\Users\\Administrator\\2020\\report-starter-10\\plugin-function-char-cartnoon\\src\\com\\fr\\plugin\\cool\\cartnoon\\web\\resource\\images\\minute.png");
image=setSize(image,300,300);
AnimatedGifEncoder encoder = new AnimatedGifEncoder();
encoder.start("d:\\out.gif");
encoder.setTransparent(Color.WHITE);
encoder.setRepeat(0);
encoder.setDelay(100);
Graphics2D g2d = image.createGraphics();
int x1=image.getWidth()/2;
int y1=image.getHeight()/2;
int x2=x1;
int y2=y1/2;
int htime=9;
int mtime=20;
int hr=htime*(360+30)/12;
int hrr=htime*360/12;
int hrm=mtime*30/60;
int mr=mtime*360/60;
System.out.printf("\nhrm:"+hrm);
int o=36;
for (int i=0; i<=o; i++) {
g2d.setColor(Color.WHITE);
BufferedImage hImage1=setFilter(hour,1,hrr+i*hrm/o);
BufferedImage hImage2=setSize(hImage1,image.getWidth(),image.getHeight());
g2d.fillRect(x1/2,y1/2,x1,y1);
g2d.drawImage(hImage2,null,0,0);
BufferedImage mImage1=setFilter(minute,1,i*mr/o);
BufferedImage mImage2=setSize(mImage1,image.getWidth(),image.getHeight());
g2d.drawImage(mImage2,null,0,0);
encoder.addFrame(image);
}
for (int i = 0; i <10 ; i++) {
encoder.addFrame(image);
}
g2d.dispose();
encoder.finish();
}
//设置图像旋转缩放
private static BufferedImage setFilter(BufferedImage src, float scale, float rotate) throws IOException {
BufferedImage result = Thumbnails.of(src).scale(scale).rotate(rotate).asBufferedImage();
return result;
}
private static BufferedImage setSize(BufferedImage src, int width, int height) throws IOException {
BufferedImage result = Thumbnails.of(src).size(width,height).asBufferedImage();
return result;
}
}

98
src/com/fr/plugin/cool/cartnoon/utils/DrawValueLine.java

@ -0,0 +1,98 @@
package com.fr.plugin.cool.cartnoon.utils;
import java.awt.*;
import java.awt.geom.AffineTransform;
import java.awt.geom.GeneralPath;
import java.awt.image.BufferedImage;
/*
*
* 划线
* */
final public class DrawValueLine {
private int startX;
private int startY;
private int endX;
private int endY;
private double alHeight;
private Graphics2D g2;
//划线起止位置
public DrawValueLine(BufferedImage image, int sx, int sy, int ex, int ey, double alH) {
g2 = (Graphics2D) image.getGraphics();
startX = sx;
startY = sy;
endX = ex;
endY = ey;
alHeight = alH;
}
//划线 (粗细,是否旋转)
public void DrawLine(float stroke,Color color) {
g2.setColor(color);
g2.setStroke(new BasicStroke(stroke));
// g2.drawLine(this.startX, this.startY, this.endX, this.endY);
drawAL(this.startX, this.startY , this.endX, this.endY , alHeight);
}
//划箭头线
public void drawAL(int sx, int sy, int ex, int ey, double alHeight) {
double L = alHeight / 2; // 底边的一半
int x3 = 0;
int y3 = 0;
int x4 = 0;
int y4 = 0;
double awrad = Math.atan(L / alHeight); // 箭头角度
double arraow_len = Math.sqrt(L * L + alHeight * alHeight); // 箭头的长度
double[] arrXY_1 = rotateVec(ex - sx, ey - sy, awrad, true, arraow_len);
double[] arrXY_2 = rotateVec(ex - sx, ey - sy, -awrad, true, arraow_len);
double x_3 = ex - arrXY_1[0]; // (x3,y3)是第一端点
double y_3 = ey - arrXY_1[1];
double x_4 = ex - arrXY_2[0]; // (x4,y4)是第二端点
double y_4 = ey - arrXY_2[1];
Double X3 = new Double(x_3);
x3 = X3.intValue();
Double Y3 = new Double(y_3);
y3 = Y3.intValue();
Double X4 = new Double(x_4);
x4 = X4.intValue();
Double Y4 = new Double(y_4);
y4 = Y4.intValue();
// 画线
g2.drawLine(sx, sy, ex, ey);
//
GeneralPath triangle = new GeneralPath();
double anglRate=(new Double(ey)-new Double(sy))/(new Double(ex)-new Double(sx));
double angl=ex==sx?1:Math.atan(anglRate)/Math.PI*2;
triangle.moveTo(ex+new Double(L)*2*(1-angl), ey+new Double(L)*2*angl);
triangle.lineTo(x3+new Double(L)*2, y3);
triangle.lineTo(x4+new Double(L)*2, y4);
triangle.closePath();
//实心箭头
g2.fill(triangle);
}
// 计算
private static double[] rotateVec(int px, int py, double ang,
boolean isChLen, double newLen) {
double mathstr[] = new double[2];
// 矢量旋转函数,参数含义分别是x分量、y分量、旋转角、是否改变长度、新长度
double vx = px * Math.cos(ang) - py * Math.sin(ang);
double vy = px * Math.sin(ang) + py * Math.cos(ang);
if (isChLen) {
double d = Math.sqrt(vx * vx + vy * vy);
vx = vx / d * newLen;
vy = vy / d * newLen;
mathstr[0] = vx;
mathstr[1] = vy;
}
return mathstr;
}
}

BIN
src/com/fr/plugin/cool/cartnoon/web/resource/images/click.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

BIN
src/com/fr/plugin/cool/cartnoon/web/resource/images/hour.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

BIN
src/com/fr/plugin/cool/cartnoon/web/resource/images/minute.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

Loading…
Cancel
Save