Skip to content

Commit

Permalink
Remove alternating page logic we're not using any more
Browse files Browse the repository at this point in the history
  • Loading branch information
Cocoa committed Mar 13, 2024
1 parent 3cb4192 commit 4b278f4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 26 deletions.
26 changes: 6 additions & 20 deletions src/book.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class Book {
this.duplex = configuration.printerType === 'duplex';
this.duplexrotate = configuration.rotatePage;
this.paper_rotation_90 = configuration.paperRotation90;
/** @type {number[]} */
/** @type {[number, number]} */
this.papersize = PAGE_SIZES[configuration.paperSize];
if (configuration.paperRotation90) {
this.papersize = [this.papersize[1], this.papersize[0]];
Expand Down Expand Up @@ -457,7 +457,6 @@ export class Book {
* @param {Object} config - object /w the following parameters:
* @param {PageInfo[]} config.pageList : objects that contain 3 values: { isSigStart: boolean, isSigEnd: boolean, info: either the page number or 'b'}
* @param {boolean} config.back : is 'back' of page (boolean)
* @param {boolean} config.alt : alternate pages (boolean)
* @return reference to the new PDF created
*/
async writepages(config) {
Expand Down Expand Up @@ -485,11 +484,9 @@ export class Book {
const positions =
this.alt_layout && !back ? calculateLayout(this) : calculateLayout(this, true);

let side2flag = back;

while (block_end <= pagelist.length) {
const sigDetails = config.pageList.slice(block_start, block_end);
side2flag = this.draw_block_onto_page({
this.draw_block_onto_page({
outPDF: outPDF,
embeddedPages: embeddedPages,
block_start: block_start,
Expand All @@ -500,8 +497,7 @@ export class Book {
cropmarks: this.cropmarks,
pdfEdgeMarks: this.pdfEdgeMarks,
cutmarks: this.cutmarks,
alt: config.alt,
side2flag: side2flag,
back: back,
});
block_start += offset;
block_end += offset;
Expand All @@ -512,13 +508,11 @@ export class Book {
/**
*
* @param {Object} config - object /w the following parameters:
* @param {string|null} config.outname : name of pdf added to ongoing zip file. Ex: 'signature1duplex.pdf' (or null if no signature file needed)
* @param {PageInfo[]} config.sigDetails : objects that contain 3 values: { isSigStart: boolean, isSigEnd: boolean, info: either the page number or 'b'}
* @param {boolean} config.side2flag : is 'back' of page (boolean)
* @param {boolean} config.back : is 'back' of page (boolean)
* @param {[number, number]} config.papersize : paper size (as [number, number])
* @param {number} config.block_start: Starting page index
* @param {number} config.block_end: Ending page index
* @param {boolean} config.alt : alternate pages (boolean)
* @param {boolean} config.cutmarks: whether to print cutmarks
* @param {boolean} config.cropmarks: whether to print cropmarks
* @param {boolean} config.pdfEdgeMarks: whether to print PDF edge marks
Expand All @@ -537,14 +531,13 @@ export class Book {
const foldmarks = config.cropmarks;
const pdfEdgeMarks = config.pdfEdgeMarks;
const cutmarks = config.cutmarks;
const alt = config.alt;
let side2flag = config.side2flag;
const back = config.back;

const block = config.embeddedPages.slice(block_start, block_end);
const currPage = outPDF.addPage(papersize);
const cropLines = cutmarks ? drawCropmarks(papersize, this.per_sheet) : [];
const foldLines = foldmarks
? drawFoldlines(side2flag, this.duplexrotate, papersize, this.per_sheet)
? drawFoldlines(back, this.duplexrotate, papersize, this.per_sheet)
: [];
const drawLines = [...cropLines, ...foldLines];

Expand Down Expand Up @@ -572,11 +565,6 @@ export class Book {
drawLines.forEach((line) => {
currPage.drawLine(line);
});

if (alt) {
side2flag = !side2flag;
}
return side2flag;
}

/**
Expand All @@ -591,12 +579,10 @@ export class Book {
this.writepages({
pageList: pages[0],
back: false,
alt: false,
}),
this.writepages({
pageList: pages[1],
back: true,
alt: false,
}),
];
const [pdfFront, pdfBack] = await Promise.all(tasks);
Expand Down
12 changes: 6 additions & 6 deletions src/utils/drawing.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ import { rgb } from '@cantoo/pdf-lib';
*/

/**
* @param {boolean} side2flag - whether we're on the back or not.
* @param {boolean} back - whether we're on the back or not.
* @param {boolean} duplexrotate - if alternate sides are rotated or not
* @param {number[]} papersize - paper dimensions
* @param {number} per_sheet - pages per sheet of paper
* @returns {Line[]}
*/
export function drawFoldlines(side2flag, duplexrotate, papersize, per_sheet) {
export function drawFoldlines(back, duplexrotate, papersize, per_sheet) {
const lineSettings = {
opacity: 0.4,
dashArray: [1, 5],
Expand All @@ -36,7 +36,7 @@ export function drawFoldlines(side2flag, duplexrotate, papersize, per_sheet) {

switch (per_sheet) {
case 32:
if (side2flag) {
if (back) {
lineSettings.dashArray = [1, 5];

x = duplexrotate ? width * 0.75 : width * 0.25;
Expand All @@ -47,7 +47,7 @@ export function drawFoldlines(side2flag, duplexrotate, papersize, per_sheet) {
}
/* falls through */
case 16:
if (side2flag) {
if (back) {
lineSettings.dashArray = [3, 5];

y = duplexrotate ? height * 0.75 : height * 0.25;
Expand All @@ -58,7 +58,7 @@ export function drawFoldlines(side2flag, duplexrotate, papersize, per_sheet) {
}
/* falls through */
case 8:
if (side2flag) {
if (back) {
lineSettings.dashArray = [5, 5];

x = width * 0.5;
Expand All @@ -69,7 +69,7 @@ export function drawFoldlines(side2flag, duplexrotate, papersize, per_sheet) {
}
/* falls through */
case 4:
if (!side2flag) {
if (!back) {
lineSettings.dashArray = [10, 5];
lines.push({ ...drawHLine(height * 0.5, 0, width), ...lineSettings });
}
Expand Down

0 comments on commit 4b278f4

Please sign in to comment.