Skip to content

Commit

Permalink
cleaning up things...
Browse files Browse the repository at this point in the history
  • Loading branch information
sithel committed Apr 12, 2024
1 parent 179e12c commit e1641cd
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
27 changes: 13 additions & 14 deletions src/book.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ export class Book {
* generate preview content AND a downloadable zip
*/
async createoutputfiles(isPreview) {
// set this to `true` to enable full-book previews (placeholder till it's in the UI)
const fullPreviewDevHack = true
const previewFrame = document.getElementById('pdf');
let previewPdf = null;

Expand All @@ -310,13 +312,13 @@ export class Book {
this.format == 'customsig'
) {
// Only generate the first signature for preview
const pagesArr = this.rearrangedpages;
const pagesArr = (isPreview && !fullPreviewDevHack) ? this.rearrangedpages.slice(0, 1) : this.rearrangedpages;
const signatures = [{}];
const makeSignatures = async () => {
const tasks = pagesArr.map(async (pages, i) => {
console.log(pages);
signatures[i] = { name: `${this.filename}_signature${i}` };
[signatures[i].front, signatures[i].back] = await this.createSignatures({
[signatures[i].front, signatures[i].back] = await this.createSignature({
pageIndexDetails: pages,
maxSigCount: pagesArr.length
});
Expand All @@ -335,11 +337,10 @@ export class Book {
await Promise.all(tasks);
};
await duplexSignatures();
console.log("Shark")
// previewPdf = signatures[0].duplex;
previewPdf = signatures[0].duplex;
}

if (this.print_file != 'aggregated' && !isPreview) {
if (this.print_file != 'aggregated' && (!isPreview || fullPreviewDevHack)) {
const saveSignatures = async () => {
const tasks = signatures.map(async (sig) => {
await sig.front?.save().then((pdfBytes) => {
Expand All @@ -357,7 +358,7 @@ export class Book {
await saveSignatures();
}

if (this.print_file != 'signatures') {
if (this.print_file != 'signatures' && (!isPreview || fullPreviewDevHack)) {
const saveAggregate = async () => {
const aggregate = {
front: !this.duplex ? await PDFDocument.create() : null,
Expand Down Expand Up @@ -403,11 +404,10 @@ export class Book {
this.zip.file(`${this.filename}_typeset.pdf`, pdfBytes);
});
}
console.log("Do I have this? ",aggregate.duplex.getPageCount())
previewPdf = aggregate.duplex
return aggregate
};
var results = await saveAggregate();

await saveAggregate();
}

var rotationMetaInfo =
Expand Down Expand Up @@ -453,7 +453,7 @@ export class Book {
}

/**
* Part of the Classic (non-Wacky) flow. Called by [createsignatures].
* Part of the Classic (non-Wacky) flow. Called by [createsignature].
* (conditionally) populates the destPdf and (conditionally) generates the outname PDF
*
* @param {Object} config - object /w the following parameters:
Expand All @@ -464,7 +464,6 @@ export class Book {
* @return reference to the new PDF created
*/
async writepages(config) {
console.log("Write pages ", config)
const pagelist = config.pageList;
const back = config.back;
const maxSigCount = config.maxSigCount;
Expand Down Expand Up @@ -549,7 +548,6 @@ export class Book {
const alt = config.alt;
const maxSigCount = config.maxSigCount
let side2flag = config.side2flag;
console.log("burp I see ",maxSigCount)

const block = config.embeddedPages.slice(block_start, block_end);
const currPage = outPDF.addPage(papersize);
Expand Down Expand Up @@ -606,13 +604,14 @@ export class Book {

/**
* PDF builder base function for Classic (non-Wacky) layouts. Called by [createoutputfiles]
* Generates a single signature (or is it just a single sheet? -- comments left long after coding)
* TODO : re-examine this logic and clean up this comment. What is going on??
*
* @param {Object} config
* @param {number} config.maxSigCount
* @param {PageInfo[][]} config.pageIndexDetails : a nested list of objects.
*/
async createSignatures(config) {
console.log("createSignatures ",config)
async createSignature(config) {
const pages = config.pageIndexDetails;
const tasks = [
this.writepages({
Expand Down
1 change: 1 addition & 0 deletions src/book.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ describe('Book model', () => {
source_rotation: 'none',
print_file: 'both',
signatureconfig: [],
sigOrderMarks: false,
};

it('returns a new Book', () => {
Expand Down
5 changes: 1 addition & 4 deletions src/signatures.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,13 @@ export class Signatures {
let front_end = center;
let back_start = center;
let back_end = center + pageblock;
console.log("outside")

while (front_start >= 0 && back_end <= pages.length) {
const front_block = pages.slice(front_start, front_end);
const back_block = pages.slice(back_start, back_end);

const block = [...front_block, ...back_block];

console.log(" ~~~~ SIG NUM "+sig_num+" on "+front_start+" --> "+back_end)
front_config.forEach((pnum) => {
const page = block[pnum - 1]; //page layouts are 1-indexed, not 0-index
pagelistdetails[0].push({
Expand All @@ -172,9 +171,7 @@ export class Signatures {
});

// Update all our counters
console.log("stepa "+front_start)
front_start -= pageblock;
console.log("stepb "+front_start)
front_end -= pageblock;
back_start += pageblock;
back_end += pageblock;
Expand Down
2 changes: 2 additions & 0 deletions src/utils/drawing.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ export function drawSpineMark(draw_top_mark, position, w) {


/**
* TODO : these params should probably be pushed into a config... maybe next time/next pass
*
* @param {import("../book.js").PageInfo} sigDetails - page info object
* @param {import("../book.js").Position} position - position info object
* @param {number} maxSigCount - number of total signatures
Expand Down

0 comments on commit e1641cd

Please sign in to comment.