From 609c8a22150a9fb25a4bdc1cc83374c1267337eb Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 17 Oct 2019 13:12:08 +0530 Subject: [PATCH] Edit book: Apply the same workaround for use of 100% instead of 100vh in full screen SVG images as is used in the viewer. This should give the same rendering as in the viewer, leading to less confusion. I of course dont like implementing this kind of hackery, but... --- src/pyj/editor.pyj | 3 +++ src/pyj/fs_images.pyj | 33 +++++++++++++++++++++++++++++++++ src/pyj/read_book/iframe.pyj | 32 ++------------------------------ 3 files changed, 38 insertions(+), 30 deletions(-) create mode 100644 src/pyj/fs_images.pyj diff --git a/src/pyj/editor.pyj b/src/pyj/editor.pyj index 6ca4dadea8..580347dee4 100644 --- a/src/pyj/editor.pyj +++ b/src/pyj/editor.pyj @@ -4,6 +4,7 @@ from __python__ import bound_methods, hash_literals from elementmaker import E +from fs_images import fix_fullscreen_svg_images from live_css import get_matched_css, get_sourceline_address from qt import from_python, to_python @@ -172,3 +173,5 @@ document.documentElement.appendChild(E.style( type='text/css', '[data-in-split-mode="1"] [data-is-block="1"]:hover { cursor: pointer !important; border-top: solid 5px green !important }' )) + +fix_fullscreen_svg_images() diff --git a/src/pyj/fs_images.pyj b/src/pyj/fs_images.pyj new file mode 100644 index 0000000000..c0268f474e --- /dev/null +++ b/src/pyj/fs_images.pyj @@ -0,0 +1,33 @@ +# vim:fileencoding=utf-8 +# License: GPL v3 Copyright: 2019, Kovid Goyal +from __python__ import bound_methods, hash_literals + + +def fix_fullscreen_svg_images(): + # Full screen images using SVG no longer render correctly + # webengine. This is because it sets the width to the + # viewport width and simply adjusts the height accordingly + # So we replace 100% with 100vw and 100vh to get the desired + # rendering + child_names = v'[]' + for node in document.body.childNodes: + if node.tagName: + name = node.tagName.toLowerCase() + if name is not 'style' and name is not 'script': + child_names.push(name) + if child_names.length > 1: + break + if child_names.length is 1 and child_names[0] is 'div': + names = [] + svg = None + for node in document.body.querySelectorAll('*'): + if node.tagName: + name = node.tagName.toLowerCase() + if name is not 'style' and name is not 'script': + names.push(name) + if name is 'svg': + svg = node + if names == ['div', 'svg', 'image'] or names == ['svg', 'image']: + if svg.getAttribute('width') is '100%' and svg.getAttribute('height') is '100%': + svg.setAttribute('width', '100vw') + svg.setAttribute('height', '100vh') diff --git a/src/pyj/read_book/iframe.pyj b/src/pyj/read_book/iframe.pyj index 8b47db68b6..7d3150462f 100644 --- a/src/pyj/read_book/iframe.pyj +++ b/src/pyj/read_book/iframe.pyj @@ -5,6 +5,7 @@ from __python__ import bound_methods, hash_literals import traceback from gettext import gettext as _ +from fs_images import fix_fullscreen_svg_images from iframe_comm import IframeClient from read_book.cfi import scroll_to as scroll_to_cfi from read_book.extract import get_elements @@ -228,35 +229,6 @@ class IframeBoss: opts.color_scheme = data.color_scheme apply_colors() - def fix_fullscreen_svg_images(self): - # Full screen images using SVG no longer render correctly - # webengine. This is because it sets the width to the - # viewport width and simply adjusts the height accordingly - # So we replace 100% with 100vw and 100vh to get the desired - # rendering - child_names = v'[]' - for node in document.body.childNodes: - if node.tagName: - name = node.tagName.toLowerCase() - if name is not 'style' and name is not 'script': - child_names.push(name) - if child_names.length > 1: - break - if child_names.length is 1 and child_names[0] is 'div': - names = [] - svg = None - for node in document.body.querySelectorAll('*'): - if node.tagName: - name = node.tagName.toLowerCase() - if name is not 'style' and name is not 'script': - names.push(name) - if name is 'svg': - svg = node - if names == ['div', 'svg', 'image'] or names == ['svg', 'image']: - if svg.getAttribute('width') is '100%' and svg.getAttribute('height') is '100%': - svg.setAttribute('width', '100vw') - svg.setAttribute('height', '100vh') - def content_loaded(self): document.documentElement.style.overflow = 'hidden' if self.is_titlepage and not opts.cover_preserve_aspect_ratio: @@ -264,7 +236,7 @@ class IframeBoss: document.body.classList.add(f'calibre-viewer-{layout_style()}') self.last_window_width, self.last_window_height = scroll_viewport.width(), scroll_viewport.height() apply_settings() - self.fix_fullscreen_svg_images() + fix_fullscreen_svg_images() self.do_layout(self.is_titlepage) if self.mathjax: return apply_mathjax(self.mathjax, self.book.manifest.link_uid, self.content_loaded_stage2)