Commit 0cb17e44 authored by duanruiming's avatar duanruiming

Merge remote-tracking branch 'origin/master'

parents eb593da5 8ec38957
......@@ -107,6 +107,7 @@ public class InduceSendController {
param.setEndTime(DateUtil.format(System.currentTimeMillis() + 1000 * 60, Constants.DATE_FORMAT.E_DATE_FORMAT_SECOND));
}
induceSendService.send(param);
Thread.sleep(1000);
}
}
return jsonView.success();
......
......@@ -74,10 +74,10 @@ public class InduceTemplate implements Serializable {
private Integer textSize;
/**
* 0:横向生成、1:竖向生成
* 字体类型
*/
@TableField("text_sign")
private Boolean textSign;
@TableField("text_font")
private String textFont;
/**
* 是否默认模板 0:否 1:是
......
......@@ -116,7 +116,7 @@ public class InduceSendServiceImpl implements InduceSendService {
int bottomRightY = Integer.parseInt(bottomRight[1]);
// 图片生成操作
boolean upDown = param.getContents()[0].contains("▲") || param.getContents()[0].contains("▼");
createImageWithText(induceTemplate, image, param.getContents(), induceTemplate.getTextSign(), upDown, topLeftX, topLeftY, bottomRightX, bottomRightY);
createImageWithText(induceTemplate, image, param.getContents(), upDown, topLeftX, topLeftY, bottomRightX, bottomRightY);
}
} catch (Exception ex) {
log.error(ex.getMessage());
......@@ -296,9 +296,17 @@ public class InduceSendServiceImpl implements InduceSendService {
* @param width 绘制区域宽度
* @param height 绘制区域高度
*/
private static FontMetrics autoFont(InduceTemplate pictureFile, Graphics2D g2d, boolean sign, String[] text, int width, int height) {
/**
* 根据绘制的区域,动态调整字体大小,以适应文本区域
*
* @param g2d graphics2d对象
* @param drawParam 绘制内容
* @param width 绘制区域宽度
* @param height 绘制区域高度
*/
private static FontMetrics autoFont(Graphics2D g2d, InduceTemplate drawParam,String[] contents, int width, int height) {
// 初始化字体
Font font = new Font("Arial", Font.BOLD, 1);
Font font = new Font(drawParam.getTextFont(), Font.BOLD, 1);
g2d.setFont(font);
FontMetrics metrics = g2d.getFontMetrics();
// 字体最大、最小限制
......@@ -306,32 +314,29 @@ public class InduceSendServiceImpl implements InduceSendService {
int maxFontSize = 100;
// 动态调整字体大小以适应文本区域
for (int fontSize = minFontSize; fontSize <= maxFontSize; fontSize++) {
font = new Font("Arial", Font.BOLD, fontSize);
font = new Font(drawParam.getTextFont(), Font.BOLD, fontSize);
g2d.setFont(font);
metrics = g2d.getFontMetrics();
pictureFile.setTextSize(fontSize);
// 确保绘制区域能够容纳文本,考虑字体长度和高度
if (sign) {
// 高度考虑上下边距
if (metrics.stringWidth(text[0]) > width || (metrics.getHeight() - 4) > height) {
// 设置字体大小
font = new Font("Arial", Font.BOLD, --fontSize);
g2d.setFont(font);
metrics = g2d.getFontMetrics();
pictureFile.setTextSize(fontSize);
return metrics;
}
} else {
// if (drawParam.getTextDirection()) {
// // 高度考虑上下边距
// if (metrics.stringWidth(contents[0]) > width || (metrics.getHeight() - 4) > height) {
// // 设置字体大小
// font = new Font(drawParam.getTextFont(), Font.BOLD, --fontSize);
// g2d.setFont(font);
// metrics = g2d.getFontMetrics();
// return metrics;
// }
// } else {
// 高度只考虑上边距
if (metrics.stringWidth(text[0]) > width || (metrics.getHeight() - 1) * text.length > height) {
if (metrics.stringWidth(contents[0]) > width || (metrics.getHeight() - 1) * contents.length > height) {
// 设置字体大小
font = new Font("Arial", Font.BOLD, --fontSize);
font = new Font(drawParam.getTextFont(), Font.BOLD, --fontSize);
g2d.setFont(font);
metrics = g2d.getFontMetrics();
pictureFile.setTextSize(fontSize);
return metrics;
}
}
// }
}
// 若字体大小超出限制,则返回最小字体
return metrics;
......@@ -348,7 +353,7 @@ public class InduceSendServiceImpl implements InduceSendService {
* @param bottomRightX 区域右下角x坐标
* @param bottomRightY 区域右下角y坐标
*/
public static void createImageWithText(InduceTemplate pictureFile, BufferedImage image, String[] text, boolean sign,boolean updown, int topLeftX, int topLeftY, int bottomRightX, int bottomRightY) {
public static void createImageWithText(InduceTemplate pictureFile, BufferedImage image, String[] text, boolean updown, int topLeftX, int topLeftY, int bottomRightX, int bottomRightY) {
// 创建Graphics2D对象
Graphics2D g2d = image.createGraphics();
// 转换坐标,原始坐标从底部开始,转换为顶部坐标
......@@ -359,7 +364,7 @@ public class InduceSendServiceImpl implements InduceSendService {
int width = bottomRightX - topLeftX;
int height = bottomRightY - topLeftY;
// 动态调整字体大小,以适应文本区域
FontMetrics metrics = autoFont(pictureFile, g2d, sign, text, width, height);
FontMetrics metrics = autoFont( g2d,pictureFile, text, width, height);
// 绘制坐标点
int textWidth;
// 考虑文字绘制方向、文字居中。垂直居中要根据文字高度,水平居中要根据文字宽度。
......@@ -369,7 +374,7 @@ public class InduceSendServiceImpl implements InduceSendService {
// 设置文字颜色
g2d.setColor(Color.green);
// 根据方向开始文字绘制
if (sign) {
if (true) {
// 因文字动态调整的字体大小,所以此处代码不应该被执行
// if (currentX < topLeftX) {
// currentX = topLeftX; // 若超出左边界,调整为左边界
......@@ -380,9 +385,6 @@ public class InduceSendServiceImpl implements InduceSendService {
currentX = topLeftX + (width - textWidth) / 2;
// 计算居中的y坐标
currentY = currentY + (height - metrics.getHeight()) / 2;
if (updown) {
currentX -= 33;
}
g2d.drawString(text[0], currentX, currentY);
} else {
// 计算每个文本内容的竖向绘制坐标
......
......@@ -194,14 +194,14 @@ public class InducesMonitorTask {
greenwaveInducesHist.setType(greenOptHistEntity.getType());// 执行策略
String upDown = "";
// 计算绿波速度变化趋势
// if (Objects.nonNull(greenwaveInducesHist.getMinSpeed()) && Objects.nonNull(greenwaveInducesHist.getMaxSpeed()) && Objects.nonNull(greenOptHistEntity.getMinSpeed()) && Objects.nonNull(greenOptHistEntity.getMaxSpeed())) {
// if (greenwaveInducesHist.getMinSpeed() > greenOptHistEntity.getMinSpeed() || greenwaveInducesHist.getMaxSpeed() > greenOptHistEntity.getMaxSpeed()) {
// upDown = "▼ ";
// }
// if (greenwaveInducesHist.getMinSpeed() < greenOptHistEntity.getMinSpeed() || greenwaveInducesHist.getMaxSpeed() < greenOptHistEntity.getMaxSpeed()) {
// upDown = "▲ ";
// }
// }
if (Objects.nonNull(greenwaveInducesHist.getMinSpeed()) && Objects.nonNull(greenwaveInducesHist.getMaxSpeed()) && Objects.nonNull(greenOptHistEntity.getMinSpeed()) && Objects.nonNull(greenOptHistEntity.getMaxSpeed())) {
if (greenwaveInducesHist.getMinSpeed() > greenOptHistEntity.getMinSpeed() || greenwaveInducesHist.getMaxSpeed() > greenOptHistEntity.getMaxSpeed()) {
upDown = "▼";
}
if (greenwaveInducesHist.getMinSpeed() < greenOptHistEntity.getMinSpeed() || greenwaveInducesHist.getMaxSpeed() < greenOptHistEntity.getMaxSpeed()) {
upDown = "▲";
}
}
greenwaveInducesHist.setMinSpeed(greenOptHistEntity.getMinSpeed());
greenwaveInducesHist.setMaxSpeed(greenOptHistEntity.getMaxSpeed());
// greenwaveInducesHist.setDir(greenOptHistEntity.getDirType());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment