pdf-preprint.js 1.9 KB

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