Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Doing some work on the Wacky layouts #60

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,18 @@ <h3>Wacky Small Layouts</h3>
</p>
</details>
</span>
<span class="row"> <input type="radio" id="thin_octavo" name="sig_format" value="thin_octavo">
<label for="thin_octavo">Thin octavo- 8 per side <sub>(4 folio signature)</sub></label>
</span>
<span class="row instruction-indent">
<details>
<summary>Instructions</summary>
<p>
When printing: FLIP ON THE <b>LONG SIDE</b><br>
This layout makes a thin, wide 4-folio signature. Fold the sheet in half (top to bottom). Make two more folds, bringing each bottom up to the top (your first fold). Fold in half-- done.
</p>
</details>
</span>
<span class="row"> <input type="radio" id="A7_2_16s" name="sig_format" value="A7_2_16s">
<label for="A7_2_16s">Petite - 16 per side <sub>(4 folio signature x 2)</sub></label>
</span>
Expand Down
83 changes: 82 additions & 1 deletion preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,9 @@ class Book {
this.book.createsigconfig();
}
this.rearrangedpages = this.book.pagelist;
} else if (this.format == 'a9_3_3_4' || this.format == 'a10_6_10s' || this.format == 'A7_2_16s' || this.format == '1_3rd' || this.format == '8_zine'|| this.format == 'a_3_6s' || this.format == 'a_4_8s') {
} else if (this.format == 'a9_3_3_4' || this.format == 'a10_6_10s' || this.format == 'A7_2_16s'
|| this.format == '1_3rd' || this.format == '8_zine'|| this.format == 'a_3_6s'
|| this.format == 'a_4_8s' || this.format == 'thin_octavo') {
this.book = new _wacky_imposition_js__WEBPACK_IMPORTED_MODULE_5__.WackyImposition(this.orderedpages, this.duplex, this.format, this.pack_pages)
}
// dracula
Expand Down Expand Up @@ -356,6 +358,8 @@ class Book {
resultPDF = await this.buildSheets(this.filename, this.book.page_1_3rd_builder());
} else if (this.format == '8_zine') {
resultPDF = await this.buildSheets(this.filename, this.book.page_8_zine_builder());
} else if (this.format == 'thin_octavo') {
resultPDF = await this.buildSheets(this.filename, this.book.page_thin_octavo_builder());
}
console.log("Attempting to generate preview for ",resultPDF);

Expand Down Expand Up @@ -31055,9 +31059,21 @@ class WackyImposition{
} else if (format == "8_zine") {
this.sheets = 1;
this.sigconfig = [1];
} else if (format == "thin_octavo") {
this.sheets = 1;
this.sigconfig = [1];
}
}

page_thin_octavo_builder() {
return {
sheetMaker: this.build_thin_octavo_sheetList.bind(this),
lineMaker: this.build_thin_octavo_lineFunction.bind(this),
isLandscape: false,
fileNameMod: "thin_octavo" + ((this.isPacked) ? "_packed" : "_spread")
}
}

page_8_zine_builder() {
return {
sheetMaker: this.build_8_zine_sheetList.bind(this),
Expand Down Expand Up @@ -31124,6 +31140,68 @@ class WackyImposition{

// ---------------- the real guts of the layout

/**
* It's an octavo with a different folding pattern than the main. (4 folio stacked atop each other)
* Added on request by a user
*
* @param pageCount - total pages in document
* @return an array of sheets. Assumes 1st is "front", 2nd is "back", 3rd is "front", etc.
* Each sheet is an array of rows, containing a list of page objects
*/
build_thin_octavo_sheetList(pageCount) {
let p = this.page;
let f = this.flipPage;
let sheets = [];
let sheetCount = Math.ceil(pageCount / 16.0);
console.log("Building the thin_octavo layout. Given ",pageCount," page count, there will be ",sheetCount," sheets...");
for (let sheet=0; sheet < sheetCount; ++sheet ) {
let i = sheet * 16 - 1;
let front = [
this.auditForBlanks([p(i+16), p(i+1)], pageCount),
this.auditForBlanks([f(i+13), f(i+4)], pageCount),
this.auditForBlanks([p(i+12), p(i+5)], pageCount),
this.auditForBlanks([f(i+9), f(i+8)], pageCount),
];
let back = [
this.auditForBlanks([p(i+2), p(i+15)], pageCount),
this.auditForBlanks([f(i+3), f(i+14)], pageCount),
this.auditForBlanks([p(i+6), p(i+11)], pageCount),
this.auditForBlanks([f(i+7), f(i+10)], pageCount),
]
sheets.push(front);
sheets.push(back);
}
return sheets;
}

/**
* @return a FUNCTION. The function takes as it's parameter:
* Object definition: {
* gap: [leftGap, topGap],
* renderPageSize: [width, height],
* paperSize: [width, height],
* isFront: boolean,
* isPacked: boolean
* }
* and returns: a list of lines, as described by PDF-lib.js's `PDFPageDrawLineOptions` object
*/
build_thin_octavo_lineFunction() {
return info => {
let vGap = row => { return (info.isPacked) ? info.gap[1] : info.gap[1] * (2 * row); };
let hGap = col => { return (info.isPacked) ? info.gap[0] : col * info.gap[0]};
let foldMarks = [];
[0,1,2,3,4].forEach( row => {
[0,1,2].forEach( page => {
foldMarks = foldMarks.concat(this.crosshairMark(
hGap(page) + info.renderPageSize[0] * page,
vGap(row) + info.renderPageSize[1] * row,
5
));
});
});
return foldMarks;
};
}

/**
* It's an 8 page zine. Same page count every time....
Expand Down Expand Up @@ -31381,6 +31459,7 @@ class WackyImposition{
return this.build_strips_sheetList(6, 5, pageCount, frontFunc, backFunc);
}


/**
* @param rows - number of rows for page
* @param folioPerRow - number of folios per row (not pages!)
Expand Down Expand Up @@ -31797,6 +31876,8 @@ function renderWacky() {
document.getElementById('a_3_6s').checked ||
document.getElementById('a_4_8s').checked ||
document.getElementById('A7_2_16s').checked ||
document.getElementById('thin_octavo').checked ||
document.getElementById('8_zine').checked ||
document.getElementById('1_3rd').checked;
console.log('Is a wacky layout? ', isWacky);
document
Expand Down
6 changes: 5 additions & 1 deletion src/book.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,9 @@ export class Book {
this.book.createsigconfig();
}
this.rearrangedpages = this.book.pagelist;
} else if (this.format == 'a9_3_3_4' || this.format == 'a10_6_10s' || this.format == 'A7_2_16s' || this.format == '1_3rd' || this.format == '8_zine'|| this.format == 'a_3_6s' || this.format == 'a_4_8s') {
} else if (this.format == 'a9_3_3_4' || this.format == 'a10_6_10s' || this.format == 'A7_2_16s'
|| this.format == '1_3rd' || this.format == '8_zine'|| this.format == 'a_3_6s'
|| this.format == 'a_4_8s' || this.format == 'thin_octavo') {
this.book = new WackyImposition(this.orderedpages, this.duplex, this.format, this.pack_pages)
}
// dracula
Expand Down Expand Up @@ -334,6 +336,8 @@ export class Book {
resultPDF = await this.buildSheets(this.filename, this.book.page_1_3rd_builder());
} else if (this.format == '8_zine') {
resultPDF = await this.buildSheets(this.filename, this.book.page_8_zine_builder());
} else if (this.format == 'thin_octavo') {
resultPDF = await this.buildSheets(this.filename, this.book.page_thin_octavo_builder());
}
console.log("Attempting to generate preview for ",resultPDF);

Expand Down
2 changes: 2 additions & 0 deletions src/utils/renderUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ export function renderWacky() {
document.getElementById('a_3_6s').checked ||
document.getElementById('a_4_8s').checked ||
document.getElementById('A7_2_16s').checked ||
document.getElementById('thin_octavo').checked ||
document.getElementById('8_zine').checked ||
document.getElementById('1_3rd').checked;
console.log('Is a wacky layout? ', isWacky);
document
Expand Down
75 changes: 75 additions & 0 deletions src/wacky_imposition.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,21 @@ export class WackyImposition{
} else if (format == "8_zine") {
this.sheets = 1;
this.sigconfig = [1];
} else if (format == "thin_octavo") {
this.sheets = 1;
this.sigconfig = [1];
}
}

page_thin_octavo_builder() {
return {
sheetMaker: this.build_thin_octavo_sheetList.bind(this),
lineMaker: this.build_thin_octavo_lineFunction.bind(this),
isLandscape: false,
fileNameMod: "thin_octavo" + ((this.isPacked) ? "_packed" : "_spread")
}
}

page_8_zine_builder() {
return {
sheetMaker: this.build_8_zine_sheetList.bind(this),
Expand Down Expand Up @@ -100,6 +112,68 @@ export class WackyImposition{

// ---------------- the real guts of the layout

/**
* It's an octavo with a different folding pattern than the main. (4 folio stacked atop each other)
* Added on request by a user
*
* @param pageCount - total pages in document
* @return an array of sheets. Assumes 1st is "front", 2nd is "back", 3rd is "front", etc.
* Each sheet is an array of rows, containing a list of page objects
*/
build_thin_octavo_sheetList(pageCount) {
let p = this.page;
let f = this.flipPage;
let sheets = [];
let sheetCount = Math.ceil(pageCount / 16.0);
console.log("Building the thin_octavo layout. Given ",pageCount," page count, there will be ",sheetCount," sheets...");
for (let sheet=0; sheet < sheetCount; ++sheet ) {
let i = sheet * 16 - 1;
let front = [
this.auditForBlanks([p(i+16), p(i+1)], pageCount),
this.auditForBlanks([f(i+13), f(i+4)], pageCount),
this.auditForBlanks([p(i+12), p(i+5)], pageCount),
this.auditForBlanks([f(i+9), f(i+8)], pageCount),
];
let back = [
this.auditForBlanks([p(i+2), p(i+15)], pageCount),
this.auditForBlanks([f(i+3), f(i+14)], pageCount),
this.auditForBlanks([p(i+6), p(i+11)], pageCount),
this.auditForBlanks([f(i+7), f(i+10)], pageCount),
]
sheets.push(front);
sheets.push(back);
}
return sheets;
}

/**
* @return a FUNCTION. The function takes as it's parameter:
* Object definition: {
* gap: [leftGap, topGap],
* renderPageSize: [width, height],
* paperSize: [width, height],
* isFront: boolean,
* isPacked: boolean
* }
* and returns: a list of lines, as described by PDF-lib.js's `PDFPageDrawLineOptions` object
*/
build_thin_octavo_lineFunction() {
return info => {
let vGap = row => { return (info.isPacked) ? info.gap[1] : info.gap[1] * (2 * row); };
let hGap = col => { return (info.isPacked) ? info.gap[0] : col * info.gap[0]};
let foldMarks = [];
[0,1,2,3,4].forEach( row => {
[0,1,2].forEach( page => {
foldMarks = foldMarks.concat(this.crosshairMark(
hGap(page) + info.renderPageSize[0] * page,
vGap(row) + info.renderPageSize[1] * row,
5
));
});
});
return foldMarks;
};
}

/**
* It's an 8 page zine. Same page count every time....
Expand Down Expand Up @@ -357,6 +431,7 @@ export class WackyImposition{
return this.build_strips_sheetList(6, 5, pageCount, frontFunc, backFunc);
}


/**
* @param rows - number of rows for page
* @param folioPerRow - number of folios per row (not pages!)
Expand Down