Debian Codegraph @

resources/pdf-preprint.js

raw
1 /* vim:fileencoding=utf-8
2 *
3 * Copyright (C) 2019 Kovid Goyal <kovid at kovidgoyal.net>
4 *
5 * Distributed under terms of the GPLv3 license
6 */
7 /*jshint esversion: 6 */
8
9 (function() {
10 "use strict";
11 // wrap up long words that don't fit in the page
12 document.body.style.overflowWrap = 'break-word';
13
14 var break_avoid_block_styles = {
15 "run-in":1, "block":1, "table-row-group":1, "table-column":1, "table-column-group":1,
16 "table-header-group":1, "table-footer-group":1, "table-row":1, "table-cell":1,
17 "table-caption":1, // page-break-avoid does not work for inline-block either
18 };
19
20 function avoid_page_breaks_inside(node) {
21 node.style.pageBreakInside = 'avoid';
22 node.style.breakInside = 'avoid';
23 }
24
25 for (const img of document.images) {
26 var style = window.getComputedStyle(img);
27 if (style.maxHeight === 'none') img.style.maxHeight = '100vh';
28 if (style.maxWidth === 'none') img.style.maxWidth = '100vw';
29
30 var is_block = break_avoid_block_styles[style.display];
31 if (is_block) avoid_page_breaks_inside(img);
32 else if (img.parentNode && img.parentNode.childElementCount === 1) avoid_page_breaks_inside(img.parentNode);
33 }
34 // Change the hyphenate character to a plain ASCII minus (U+002d) the default
35 // is U+2010 but that does not render with the default Times font on macOS as of Monterey
36 // and Qt 15.5 See https://bugs.launchpad.net/bugs/1951467 and can be easily reproduced
37 // by converting a plain text file with the --pdf-hyphenate option
38 // https://bugs.chromium.org/p/chromium/issues/detail?id=1267606 (fix released Feb 1 2022 v98)
39 // See also settings.pyj
40 if (HYPHEN_CHAR) {
41 for (const elem of document.getElementsByTagName('*')) {
42 if (elem.style) {
43 elem.style.setProperty('-webkit-hyphenate-character', '"-"', 'important');
44 }
45 }
46 }
47 })();
48
49