From e1641cd8696778a1416f5ed3b5fe08acab515503 Mon Sep 17 00:00:00 2001 From: Sithel Date: Thu, 11 Apr 2024 21:13:42 -0500 Subject: [PATCH] cleaning up things... --- src/book.js | 27 +++++++++++++-------------- src/book.test.js | 1 + src/signatures.js | 5 +---- src/utils/drawing.js | 2 ++ 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/book.js b/src/book.js index 7f9c0a9..56d28cf 100644 --- a/src/book.js +++ b/src/book.js @@ -290,6 +290,8 @@ export class Book { * generate preview content AND a downloadable zip */ async createoutputfiles(isPreview) { + // set this to `true` to enable full-book previews (placeholder till it's in the UI) + const fullPreviewDevHack = true const previewFrame = document.getElementById('pdf'); let previewPdf = null; @@ -310,13 +312,13 @@ export class Book { this.format == 'customsig' ) { // Only generate the first signature for preview - const pagesArr = this.rearrangedpages; + const pagesArr = (isPreview && !fullPreviewDevHack) ? this.rearrangedpages.slice(0, 1) : this.rearrangedpages; const signatures = [{}]; const makeSignatures = async () => { const tasks = pagesArr.map(async (pages, i) => { console.log(pages); signatures[i] = { name: `${this.filename}_signature${i}` }; - [signatures[i].front, signatures[i].back] = await this.createSignatures({ + [signatures[i].front, signatures[i].back] = await this.createSignature({ pageIndexDetails: pages, maxSigCount: pagesArr.length }); @@ -335,11 +337,10 @@ export class Book { await Promise.all(tasks); }; await duplexSignatures(); - console.log("Shark") - // previewPdf = signatures[0].duplex; + previewPdf = signatures[0].duplex; } - if (this.print_file != 'aggregated' && !isPreview) { + if (this.print_file != 'aggregated' && (!isPreview || fullPreviewDevHack)) { const saveSignatures = async () => { const tasks = signatures.map(async (sig) => { await sig.front?.save().then((pdfBytes) => { @@ -357,7 +358,7 @@ export class Book { await saveSignatures(); } - if (this.print_file != 'signatures') { + if (this.print_file != 'signatures' && (!isPreview || fullPreviewDevHack)) { const saveAggregate = async () => { const aggregate = { front: !this.duplex ? await PDFDocument.create() : null, @@ -403,11 +404,10 @@ export class Book { this.zip.file(`${this.filename}_typeset.pdf`, pdfBytes); }); } - console.log("Do I have this? ",aggregate.duplex.getPageCount()) previewPdf = aggregate.duplex - return aggregate }; - var results = await saveAggregate(); + + await saveAggregate(); } var rotationMetaInfo = @@ -453,7 +453,7 @@ export class Book { } /** - * Part of the Classic (non-Wacky) flow. Called by [createsignatures]. + * Part of the Classic (non-Wacky) flow. Called by [createsignature]. * (conditionally) populates the destPdf and (conditionally) generates the outname PDF * * @param {Object} config - object /w the following parameters: @@ -464,7 +464,6 @@ export class Book { * @return reference to the new PDF created */ async writepages(config) { - console.log("Write pages ", config) const pagelist = config.pageList; const back = config.back; const maxSigCount = config.maxSigCount; @@ -549,7 +548,6 @@ export class Book { const alt = config.alt; const maxSigCount = config.maxSigCount let side2flag = config.side2flag; - console.log("burp I see ",maxSigCount) const block = config.embeddedPages.slice(block_start, block_end); const currPage = outPDF.addPage(papersize); @@ -606,13 +604,14 @@ export class Book { /** * PDF builder base function for Classic (non-Wacky) layouts. Called by [createoutputfiles] + * Generates a single signature (or is it just a single sheet? -- comments left long after coding) + * TODO : re-examine this logic and clean up this comment. What is going on?? * * @param {Object} config * @param {number} config.maxSigCount * @param {PageInfo[][]} config.pageIndexDetails : a nested list of objects. */ - async createSignatures(config) { - console.log("createSignatures ",config) + async createSignature(config) { const pages = config.pageIndexDetails; const tasks = [ this.writepages({ diff --git a/src/book.test.js b/src/book.test.js index a008292..d74e0c9 100644 --- a/src/book.test.js +++ b/src/book.test.js @@ -51,6 +51,7 @@ describe('Book model', () => { source_rotation: 'none', print_file: 'both', signatureconfig: [], + sigOrderMarks: false, }; it('returns a new Book', () => { diff --git a/src/signatures.js b/src/signatures.js index 0db40ed..0f8a861 100644 --- a/src/signatures.js +++ b/src/signatures.js @@ -141,14 +141,13 @@ export class Signatures { let front_end = center; let back_start = center; let back_end = center + pageblock; - console.log("outside") + while (front_start >= 0 && back_end <= pages.length) { const front_block = pages.slice(front_start, front_end); const back_block = pages.slice(back_start, back_end); const block = [...front_block, ...back_block]; - console.log(" ~~~~ SIG NUM "+sig_num+" on "+front_start+" --> "+back_end) front_config.forEach((pnum) => { const page = block[pnum - 1]; //page layouts are 1-indexed, not 0-index pagelistdetails[0].push({ @@ -172,9 +171,7 @@ export class Signatures { }); // Update all our counters - console.log("stepa "+front_start) front_start -= pageblock; - console.log("stepb "+front_start) front_end -= pageblock; back_start += pageblock; back_end += pageblock; diff --git a/src/utils/drawing.js b/src/utils/drawing.js index 6e26411..c44fad7 100644 --- a/src/utils/drawing.js +++ b/src/utils/drawing.js @@ -150,6 +150,8 @@ export function drawSpineMark(draw_top_mark, position, w) { /** + * TODO : these params should probably be pushed into a config... maybe next time/next pass + * * @param {import("../book.js").PageInfo} sigDetails - page info object * @param {import("../book.js").Position} position - position info object * @param {number} maxSigCount - number of total signatures