Skip to content

Commit

Permalink
Refactor draw_spine_marks
Browse files Browse the repository at this point in the history
  • Loading branch information
acestronautical committed Feb 13, 2024
1 parent fee1159 commit aa7ed86
Showing 1 changed file with 27 additions and 43 deletions.
70 changes: 27 additions & 43 deletions src/book.js
Original file line number Diff line number Diff line change
Expand Up @@ -561,52 +561,36 @@ export class Book {
*/
draw_spine_marks(curPage, sigDetails, position) {
const w = 5;
if (position.rotation == 0) {
const start = {
x: sigDetails.isSigStart
? position.spineMarkTop[0] - w / 2
: position.spineMarkBottom[0] - w / 2,
y: sigDetails.isSigStart ? position.spineMarkTop[1] : position.spineMarkBottom[1],
};
let startX, startY, endX, endY;
if (sigDetails.isSigStart) {
[startX, startY] = position.spineMarkTop;
[endX, endY] = position.spineMarkTop;
} else {
[startX, startY] = position.spineMarkBottom;
[endX, endY] = position.spineMarkBottom;
}

const end = {
x: sigDetails.isSigStart
? position.spineMarkTop[0] + w / 2
: position.spineMarkBottom[0] + w / 2,
y: sigDetails.isSigStart ? position.spineMarkTop[1] : position.spineMarkBottom[1],
};
const drawOpts = {
start,
end,
thickness: 0.5,
color: rgb(0, 0, 0),
opacity: 1,
};
console.log(' --> draw this: ', drawOpts);
curPage.drawLine(drawOpts);
if (position.rotation == 0) {
startX -= w / 2;
endX += w / 2;
} else if (sigDetails.isSigStart) {
startY -= w;
endY += w;
} else {
curPage.drawLine({
start: {
x: sigDetails.isSigStart ? position.spineMarkTop[0] : position.spineMarkBottom[0],
y:
(sigDetails.isSigStart
? position.spineMarkTop[1] - w / 2
: position.spineMarkBottom[1]) -
w / 2,
},
end: {
x: sigDetails.isSigStart ? position.spineMarkTop[0] : position.spineMarkBottom[0],
y:
(sigDetails.isSigStart
? position.spineMarkTop[1] + w / 2
: position.spineMarkBottom[1]) +
w / 2,
},
thickness: 0.25,
color: rgb(0, 0, 0),
opacity: 1,
});
startY -= w / 2;
endY += w / 2;
}

const drawLineArgs = {
start: { x: startX, y: startY },
end: { x: endX, y: endY },
thickness: position.rotation == 0 ? 0.5 : 0.25,
color: rgb(0, 0, 0),
opacity: 1,
};

console.log(' --> draw this: ', drawLineArgs);
curPage.drawLine(drawLineArgs);
}

draw_cropmarks(currPage, side2flag) {
Expand Down

0 comments on commit aa7ed86

Please sign in to comment.