mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
PDF Output: When an inline image is placed alone inside a block tag, ensure that it is not split over two pages.
This commit is contained in:
parent
89b0adfb43
commit
dcbed07c95
@ -11,19 +11,25 @@
|
|||||||
// wrap up long words that dont fit in the page
|
// wrap up long words that dont fit in the page
|
||||||
document.body.style.overflowWrap = 'break-word';
|
document.body.style.overflowWrap = 'break-word';
|
||||||
|
|
||||||
var block_styles = {
|
var break_avoid_block_styles = {
|
||||||
"run-in":1, "block":1, "table-row-group":1, "table-column":1, "table-column-group":1,
|
"run-in":1, "block":1, "table-row-group":1, "table-column":1, "table-column-group":1,
|
||||||
"table-header-group":1, "table-footer-group":1, "table-row":1, "table-cell":1,
|
"table-header-group":1, "table-footer-group":1, "table-row":1, "table-cell":1,
|
||||||
"table-caption":1, "inline-block:":1
|
"table-caption":1, // page-break-avoid does not work for inline-block either
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function avoid_page_breaks_inside(node) {
|
||||||
|
node.style.pageBreakInside = 'avoid';
|
||||||
|
node.style.breakInside = 'avoid';
|
||||||
|
}
|
||||||
|
|
||||||
for (const img of document.images) {
|
for (const img of document.images) {
|
||||||
var style = window.getComputedStyle(img);
|
var style = window.getComputedStyle(img);
|
||||||
if (style.maxHeight === 'none') img.style.maxHeight = '100vh';
|
if (style.maxHeight === 'none') img.style.maxHeight = '100vh';
|
||||||
if (style.maxWidth === 'none') img.style.maxWidth = '100vw';
|
if (style.maxWidth === 'none') img.style.maxWidth = '100vw';
|
||||||
if (block_styles[style.display]) {
|
|
||||||
img.style.pageBreakInside = 'avoid';
|
var is_block = break_avoid_block_styles[style.display];
|
||||||
img.style.breakInside = 'avoid';
|
if (is_block) avoid_page_breaks_inside(img);
|
||||||
}
|
else if (img.parentNode && img.parentNode.childElementCount === 1) avoid_page_breaks_inside(img.parentNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user