Skip to content

Commit

Permalink
Fix prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
MikDal002 committed Apr 19, 2024
1 parent d47c054 commit b42652c
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 63 deletions.
38 changes: 23 additions & 15 deletions src/book.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class Book {
isEnabled: configuration.sewingMarksEnabled,
amount: configuration.sewingMarksAmount,
marginPt: configuration.sewingMarksMarginPt,
tapeWidthPt: configuration.sewingMarksTapeWidthPt
tapeWidthPt: configuration.sewingMarksTapeWidthPt,
};
this.pdfEdgeMarks = configuration.pdfEdgeMarks;
this.cutmarks = configuration.cutMarks;
Expand Down Expand Up @@ -511,7 +511,7 @@ export class Book {
cutmarks: this.cutmarks,
alt: config.alt,
side2flag: side2flag,
sewingMarks: this.sewingMarks
sewingMarks: this.sewingMarks,
});
block_start += offset;
block_end += offset;
Expand Down Expand Up @@ -558,13 +558,13 @@ export class Book {
const foldLines = foldmarks
? drawFoldlines(side2flag, this.duplexrotate, papersize, this.per_sheet)
: [];
const drawLines = [...cropLines, ...foldLines];
const drawPoints = [ ];
block.forEach((page, i) => {
if (page == 'b' || page === undefined) {
// blank page, move on.
} else if (page instanceof PDFEmbeddedPage) {
const drawLines = [...cropLines, ...foldLines];
const drawPoints = [];

block.forEach((page, i) => {
if (page == 'b' || page === undefined) {
// blank page, move on.
} else if (page instanceof PDFEmbeddedPage) {
const { y, x, sx, sy, rotation } = positions[i];
currPage.drawPage(page, {
y,
Expand All @@ -576,22 +576,30 @@ export class Book {
} else {
console.error('Unexpected type for page: ', page);
}

if (pdfEdgeMarks && (sigDetails[i].isSigStart || sigDetails[i].isSigEnd)) {
drawLines.push(drawSpineMarks(sigDetails[i], positions[i]));
}
const sewingMarkPoints = sewingMarks.isEnabled ? drawSewingMarks(sigDetails[i], positions[i], papersize, sewingMarks.amount, sewingMarks.marginPt, sewingMarks.tapeWidthPt) : [];
const sewingMarkPoints = sewingMarks.isEnabled
? drawSewingMarks(
sigDetails[i],
positions[i],
papersize,
sewingMarks.amount,
sewingMarks.marginPt,
sewingMarks.tapeWidthPt
)
: [];
drawPoints.push(...sewingMarkPoints);
});

drawLines.forEach((line) => {
currPage.drawLine(line);
});

console.log("drawpoints", drawPoints)

drawPoints.forEach((point) => {
currPage.drawCircle(point);
})
});

if (alt) {
side2flag = !side2flag;
Expand Down
50 changes: 25 additions & 25 deletions src/html/page_layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,40 +82,40 @@ <h2>Page Layout</h2>
</span>

<span class="row">
<label>Add marks for sewing</label>
<input
type="checkbox"
id="add_sewing_marks_checkbox"
name="add_sewing_marks_checkbox"
/>
<label>Add marks for sewing</label>
<input type="checkbox" id="add_sewing_marks_checkbox" name="add_sewing_marks_checkbox" />
<details>
<summary>Detailed settings for sewing</summary>
Look at the image below.
<span class="row">
<label>(A) Margin (distance where first point should be draw):</label>
<label>(A) Margin (distance where first point should be draw):</label>
<input
type="number"
id="sewing_marks_margin_pt"
name="sewing_marks_margin_pt"
class="layout_margin_user_input_field"
/><sub>pt</sub><br />
type="number"
id="sewing_marks_margin_pt"
name="sewing_marks_margin_pt"
class="layout_margin_user_input_field"
/><sub>pt</sub><br />

<label>(B) Amount of sewing points:</label>
<label>(B) Amount of sewing points:</label>
<input
type="number"
id="sewing_marks_amount"
name="sewing_marks_amount"
class="layout_margin_user_input_field"
/><br />
type="number"
id="sewing_marks_amount"
name="sewing_marks_amount"
class="layout_margin_user_input_field"
/><br />

<label>(C) Tape width:</label>
<label>(C) Tape width:</label>
<input
type="number"
id="sewing_marks_tape_width_pt"
name="sewing_marks_tape_width_pt"
class="layout_margin_user_input_field"
/><sub>pt</sub><br />
<img alt="sewing image" src="/img/sewing_settings_explanation.png" style="height: 100%; width: 100%; object-fit: contain" />
type="number"
id="sewing_marks_tape_width_pt"
name="sewing_marks_tape_width_pt"
class="layout_margin_user_input_field"
/><sub>pt</sub><br />
<img
alt="sewing image"
src="/img/sewing_settings_explanation.png"
style="height: 100%; width: 100%; object-fit: contain"
/>
</span>
</details>
</span>
Expand Down
37 changes: 14 additions & 23 deletions src/utils/drawing.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { rgb, grayscale } from '@cantoo/pdf-lib';
* @property {number} y,
* @property {number} size,
* @property {Grayscale|RGB|CMYK} color,
*
*
*/

/**
Expand Down Expand Up @@ -131,10 +131,6 @@ export function drawCropmarks(papersize, per_sheet) {
* @returns {Point[]}
*/
export function drawSewingMarks(sigDetails, position, papersize, amount, marginPt, tapeWidthPt) {
console.log("sigDetails", sigDetails);
console.log("position", position);
console.log("papersize", papersize)

// Here normalize coordinates to always think in x an y like this
// | P |H| P |
// | A |E| A |
Expand All @@ -149,20 +145,19 @@ export function drawSewingMarks(sigDetails, position, papersize, amount, marginP

if (arePageRotated) {
spineHeight = Math.abs(position.spineMarkTop[0] - position.spineMarkBottom[0]);
spinePosition = position.spineMarkTop[1]
}
else {
spinePosition = position.spineMarkTop[1];
} else {
spineHeight = Math.abs(position.spineMarkTop[1] - position.spineMarkBottom[1]);
spinePosition = position.spineMarkTop[0]
spinePosition = position.spineMarkTop[0];
}

console.log("spine properties", {
console.log('spine properties', {
spineLength: spineHeight,
reverseCoords: arePageRotated,
height: spinePosition
})
height: spinePosition,
});

const commonCircleValues = { /*y*/ spinePosition, size: 1, color: grayscale(0.0) }
const commonCircleValues = { /*y*/ spinePosition, size: 1, color: grayscale(0.0) };

const workingWidth = spineHeight - 2 * marginPt;
const spaceBetweenPoints = workingWidth / (amount + 1);
Expand All @@ -171,27 +166,23 @@ export function drawSewingMarks(sigDetails, position, papersize, amount, marginP
for (let index = 1; index <= amount; index++) {
const halfOfTape = tapeWidthPt / 2;
sewingPoints.push(

{ pointHeight: marginPt + spaceBetweenPoints * index + halfOfTape, ...commonCircleValues },
{ pointHeight: marginPt + spaceBetweenPoints * index - halfOfTape, ...commonCircleValues }
)

);
}

const allPoints = [
{ pointHeight: marginPt, ...commonCircleValues },
{ pointHeight: spineHeight - marginPt, ...commonCircleValues },
...sewingPoints
...sewingPoints,
];


allPoints.forEach(point => {
allPoints.forEach((point) => {
if (arePageRotated) {
point.y = point.spinePosition;
point.x = point.pointHeight
}
else {
point.y = point.pointHeight
point.x = point.pointHeight;
} else {
point.y = point.pointHeight;
point.x = point.spinePosition;
}
});
Expand Down

0 comments on commit b42652c

Please sign in to comment.