Commit edf07860 authored by nanahira's avatar nanahira

tune

parent 696ceae9
Pipeline #41250 passed with stages
in 2 minutes and 26 seconds
......@@ -34,11 +34,7 @@ export class AppService extends ConsoleLogger {
const directDrawFields = ['name', 'event', 'lastInitial'] as const;
for (const field of directDrawFields) {
if (!dto[field]) continue;
await this.drawTextService.drawTextInBox(
doc,
dto[field],
Coordinates[field],
);
this.drawTextService.drawTextInBox(doc, dto[field], Coordinates[field]);
}
this.log(`Filled direct draw fields.`);
if (dto.date) {
......@@ -59,7 +55,7 @@ export class AppService extends ConsoleLogger {
dateChars[7],
];
for (let i = 0; i < datePrintStr.length; i++) {
await this.drawTextService.drawTextInBox(
this.drawTextService.drawTextInBox(
doc,
datePrintStr[i],
moveRight(Coordinates.dateFirst, i),
......@@ -72,7 +68,7 @@ export class AppService extends ConsoleLogger {
const totalCounts = [ydk.main.length, ydk.extra.length, ydk.side.length];
for (let i = 0; i < 3; ++i) {
await this.drawTextService.drawTextInBox(
this.drawTextService.drawTextInBox(
doc,
totalCounts[i].toString(),
moveRight(Coordinates.totalFirst, i),
......@@ -84,7 +80,7 @@ export class AppService extends ConsoleLogger {
const copyFirstPageToBottom = async () => {
const [newPage] = await doc.copyPages(doc, [0]);
doc.addPage(newPage);
this.drawTextService.duplicateOperations(doc, 0, doc.getPageCount() - 1);
// this.drawTextService.duplicateOperations(doc, 0, doc.getPageCount() - 1);
};
const cards = [...new Set([...ydk.main, ...ydk.extra, ...ydk.side])];
......@@ -142,7 +138,7 @@ export class AppService extends ConsoleLogger {
spaces = 20,
) => {
const groupedCards = Object.values(_.groupBy(cards, (id) => id));
const drawCardsOnPage = async (
const drawCardsOnPage = (
currentPageCards: number[][],
pageIndex: number,
) => {
......@@ -160,20 +156,20 @@ export class AppService extends ConsoleLogger {
).toException();
}
await this.drawTextService.drawTextInBox(
this.drawTextService.drawTextInBox(
doc,
qty.toString(),
moveDown(cord.qty, j),
pageIndex,
);
await this.drawTextService.drawTextInBox(
this.drawTextService.drawTextInBox(
doc,
cardData[`${dto.lang || 'sc'}_name`],
moveDown(cord.name, j),
pageIndex,
);
}
await this.drawTextService.drawTextInBox(
this.drawTextService.drawTextInBox(
doc,
_.sumBy(currentPageCards, (s) => s.length).toString(),
moveDown(cord.qty, spaces),
......@@ -183,7 +179,7 @@ export class AppService extends ConsoleLogger {
const usePages = _.chunk(groupedCards, spaces);
await ensurePages(usePages.length - 1);
for (let i = 0; i < usePages.length; ++i) {
await drawCardsOnPage(usePages[i], i);
drawCardsOnPage(usePages[i], i);
}
};
await drawCards(filterType(1), Coordinates.main.monsters);
......
......@@ -42,12 +42,12 @@ export class DrawTextService {
/**
* 在指定矩形内绘制文本(改为仅记录步骤;仍保持 async 签名以兼容调用端)
*/
async drawTextInBox(
drawTextInBox(
doc: PDFDocument,
text: string,
options: DrawTextOptions,
pageCount = 0,
): Promise<void> {
pageCount = -1,
) {
if (!text) return;
const ops = this.ensureOps(doc);
ops.push({
......@@ -88,14 +88,26 @@ export class DrawTextService {
// 4) 回放并实际绘制
for (const op of ops) {
if (op.kind === 'drawTextInBox') {
await this.drawTextInBoxWithFont(
doc,
subsetFont,
op.text,
op.options,
op.pageIndex,
);
const runOp = async (pc: number) => {
if (op.kind === 'drawTextInBox') {
await this.drawTextInBoxWithFont(
doc,
subsetFont,
op.text,
op.options,
pc,
);
}
};
if (op.pageIndex === -1) {
// 应用到所有页面
const pageCount = doc.getPageCount();
for (let i = 0; i < pageCount; ++i) {
await runOp(i);
}
} else {
// 仅应用到指定页面
await runOp(op.pageIndex);
}
}
......@@ -192,6 +204,7 @@ export class DrawTextService {
});
}
/*
duplicateOperations(doc: PDFDocument, fromPage: number, toPage: number) {
const ops = this.operations.get(doc);
if (!ops) return;
......@@ -207,4 +220,5 @@ export class DrawTextService {
}
ops.push(...newOps);
}
*/
}
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