diff --git a/src/book.js b/src/book.js index 977e2e0..d0f0b89 100644 --- a/src/book.js +++ b/src/book.js @@ -5,7 +5,6 @@ import { PDFDocument, degrees, rgb } from 'pdf-lib'; import { saveAs } from 'file-saver'; import { Signatures } from './signatures.js'; -import { PerfectBound } from './perfectbound.js'; import { WackyImposition } from './wacky_imposition.js'; import { PAGE_LAYOUTS, PAGE_SIZES, LINE_LEN } from './constants.js'; import { updatePageLayoutInfo } from './utils/renderUtils.js'; @@ -203,17 +202,16 @@ export class Book { switch (this.format) { case 'perfect': - this.book = new PerfectBound( - this.orderedpages, - this.duplex, - this.per_sheet, - this.duplexrotate - ); - this.rearrangedpages = [this.book.pagelistdetails]; - break; case 'booklet': - // Booklets are a special case where sig size is the total book size - this.sigsize = Math.ceil(this.orderedpages.length / this.per_sheet); + if (this.format == 'perfect') { + // Perfect bind is a special case where sig size is 1 + this.sigsize = 1; + } else { + // Booklets are a special case where sig size is the total book size + this.sigsize = Math.ceil(this.orderedpages.length / this.per_sheet); + } + // Only generate aggragated file for perfectbound and booklets + this.print_file = 'aggregated'; /* falls through */ case 'standardsig': case 'customsig': diff --git a/src/perfectbound.js b/src/perfectbound.js deleted file mode 100644 index 36005f0..0000000 --- a/src/perfectbound.js +++ /dev/null @@ -1,59 +0,0 @@ -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. -import { PERFECTBOUND_LAYOUTS } from './constants'; - -export class PerfectBound { - // Duplex printer pages are arranged in a 4-1-2-3 pattern. - // Single-sided pages are arranged in two sets, 4-1 and 2-3. - // After printing two to a page, each sheet is folded in half - // and all the sheets collated into a block for gluing. - // this.pagelist holds the rearranged index numbers that the - // book class uses to create a finished document - constructor(pages, duplex, per_sheet, duplexrotate) { - this.duplex = duplex; - this.per_sheet = per_sheet || 4; // pages per sheet - default is 4. - this.duplexrotate = duplexrotate || false; - - this.sheets = Math.ceil(pages.length / per_sheet); - this.sigconfig = ['N/A']; - - const { front, rotate, back } = PERFECTBOUND_LAYOUTS[per_sheet]; - const front_config = front; - const back_config = duplexrotate ? rotate : back; - - this.pagelistdetails = duplex ? [[]] : [[], []]; - - // Pad the page list with blanks if necessary - const totalpages = this.sheets * per_sheet; - if (totalpages > pages.length) { - const diff = totalpages - pages.length; - const blanks = new Array(diff).fill('b'); - this.inputpagelist.push(...blanks); - } - - for (let i = 0; i < pages.length; i = i + per_sheet) { - const block = pages.slice(i, i + per_sheet); - - front_config.forEach((pnum) => { - const page = block[pnum - 1]; //page layouts are 1-indexed, not 0-index - this.pagelistdetails[0].push({ - info: page, - isSigStart: true, - isSigEnd: true, - }); - }); - - const backlist = this.duplex ? 0 : 1; - - back_config.forEach((pnum) => { - const page = block[pnum - 1]; - this.pagelistdetails[backlist].push({ - info: page, - isSigStart: true, - isSigEnd: true, - }); - }); - } - } -} diff --git a/src/perfectbound.test.js b/src/perfectbound.test.js deleted file mode 100644 index 0687464..0000000 --- a/src/perfectbound.test.js +++ /dev/null @@ -1,77 +0,0 @@ -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. - -import { expect, describe, it } from 'vitest'; - -import { PerfectBound } from './perfectbound'; - -const testPages = []; -const testPagesEven = Array.from({ length: 32 }, (x, i) => i + 1); -const generatePageInfo = (page) => { - return { info: page, isSigEnd: true, isSigStart: true }; -}; - -describe('PerfectBound model', () => { - it('returns config for a perfectbound booklet based on params (default)', () => { - const testDuplex = true; - const expected = { - duplex: true, - sheets: 0, - per_sheet: 4, - duplexrotate: true, - sigconfig: ['N/A'], - pagelistdetails: [[]], - }; - const actual = new PerfectBound(testPages, testDuplex, 4, true); - expect(actual).toEqual(expected); - }); - - it('returns config for a perfectbound booklet based on params (no duplex)', () => { - const testDuplex = false; - const expected = { - duplex: false, - duplexrotate: false, - sheets: 0, - per_sheet: 4, - sigconfig: ['N/A'], - pagelistdetails: [[], []], - }; - const actual = new PerfectBound(testPages, testDuplex, 4, false); - expect(actual).toEqual(expected); - }); - - it('correctly orders folio pages with no duplex', () => { - const testDuplex = false; - const expected = { - duplex: false, - duplexrotate: false, - sheets: 8, - per_sheet: 4, - sigconfig: ['N/A'], - pagelistdetails: [ - [3, 2, 7, 6, 11, 10, 15, 14, 19, 18, 23, 22, 27, 26, 31, 30].map(generatePageInfo), - [1, 4, 5, 8, 9, 12, 13, 16, 17, 20, 21, 24, 25, 28, 29, 32].map(generatePageInfo), - ], - }; - const actual = new PerfectBound(testPagesEven, testDuplex, 4, false); - expect(actual).toEqual(expected); - }); - - it('correctly orders quarto pages with no duplex', () => { - const testDuplex = false; - const expected = { - duplex: false, - duplexrotate: false, - sheets: 4, - per_sheet: 8, - sigconfig: ['N/A'], - pagelistdetails: [ - [4, 1, 7, 6, 12, 9, 15, 14, 20, 17, 23, 22, 28, 25, 31, 30].map(generatePageInfo), - [8, 5, 3, 2, 16, 13, 11, 10, 24, 21, 19, 18, 32, 29, 27, 26].map(generatePageInfo), - ], - }; - const actual = new PerfectBound(testPagesEven, testDuplex, 8, false); - expect(actual).toEqual(expected); - }); -});