From 9c1bc02fe9635f689c130f2eb4edf29b7c83ab7a Mon Sep 17 00:00:00 2001 From: Cocoa Date: Tue, 12 Mar 2024 17:11:42 -0400 Subject: [PATCH] Fixed folio duplexrotate - but at what cost... --- src/book.js | 8 +++++++- src/utils/layout.js | 17 +++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/book.js b/src/book.js index af666c1..fd2008f 100644 --- a/src/book.js +++ b/src/book.js @@ -94,6 +94,11 @@ export class Book { const pageLayout = PAGE_LAYOUTS[configuration.pageLayout]; this.page_layout = pageLayout; + // Slightly messy hack because folio with duplex rotation is the only layout where different sides have different rotations + this.alt_layout = + configuration.rotatePage && configuration.pageLayout === 'folio' + ? PAGE_LAYOUTS.folio_alt + : null; this.per_sheet = pageLayout.per_sheet; this.pack_pages = configuration.wackySpacing === 'wacky_pack'; this.fore_edge_padding_pt = configuration.foreEdgePaddingPt; @@ -477,7 +482,8 @@ export class Book { // const alt_folio = this.per_sheet == 4 && back; - const positions = calculateLayout(this); + const positions = + this.alt_layout && !back ? calculateLayout(this) : calculateLayout(this, true); let side2flag = back; diff --git a/src/utils/layout.js b/src/utils/layout.js index a040371..98e928d 100644 --- a/src/utils/layout.js +++ b/src/utils/layout.js @@ -4,7 +4,7 @@ * * @return {import("../book.js").Position[]} */ -export function calculateLayout(book) { +export function calculateLayout(book, alt) { const l = calculateDimensions(book); const { layoutCell, @@ -16,8 +16,8 @@ export function calculateLayout(book) { } = l; const [cellWidth, cellHeight] = layoutCell; const positions = []; - - l.layout.rotations.forEach((row, i) => { + const rotations = alt && l.alt_layout ? l.alt_layout.rotations : l.layout.rotations; + rotations.forEach((row, i) => { row.forEach((col, j) => { const xForeEdgeShift = xForeEdgeShiftFunc(); const xBindingShift = xBindingShiftFunc(); @@ -94,7 +94,15 @@ export function calculateLayout(book) { * } */ export function calculateDimensions(book) { - const { cropbox, padding_pt, papersize, page_layout, page_positioning, page_scaling } = book; + const { + cropbox, + padding_pt, + papersize, + page_layout, + alt_layout, + page_positioning, + page_scaling, + } = book; const { width, height } = cropbox; const pageX = width + Math.max(padding_pt.binding, 0) + Math.max(padding_pt.fore_edge, 0); @@ -160,6 +168,7 @@ export function calculateDimensions(book) { }; return { layout: page_layout, + alt_layout: alt_layout, rawPdfSize: [width, height], pdfScale: [sx, sy], pdfSize: [pageX, pageY],