|
@@ -62,6 +62,11 @@ export async function addWatermark(
|
|
|
// const size = sizeOf(image);
|
|
|
// console.log(size);
|
|
|
const imgData = gm(image);
|
|
|
+ const drawText = (l: number, t: number, content: string) => {
|
|
|
+ const top = t < 30 ? 30 : t > imageHeight ? imageHeight : t;
|
|
|
+ const left = l > imageWidth - 30 ? imageWidth - 30 : l;
|
|
|
+ imgData.drawText(left, top + 30, content);
|
|
|
+ };
|
|
|
//添加第一页的得分明细
|
|
|
if (index == 1) {
|
|
|
//初始坐标
|
|
@@ -77,10 +82,10 @@ export async function addWatermark(
|
|
|
(parseFloat(student.subjectiveScore) || 0);
|
|
|
//显示总分明细
|
|
|
imgData.font(fontFile, fontSize).fill(color);
|
|
|
- imgData.drawText(x, (y += height), "成绩明细");
|
|
|
+ drawText(x, (y += height), "成绩明细");
|
|
|
//普通考试模式,按客观+主观模式显示总分
|
|
|
if (trackMode === "1") {
|
|
|
- imgData.drawText(
|
|
|
+ drawText(
|
|
|
x,
|
|
|
(y += height),
|
|
|
"总分=(客观+主观) | " +
|
|
@@ -93,7 +98,7 @@ export async function addWatermark(
|
|
|
}
|
|
|
//研究生考试模式,只显示总分
|
|
|
else if (trackMode === "2") {
|
|
|
- imgData.drawText(x, (y += height), "总分=" + totalScore + "分");
|
|
|
+ drawText(x, (y += height), "总分=" + totalScore + "分");
|
|
|
}
|
|
|
//显示客观题明细
|
|
|
if (
|
|
@@ -127,20 +132,12 @@ export async function addWatermark(
|
|
|
// y = startY;
|
|
|
// x += width;
|
|
|
// }
|
|
|
- imgData.drawText(
|
|
|
- x,
|
|
|
- (y += height),
|
|
|
- "客观题识别结果 | " + lines[l].join(";")
|
|
|
- );
|
|
|
+ drawText(x, (y += height), "客观题识别结果 | " + lines[l].join(";"));
|
|
|
}
|
|
|
}
|
|
|
//显示复核人
|
|
|
if (student.inspector) {
|
|
|
- imgData.drawText(
|
|
|
- x,
|
|
|
- (y += height),
|
|
|
- "复核人: " + student.inspector.loginName
|
|
|
- );
|
|
|
+ drawText(x, (y += height), "复核人: " + student.inspector.loginName);
|
|
|
}
|
|
|
//显示主观题明细
|
|
|
if (
|
|
@@ -152,14 +149,14 @@ export async function addWatermark(
|
|
|
const title = "主观题号 | 分数 | 评卷员 | 仲裁员";
|
|
|
const startY = y;
|
|
|
let width = title.length * fontSize;
|
|
|
- imgData.drawText(x, (y += height), title);
|
|
|
+ drawText(x, (y += height), title);
|
|
|
for (let i = 0; i < student.subjectiveScoreDetail.length; i++) {
|
|
|
const detail = student.subjectiveScoreDetail[i];
|
|
|
//超过最大高度了则另起一列
|
|
|
if (y + height + 15 > imageHeight) {
|
|
|
y = startY;
|
|
|
x += width;
|
|
|
- imgData.drawText(x, (y += height), title);
|
|
|
+ drawText(x, (y += height), title);
|
|
|
}
|
|
|
const content =
|
|
|
detail.mainNumber +
|
|
@@ -172,7 +169,7 @@ export async function addWatermark(
|
|
|
" " +
|
|
|
(detail.header || "");
|
|
|
width = Math.max(width, content.length * fontSize);
|
|
|
- imgData.drawText(x, (y += height), content);
|
|
|
+ drawText(x, (y += height), content);
|
|
|
}
|
|
|
}
|
|
|
//研究生考试模式,按分组显示明细
|
|
@@ -180,7 +177,7 @@ export async function addWatermark(
|
|
|
const title = "评卷分组 | 总分 | 评卷员";
|
|
|
const startY = y;
|
|
|
let width = title.length * fontSize;
|
|
|
- imgData.drawText(x, (y += height), title);
|
|
|
+ drawText(x, (y += height), title);
|
|
|
//所有小题得分按评卷分组聚合
|
|
|
let maxGroupNumber = 0;
|
|
|
const groups = {};
|
|
@@ -222,7 +219,7 @@ export async function addWatermark(
|
|
|
if (y + height + 15 > imageHeight) {
|
|
|
y = startY;
|
|
|
x += width;
|
|
|
- imgData.drawText(x, (y += height), title);
|
|
|
+ drawText(x, (y += height), title);
|
|
|
}
|
|
|
const content =
|
|
|
group.number +
|
|
@@ -236,7 +233,7 @@ export async function addWatermark(
|
|
|
" " +
|
|
|
" "; //+group.headerString.join(",");
|
|
|
width = Math.max(width, content.length * fontSize);
|
|
|
- imgData.drawText(x, (y += height), content);
|
|
|
+ drawText(x, (y += height), content);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -265,7 +262,7 @@ export async function addWatermark(
|
|
|
.font(fontFile, fontSize)
|
|
|
.fill(colorMap[tag.groupNumber + ""][tag.userId + ""] || "gray");
|
|
|
for (let j = 0; j < tag.content.length; j++) {
|
|
|
- imgData.drawText(tag.left, top, tag.content[j]);
|
|
|
+ drawText(tag.left, top, tag.content[j]);
|
|
|
top += height;
|
|
|
}
|
|
|
}
|