Skip to content

Commit

Permalink
WIP: replace perfectbound logic with sigsize = 1
Browse files Browse the repository at this point in the history
It seems like we might be able to remove all the perfect bound logic,
and instead treat perfectbound as signature size of 1.

This would simply the codebase if true.
  • Loading branch information
acestronautical committed Feb 5, 2024
1 parent 7138d31 commit d8868c1
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 193 deletions.
15 changes: 8 additions & 7 deletions src/book.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import { PDFDocument, degrees, grayscale, 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';
Expand Down Expand Up @@ -193,13 +192,15 @@ 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);
/* falls through */
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);
}
/* falls through */
case 'standardsig':
case 'customsig':
this.book = new Signatures(this.orderedpages, this.duplex, this.sigsize, this.per_sheet, this.duplexrotate);
Expand Down
30 changes: 0 additions & 30 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,33 +147,3 @@ export const BOOKLET_LAYOUTS = {
rotate: [28, 5, 4, 29, 21, 12, 13, 20, 24, 9, 16, 17, 25, 8, 1, 32],
},
};

export const PERFECTBOUND_LAYOUTS = {
/*
For page layouts: pages are 1-indexed for sanity reasons, and the order for the back list must be reversed
'front' will be the side that ends up with consecutive pagenumbers on the innermost fold, by convention.
page numbers should be listed from left to right, top to bottom, starting in the top left.
*/
4: {
front: [3, 2],
back: [1, 4],
rotate: [4, 1],
},
8: {
front: [4, 1, 7, 6],
back: [8, 5, 3, 2],
rotate: [2, 3, 5, 8],
},
16: {
front: [5, 10, 8, 11, 3, 16, 2, 13],
back: [1, 14, 4, 15, 7, 12, 6, 9],
rotate: [9, 6, 12, 7, 15, 4, 14, 1],
},
32: {
front: [8, 5, 10, 11, 27, 26, 21, 24, 32, 29, 18, 19, 3, 2, 13, 16],
back: [4, 1, 14, 15, 31, 30, 17, 20, 28, 25, 22, 23, 7, 6, 9, 12],
rotate: [12, 9, 6, 7, 23, 22, 25, 28, 20, 17, 30, 31, 15, 14, 1, 4],
},
};
27 changes: 2 additions & 25 deletions src/constants.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,11 @@

import { expect, describe, it } from 'vitest';

import { PERFECTBOUND_LAYOUTS, BOOKLET_LAYOUTS, PAGE_LAYOUTS } from './constants';
import { BOOKLET_LAYOUTS, PAGE_LAYOUTS } from './constants';

function numSort(a, b) {
return a - b;
}


describe('Tests of the perfectbound layout constants', () => {
Object.keys(PERFECTBOUND_LAYOUTS).forEach( (key) => {
const {front, back, rotate} = PERFECTBOUND_LAYOUTS[key];
it(`has the same pages on the back regardless of rotation for ${key}-per-sheet layouts`, () => {
const back_sorted = back.sort(numSort);
const back_rotated = rotate.sort(numSort);
expect(back_sorted).toEqual(back_rotated);

});

it(`accounts for all pages in ${key}-per-sheet layouts`, () => {
let both = front.concat(back);
both.sort(numSort);
const expected = Array.from({length: key}, (x, i) => i + 1);
expect(both).toEqual(expected);

});
});

});


describe('Tests of the booklet layout constants', () => {
Object.keys(BOOKLET_LAYOUTS).forEach( (key) => {
Expand Down Expand Up @@ -80,4 +57,4 @@ describe('Tests of the page layout constants', () => {
});
});

});
});
62 changes: 0 additions & 62 deletions src/perfectbound.js

This file was deleted.

69 changes: 0 additions & 69 deletions src/perfectbound.test.js

This file was deleted.

0 comments on commit d8868c1

Please sign in to comment.