Skip to content

Commit

Permalink
Fixed folio duplexrotate - but at what cost...
Browse files Browse the repository at this point in the history
  • Loading branch information
Cocoa committed Mar 12, 2024
1 parent 261a32f commit 9c1bc02
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
8 changes: 7 additions & 1 deletion src/book.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down
17 changes: 13 additions & 4 deletions src/utils/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* @return {import("../book.js").Position[]}
*/
export function calculateLayout(book) {
export function calculateLayout(book, alt) {
const l = calculateDimensions(book);
const {
layoutCell,
Expand All @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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],
Expand Down

0 comments on commit 9c1bc02

Please sign in to comment.