Skip to content

Commit

Permalink
feel good about all padding/scaling now
Browse files Browse the repository at this point in the history
  • Loading branch information
sithel committed Jan 23, 2025
1 parent bf7ac72 commit fdbf83b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
7 changes: 7 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,13 @@
margin-bottom: 4px;
margin-left: 50px;
}
#markup_sewing_dist_top_color, #markup_sewing_dist_bottom_color {
display: inline;
width: 30px;
padding: 0px;
margin: 0px 10px;
vertical-align: middle;
}
}
#pdf_preview {
button {
Expand Down
32 changes: 13 additions & 19 deletions js/imposer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ export const imposerMagic = {
}
const is_odd = page_num % 2 == 0 // YES this looks backwards - because page_map is 0 indexed, but the idea of a book is 1 indexed
if (window.book.physical.scaling == 'original') {
this._renderPageOriginal(new_page, embedded_page, corner_x, corner_y, w, h, orientation, is_odd);
this._renderPageOriginal(new_page, embedded_page, corner_x, corner_y, w, h, orientation, is_odd, center_info);
} else if (window.book.physical.scaling == 'fit') {
this._renderPageFit(new_page, embedded_page, corner_x, corner_y, w, h, orientation, is_odd, center_info);
} else if (window.book.physical.scaling == 'fill') {
this._renderPageFill(new_page, embedded_page, corner_x, corner_y, w, h, orientation, is_odd);
this._renderPageFill(new_page, embedded_page, corner_x, corner_y, w, h, orientation, is_odd, center_info);
} else {
throw new Error("Invalid scaling option : ",window.book.physical.scaling);
}
Expand Down Expand Up @@ -101,31 +101,21 @@ export const imposerMagic = {
}
},
_renderPageOriginal: function(new_page, embedded_page, corner_x, corner_y, w, h, orientation, is_odd, center_info) {
const {padding_i, padding_t} = this._calcPadding();
let rotation_deg = 0
switch(orientation) {
case RIGHT_SIDE_UP:
break;
case UP_SIDE_DOWN:
rotation_deg = 180;
break;
case BOTTOM_TO_LEFT:
rotation_deg = -90;
break;
case BOTTOM_TO_RIGHT:
rotation_deg = 90;
break;
}
const [embedded_w, embedded_h] = [embedded_page.width, embedded_page.height]
const finalPlacement = this._calcPlacementOffsets(corner_x, corner_y, w, h, orientation, 1, 1, is_odd, embedded_w, embedded_h)
new_page.drawPage(embedded_page, {
x: finalPlacement.x,
y: finalPlacement.y,
xScale: finalPlacement.xScale,
yScale: finalPlacement.yScale,
opacity: 0.15,
rotate: PDFLib.degrees(rotation_deg)
opacity: 0.75,
rotate: PDFLib.degrees(finalPlacement.rotation_deg)
})
this._maskPage(new_page, embedded_page, corner_x + window.book.physical.short_margin, corner_y + window.book.physical.long_margin, w, h, orientation);
if (center_info.length > 0 && center_info[1])
this._renderSpineMarks(new_page, center_info[0], finalPlacement.spineHead, finalPlacement.spineTail)
if (center_info.length > 0)
this._renderInnerMarks(new_page, finalPlacement.spineHead, finalPlacement.spineTail, orientation, center_info[1])
},
_renderPageFit: function(new_page, embedded_page, corner_x, corner_y, w, h, orientation, is_odd, center_info) {
const {total_w, total_h} = this._calcPadding();
Expand Down Expand Up @@ -167,6 +157,10 @@ export const imposerMagic = {
rotate: PDFLib.degrees(finalPlacement.rotation_deg)
})
this._maskPage(new_page, embedded_page, corner_x + window.book.physical.short_margin, corner_y + window.book.physical.long_margin, w, h, orientation);
if (center_info.length > 0 && center_info[1])
this._renderSpineMarks(new_page, center_info[0], finalPlacement.spineHead, finalPlacement.spineTail)
if (center_info.length > 0)
this._renderInnerMarks(new_page, finalPlacement.spineHead, finalPlacement.spineTail, orientation, center_info[1])
},
/*
* Remember: working from the lower-left corner of the cell
Expand Down

0 comments on commit fdbf83b

Please sign in to comment.