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